Skip to content

Commit f9ffdd8

Browse files
committed
Generate documentation dynamically
1 parent d43a3ab commit f9ffdd8

11 files changed

Lines changed: 109 additions & 172 deletions

File tree

.github/workflows/docs.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Build docs
2+
3+
on: [push]
4+
5+
jobs:
6+
docs:
7+
runs-on: ubuntu-24.04
8+
9+
steps:
10+
- uses: actions/checkout@v6
11+
with:
12+
# This actions is ridiculously bad at fetching tags
13+
# See https://github.com/actions/checkout/issues/2309
14+
fetch-depth: 0
15+
fetch-tags: true
16+
17+
- name: Install prerequisites on Ubuntu
18+
run: |
19+
sudo apt update
20+
sudo apt install --yes libdjvulibre21 libdjvulibre-dev
21+
22+
- uses: astral-sh/setup-uv@v7
23+
- name: Install dependencies
24+
run: uv sync
25+
26+
- name: Build docs
27+
run: make build-docs
28+
29+
- name: Upload to wiki
30+
uses: spenserblack/actions-wiki@v0.3.0
31+
with:
32+
# Whatever directory you choose will be mirrored to the GitHub
33+
# .wiki.git. The default is .github/wiki.
34+
path: wiki

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.pytest_cache
22
.ruff_cache
3-
.tests
3+
docs/dpsprep.1
4+
docs/dpsprep.1.txt

Makefile

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
.PHONY: lint test
1+
SOURCE := $(wildcard dpsprep/*.py)
2+
3+
.PHONY: lint test build-docs
24

35
lint:
46
uv run ruff check
@@ -7,5 +9,18 @@ lint:
79
test:
810
uv run pytest
911

10-
dpsprep.1: dpsprep.1.ronn
11-
ronn --roff dpsprep.1.ronn
12+
docs:
13+
mkdir docs
14+
15+
docs/dpsprep.1: $(SOURCE) pyproject.toml docs/examples.man | docs
16+
uv run click-man dpsprep \
17+
--target docs \
18+
--man-version $(shell git describe --tags) \
19+
--man-date $(shell git log --max-count 1 --format=%as)
20+
21+
cat docs/examples.man >> docs/dpsprep.1
22+
23+
docs/dpsprep.1.txt: docs/dpsprep.1
24+
MANWIDTH=100 man docs/dpsprep.1 > docs/dpsprep.1.txt
25+
26+
build-docs: docs/dpsprep.1.txt

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
[![Tests](https://github.com/kcroker/dpsprep/actions/workflows/test.yml/badge.svg)](https://github.com/kcroker/dpsprep/actions/workflows/test.yml) [![AUR Package](https://img.shields.io/aur/version/dpsprep)](https://aur.archlinux.org/packages/dpsprep)
44

5-
This tool, initially made specifically for use with Sony's Digital Paper System (DPS), is now a general-purpose DjVu to PDF converter with a focus on small output size and the ability to preserve document outlines (e.g. TOC) and text layers (e.g. OCR).
5+
Convert DjVu files to PDF.
6+
7+
The name comes from Sony's Digital Paper System (DPS), for which the tool was initially developed - see [below](#kevins-notes-regarding-the-first-version).
68

79
## Usage
810

@@ -18,7 +20,7 @@ You can also skip translating the text layer (it is sometimes not translated wel
1820

1921
dpsprep --ocr '{"language": ["rus", "eng"]}' input.djvu
2022

21-
Consult the man file ([online](./dpsprep.1.ronn)) for details; there are a lot of options to consider.
23+
Consult the man file ([online](./docs/dpsprep.1.txt)) for details; there are a lot of options to consider.
2224

2325
See the next section for different ways to run the program.
2426

@@ -80,7 +82,7 @@ If you want `dpsprep` to be able to use `ocrmypdf` from `pipx`'s isolated enviro
8082
> If you are packaging this for some other package manager, consider using PEP-517 tools as shown in [this PKGBUILD file](https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=dpsprep).
8183
8284
> [!NOTE]
83-
> Previous versions of the tool itself used to depend on third-party binaries, but this is no longer the case. The test fixtures are checked in, however regenerating them (see [`./fixtures/Makefile`](./fixtures/Makefile)) requires `pdflatex` (texlive, among others), `gs` (Ghostscript), `oxipng` (oxipng), `pdftotext` (Poppler), `djvudigital` (GSDjVU) and `djvused` (DjVuLibre). Similarly, the man file is checked in, but building it from markdown depends on `ronn`.
85+
> Previous versions of the tool itself used to depend on third-party binaries, but this is no longer the case. The test fixtures are checked in, however regenerating them (see [`./fixtures/Makefile`](./fixtures/Makefile)) requires `pdflatex` (texlive, among others), `gs` (Ghostscript), `oxipng` (oxipng), `pdftotext` (Poppler), `djvudigital` (GSDjVU) and `djvused` (DjVuLibre).
8486
8587
## Details
8688

docs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# dpsprep docs
2+
3+
The documentation is built dynamically. This directory contains only auxiliary files.

docs/examples.man

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.SH EXAMPLES
2+
.P
3+
Produce `file.pdf` in the current directory:
4+
.IP
5+
dpsprep /wherever/file.djvu
6+
.P
7+
Produce `output.pdf` with reduced image quality and aggressive PDF image optimizations:
8+
.IP
9+
dpsprep --quality=30 -O3 input.djvu output.pdf
10+
.P
11+
Produce an output file using a large pool of workers:
12+
.IP
13+
dpsprep --pool=16 input.djvu
14+
.P
15+
Force bitonal images:
16+
.IP
17+
dpsprep --mode bitonal input.djvu
18+
.P
19+
Produce an output file by disregarding the text layer and running OCRmyPDF instead:
20+
.IP
21+
dpsprep --ocr '{"language": ["rus", "eng"]}' input.djvu
22+
.P
23+
Simply disregard the text layer without OCR:
24+
.IP
25+
dpsprep --no-text input.djvu
26+
.P

dpsprep.1

Lines changed: 0 additions & 98 deletions
This file was deleted.

dpsprep.1.ronn

Lines changed: 0 additions & 65 deletions
This file was deleted.

dpsprep/dpsprep.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def process_text(workdir: WorkingDirectory, dpi: int | None, *, verbose: bool) -
8787
@click.version_option()
8888
@click.argument('dest', type=click.Path(exists=False, resolve_path=True), required=False)
8989
@click.argument('src', type=click.Path(exists=True, resolve_path=True), required=True)
90-
@click.command()
90+
@click.command(epilog='See dpsprep(1) for more details.')
9191
def dpsprep( # noqa: C901
9292
src: str,
9393
dest: str | None,
@@ -104,6 +104,10 @@ def dpsprep( # noqa: C901
104104
preserve_working: bool,
105105
no_text: bool,
106106
) -> None:
107+
"""Convert DjVu files to PDF.
108+
109+
The name comes from Sony's Digital Paper System (DPS), for which the tool was initially developed.
110+
"""
107111
configure_loguru(verbose=verbose)
108112
workdir = WorkingDirectory(src, dest)
109113

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies = [
1414
"fpdf2 (>=2.8)",
1515
"loguru (>=0.7)",
1616
"pdfrw (>=0.4)",
17-
"pillow (>=12.2.0)"
17+
"pillow (>=12.2.0)",
1818
]
1919

2020
[project.urls]
@@ -31,6 +31,7 @@ dpsprep = "dpsprep:dpsprep"
3131

3232
[dependency-groups]
3333
dev = [
34+
"click-man (>=0.5.1)",
3435
"mypy (>=1.19)",
3536
"pytest (>=9.0.3)",
3637
"ruff (>=0.15)",

0 commit comments

Comments
 (0)