scanlayer 1.1.0__tar.gz → 1.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {scanlayer-1.1.0/scanlayer.egg-info → scanlayer-1.2.1}/PKG-INFO +52 -16
- {scanlayer-1.1.0 → scanlayer-1.2.1}/README.md +47 -15
- {scanlayer-1.1.0 → scanlayer-1.2.1}/pyproject.toml +3 -2
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/__init__.py +1 -1
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/cli/dry_run.py +50 -64
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/cli/parser.py +15 -2
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/cli/run.py +125 -72
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/config.py +11 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/main.py +603 -82
- scanlayer-1.2.1/scanlayer/ocr/engine.py +588 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/pdf/builder.py +74 -24
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/preprocessing/enhance.py +168 -43
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/utils/logger.py +28 -0
- scanlayer-1.2.1/scanlayer/utils/resources.py +35 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1/scanlayer.egg-info}/PKG-INFO +52 -16
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer.egg-info/SOURCES.txt +10 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer.egg-info/requires.txt +5 -0
- scanlayer-1.2.1/tests/test_batch_parallel.py +213 -0
- scanlayer-1.2.1/tests/test_batch_planning.py +317 -0
- scanlayer-1.2.1/tests/test_benchmark_helpers.py +46 -0
- scanlayer-1.2.1/tests/test_cli_logging.py +46 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/tests/test_config.py +6 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/tests/test_merge_workers.py +3 -2
- scanlayer-1.2.1/tests/test_ocr_optimizations.py +315 -0
- scanlayer-1.2.1/tests/test_pdf_optimizations.py +215 -0
- scanlayer-1.2.1/tests/test_pdf_streaming.py +249 -0
- scanlayer-1.2.1/tests/test_preprocess_optimizations.py +115 -0
- scanlayer-1.2.1/tests/test_resources.py +179 -0
- scanlayer-1.1.0/scanlayer/ocr/engine.py +0 -373
- {scanlayer-1.1.0 → scanlayer-1.2.1}/LICENSE.md +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/__main__.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/cli/__init__.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/fonts/DejaVuSans.ttf +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/layout/__init__.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/layout/columns.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/ocr/__init__.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/ocr/export.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/pdf/__init__.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/pdf/fonts.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/preprocessing/__init__.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/utils/__init__.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/utils/debug_image.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/utils/errors.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer/utils/validators.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer.egg-info/dependency_links.txt +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer.egg-info/entry_points.txt +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/scanlayer.egg-info/top_level.txt +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/setup.cfg +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/tests/test_columns.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/tests/test_dry_run.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/tests/test_export.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/tests/test_fonts.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/tests/test_main_integration.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/tests/test_pdf_builder.py +0 -0
- {scanlayer-1.1.0 → scanlayer-1.2.1}/tests/test_validators.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scanlayer
|
|
3
|
-
Version: 1.1
|
|
3
|
+
Version: 1.2.1
|
|
4
4
|
Summary: Image (scan/photo) to searchable PDF, or raw OCR export, via Tesseract.
|
|
5
5
|
Author: Hyacinthe-primus
|
|
6
6
|
Author-email: Hyacinthe-primus <hyacintheatho91@gmail.com>
|
|
@@ -20,6 +20,10 @@ Requires-Dist: pdf2image>=1.17.0
|
|
|
20
20
|
Provides-Extra: test
|
|
21
21
|
Requires-Dist: pytest>=7.0; extra == "test"
|
|
22
22
|
Requires-Dist: pytest-cov>=4.1; extra == "test"
|
|
23
|
+
Requires-Dist: pypdf>=4.0; extra == "test"
|
|
24
|
+
Provides-Extra: bench
|
|
25
|
+
Requires-Dist: psutil>=5.9; extra == "bench"
|
|
26
|
+
Requires-Dist: pypdf>=4.0; extra == "bench"
|
|
23
27
|
Provides-Extra: yaml
|
|
24
28
|
Requires-Dist: PyYAML>=6.0; extra == "yaml"
|
|
25
29
|
Dynamic: license-file
|
|
@@ -34,13 +38,13 @@ Dynamic: license-file
|
|
|
34
38
|
export the raw OCR result as plain text, JSON, TSV, or hOCR. Use it as a
|
|
35
39
|
command-line tool or as a Python library; both are the same engine underneath.
|
|
36
40
|
|
|
37
|
-
[](#)
|
|
40
|
-

|
|
41
|
-
[](https://github.com/Hyacinthe-primus/scanlayer)
|
|
43
|
-
[](LICENSE.md)
|
|
41
|
+
[](https://badge.fury.io/py/scanlayer)
|
|
42
|
+
[](https://codecov.io/gh/Hyacinthe-primus/scanlayer)
|
|
43
|
+
[](#)
|
|
44
|
+

|
|
45
|
+
[](https://Hyacinthe-primus.github.io/scanlayer/)
|
|
46
|
+
[](https://github.com/Hyacinthe-primus/scanlayer)
|
|
47
|
+
[](LICENSE.md)
|
|
44
48
|
|
|
45
49
|
---
|
|
46
50
|
|
|
@@ -71,7 +75,8 @@ each other to pick the most confident result.
|
|
|
71
75
|
| **Two interfaces, one engine** | `scanlayer` CLI and `import scanlayer` call the exact same pipeline |
|
|
72
76
|
| **Five output formats** | Searchable `pdf`, or raw `txt` / `json` / `tsv` / `hocr` |
|
|
73
77
|
| **Real column detection** | Two-column articles/letters read in correct order, not interleaved |
|
|
74
|
-
| **Batch, merge, native PDF input** | Convert a folder
|
|
78
|
+
| **Batch, merge, native PDF input** | Convert a folder with bounded batch workers, merge pages into one PDF, or `--dry-run` a batch before spending time on OCR |
|
|
79
|
+
| **Incremental PDF pages** | Normal batch PDFs are rasterized page-by-page, keeping memory bounded by active workers |
|
|
75
80
|
| **One configuration surface** | `configure()`, a JSON/YAML profile, or CLI flags, documented precedence |
|
|
76
81
|
| **Debug overlay** | `--debug-image` draws every word, color-coded by confidence |
|
|
77
82
|
|
|
@@ -150,8 +155,11 @@ the complete details of each.
|
|
|
150
155
|
A few more common cases:
|
|
151
156
|
|
|
152
157
|
```bash
|
|
153
|
-
# Batch-convert a folder
|
|
154
|
-
scanlayer *.jpg -o ./converted/
|
|
158
|
+
# Batch-convert a folder with bounded parallelism (default: 2 workers)
|
|
159
|
+
scanlayer *.jpg -o ./converted/ --batch-workers 2
|
|
160
|
+
|
|
161
|
+
# Original sequential batch behavior
|
|
162
|
+
scanlayer *.jpg -o ./converted/ --batch-workers 1
|
|
155
163
|
|
|
156
164
|
# Merge several photographed pages into one searchable PDF
|
|
157
165
|
scanlayer page1.jpg page2.jpg page3.jpg -o report.pdf --merge
|
|
@@ -170,8 +178,9 @@ scanlayer *.jpg -o ./converted/ --dry-run
|
|
|
170
178
|
```python
|
|
171
179
|
import scanlayer
|
|
172
180
|
|
|
173
|
-
# Batch
|
|
174
|
-
|
|
181
|
+
# Batch with bounded parallelism (default: 2 workers)
|
|
182
|
+
batch = scanlayer.convert_batch(["*.jpg"], "./converted/", batch_workers=2)
|
|
183
|
+
print(batch.succeeded, batch.failed)
|
|
175
184
|
|
|
176
185
|
# Merge
|
|
177
186
|
scanlayer.convert_merge(["page1.jpg", "page2.jpg", "page3.jpg"], "report.pdf")
|
|
@@ -180,6 +189,13 @@ scanlayer.convert_merge(["page1.jpg", "page2.jpg", "page3.jpg"], "report.pdf")
|
|
|
180
189
|
scanlayer.convert("invoice.jpg", "invoice.json", output_format="json")
|
|
181
190
|
```
|
|
182
191
|
|
|
192
|
+
`--workers` remains the merge-page worker option; use `--batch-workers` (or
|
|
193
|
+
`batch_workers=`) for normal non-merge batch conversion. The default batch
|
|
194
|
+
worker count is 2 and can be changed with `scanlayer.configure(batch_workers=...)`.
|
|
195
|
+
Normal batch PDFs are enumerated first and rasterized incrementally, so peak
|
|
196
|
+
memory is bounded by the active workers rather than total page count. Merge
|
|
197
|
+
still builds its full page set before writing the combined PDF.
|
|
198
|
+
|
|
183
199
|
## Repository layout
|
|
184
200
|
|
|
185
201
|
```
|
|
@@ -197,6 +213,7 @@ scanlayer.convert("invoice.jpg", "invoice.json", output_format="json")
|
|
|
197
213
|
│ ├── layout/
|
|
198
214
|
│ ├── pdf/
|
|
199
215
|
│ └── utils/
|
|
216
|
+
├── benchmarks/ # opt-in corpus and reproducible performance harness
|
|
200
217
|
├── tests/ # pytest suite
|
|
201
218
|
├── pyproject.toml
|
|
202
219
|
├── requirements.txt
|
|
@@ -206,13 +223,32 @@ scanlayer.convert("invoice.jpg", "invoice.json", output_format="json")
|
|
|
206
223
|
└── LICENSE.md
|
|
207
224
|
```
|
|
208
225
|
|
|
226
|
+
## Development benchmarks
|
|
227
|
+
|
|
228
|
+
The reproducible benchmark harness is under `benchmarks/` and is not part of
|
|
229
|
+
the default pytest run:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
pip install -e ".[test,bench]"
|
|
233
|
+
python -m benchmarks.bench_batch --repeats 2 --batch-workers 2
|
|
234
|
+
python -m benchmarks.bench_pipeline --repeats 2 --warmup 1
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
See `benchmarks/README.md` for the synthetic corpus, stage benchmarks, and
|
|
238
|
+
caveats.
|
|
239
|
+
|
|
209
240
|
## Contributing
|
|
210
241
|
|
|
211
242
|
Bug reports, fixes, and feature discussions are welcome: see
|
|
212
243
|
[CONTRIBUTING.md](CONTRIBUTING.md) for how to set up a development
|
|
213
|
-
environment and what to include in a pull request.
|
|
214
|
-
|
|
215
|
-
|
|
244
|
+
environment and what to include in a pull request. The `tests/` directory
|
|
245
|
+
covers validators and the `--dry-run` flag, with cross-platform coverage for
|
|
246
|
+
Tesseract discovery on Windows/macOS/Linux; the opt-in `benchmarks/` suite
|
|
247
|
+
covers stage timings and batch throughput. Tests run with `pytest`
|
|
248
|
+
automatically in CI on every push and pull request; see
|
|
249
|
+
[Roadmap & Limitations](https://Hyacinthe-primus.github.io/scanlayer/roadmap.html)
|
|
250
|
+
and the [Adding tests](CONTRIBUTING.md#adding-tests) section of the
|
|
251
|
+
contributing guide for where coverage is thinnest.
|
|
216
252
|
|
|
217
253
|
## Support the project
|
|
218
254
|
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
export the raw OCR result as plain text, JSON, TSV, or hOCR. Use it as a
|
|
9
9
|
command-line tool or as a Python library; both are the same engine underneath.
|
|
10
10
|
|
|
11
|
-
[](#)
|
|
14
|
-

|
|
15
|
-
[](https://github.com/Hyacinthe-primus/scanlayer)
|
|
17
|
-
[](LICENSE.md)
|
|
11
|
+
[](https://badge.fury.io/py/scanlayer)
|
|
12
|
+
[](https://codecov.io/gh/Hyacinthe-primus/scanlayer)
|
|
13
|
+
[](#)
|
|
14
|
+

|
|
15
|
+
[](https://Hyacinthe-primus.github.io/scanlayer/)
|
|
16
|
+
[](https://github.com/Hyacinthe-primus/scanlayer)
|
|
17
|
+
[](LICENSE.md)
|
|
18
18
|
|
|
19
19
|
---
|
|
20
20
|
|
|
@@ -45,7 +45,8 @@ each other to pick the most confident result.
|
|
|
45
45
|
| **Two interfaces, one engine** | `scanlayer` CLI and `import scanlayer` call the exact same pipeline |
|
|
46
46
|
| **Five output formats** | Searchable `pdf`, or raw `txt` / `json` / `tsv` / `hocr` |
|
|
47
47
|
| **Real column detection** | Two-column articles/letters read in correct order, not interleaved |
|
|
48
|
-
| **Batch, merge, native PDF input** | Convert a folder
|
|
48
|
+
| **Batch, merge, native PDF input** | Convert a folder with bounded batch workers, merge pages into one PDF, or `--dry-run` a batch before spending time on OCR |
|
|
49
|
+
| **Incremental PDF pages** | Normal batch PDFs are rasterized page-by-page, keeping memory bounded by active workers |
|
|
49
50
|
| **One configuration surface** | `configure()`, a JSON/YAML profile, or CLI flags, documented precedence |
|
|
50
51
|
| **Debug overlay** | `--debug-image` draws every word, color-coded by confidence |
|
|
51
52
|
|
|
@@ -124,8 +125,11 @@ the complete details of each.
|
|
|
124
125
|
A few more common cases:
|
|
125
126
|
|
|
126
127
|
```bash
|
|
127
|
-
# Batch-convert a folder
|
|
128
|
-
scanlayer *.jpg -o ./converted/
|
|
128
|
+
# Batch-convert a folder with bounded parallelism (default: 2 workers)
|
|
129
|
+
scanlayer *.jpg -o ./converted/ --batch-workers 2
|
|
130
|
+
|
|
131
|
+
# Original sequential batch behavior
|
|
132
|
+
scanlayer *.jpg -o ./converted/ --batch-workers 1
|
|
129
133
|
|
|
130
134
|
# Merge several photographed pages into one searchable PDF
|
|
131
135
|
scanlayer page1.jpg page2.jpg page3.jpg -o report.pdf --merge
|
|
@@ -144,8 +148,9 @@ scanlayer *.jpg -o ./converted/ --dry-run
|
|
|
144
148
|
```python
|
|
145
149
|
import scanlayer
|
|
146
150
|
|
|
147
|
-
# Batch
|
|
148
|
-
|
|
151
|
+
# Batch with bounded parallelism (default: 2 workers)
|
|
152
|
+
batch = scanlayer.convert_batch(["*.jpg"], "./converted/", batch_workers=2)
|
|
153
|
+
print(batch.succeeded, batch.failed)
|
|
149
154
|
|
|
150
155
|
# Merge
|
|
151
156
|
scanlayer.convert_merge(["page1.jpg", "page2.jpg", "page3.jpg"], "report.pdf")
|
|
@@ -154,6 +159,13 @@ scanlayer.convert_merge(["page1.jpg", "page2.jpg", "page3.jpg"], "report.pdf")
|
|
|
154
159
|
scanlayer.convert("invoice.jpg", "invoice.json", output_format="json")
|
|
155
160
|
```
|
|
156
161
|
|
|
162
|
+
`--workers` remains the merge-page worker option; use `--batch-workers` (or
|
|
163
|
+
`batch_workers=`) for normal non-merge batch conversion. The default batch
|
|
164
|
+
worker count is 2 and can be changed with `scanlayer.configure(batch_workers=...)`.
|
|
165
|
+
Normal batch PDFs are enumerated first and rasterized incrementally, so peak
|
|
166
|
+
memory is bounded by the active workers rather than total page count. Merge
|
|
167
|
+
still builds its full page set before writing the combined PDF.
|
|
168
|
+
|
|
157
169
|
## Repository layout
|
|
158
170
|
|
|
159
171
|
```
|
|
@@ -171,6 +183,7 @@ scanlayer.convert("invoice.jpg", "invoice.json", output_format="json")
|
|
|
171
183
|
│ ├── layout/
|
|
172
184
|
│ ├── pdf/
|
|
173
185
|
│ └── utils/
|
|
186
|
+
├── benchmarks/ # opt-in corpus and reproducible performance harness
|
|
174
187
|
├── tests/ # pytest suite
|
|
175
188
|
├── pyproject.toml
|
|
176
189
|
├── requirements.txt
|
|
@@ -180,13 +193,32 @@ scanlayer.convert("invoice.jpg", "invoice.json", output_format="json")
|
|
|
180
193
|
└── LICENSE.md
|
|
181
194
|
```
|
|
182
195
|
|
|
196
|
+
## Development benchmarks
|
|
197
|
+
|
|
198
|
+
The reproducible benchmark harness is under `benchmarks/` and is not part of
|
|
199
|
+
the default pytest run:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
pip install -e ".[test,bench]"
|
|
203
|
+
python -m benchmarks.bench_batch --repeats 2 --batch-workers 2
|
|
204
|
+
python -m benchmarks.bench_pipeline --repeats 2 --warmup 1
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
See `benchmarks/README.md` for the synthetic corpus, stage benchmarks, and
|
|
208
|
+
caveats.
|
|
209
|
+
|
|
183
210
|
## Contributing
|
|
184
211
|
|
|
185
212
|
Bug reports, fixes, and feature discussions are welcome: see
|
|
186
213
|
[CONTRIBUTING.md](CONTRIBUTING.md) for how to set up a development
|
|
187
|
-
environment and what to include in a pull request.
|
|
188
|
-
|
|
189
|
-
|
|
214
|
+
environment and what to include in a pull request. The `tests/` directory
|
|
215
|
+
covers validators and the `--dry-run` flag, with cross-platform coverage for
|
|
216
|
+
Tesseract discovery on Windows/macOS/Linux; the opt-in `benchmarks/` suite
|
|
217
|
+
covers stage timings and batch throughput. Tests run with `pytest`
|
|
218
|
+
automatically in CI on every push and pull request; see
|
|
219
|
+
[Roadmap & Limitations](https://Hyacinthe-primus.github.io/scanlayer/roadmap.html)
|
|
220
|
+
and the [Adding tests](CONTRIBUTING.md#adding-tests) section of the
|
|
221
|
+
contributing guide for where coverage is thinnest.
|
|
190
222
|
|
|
191
223
|
## Support the project
|
|
192
224
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "scanlayer"
|
|
7
|
-
version = "1.1
|
|
7
|
+
version = "1.2.1"
|
|
8
8
|
description = "Image (scan/photo) to searchable PDF, or raw OCR export, via Tesseract."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -23,7 +23,8 @@ dependencies = [
|
|
|
23
23
|
]
|
|
24
24
|
|
|
25
25
|
[project.optional-dependencies]
|
|
26
|
-
test = ["pytest>=7.0", "pytest-cov>=4.1"]
|
|
26
|
+
test = ["pytest>=7.0", "pytest-cov>=4.1", "pypdf>=4.0"]
|
|
27
|
+
bench = ["psutil>=5.9", "pypdf>=4.0"]
|
|
27
28
|
yaml = ["PyYAML>=6.0"]
|
|
28
29
|
|
|
29
30
|
[project.scripts]
|
|
@@ -8,7 +8,7 @@ import argparse
|
|
|
8
8
|
import os
|
|
9
9
|
from typing import Optional
|
|
10
10
|
|
|
11
|
-
from scanlayer.main import
|
|
11
|
+
from scanlayer.main import _resolve_output_target
|
|
12
12
|
from scanlayer.utils.errors import BlankPageDetectedError, PipelineError
|
|
13
13
|
from scanlayer.utils.logger import log_error
|
|
14
14
|
from scanlayer.utils.validators import (
|
|
@@ -47,21 +47,11 @@ def _exit_code_for(exc: Exception) -> int:
|
|
|
47
47
|
def _dry_run_resolve_output_path(
|
|
48
48
|
output_arg: str, input_path: str, is_batch: bool, output_format: str = "pdf"
|
|
49
49
|
) -> "tuple[str, Optional[str]]":
|
|
50
|
-
"""
|
|
50
|
+
"""Pure output-path resolution used by dry-run.
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
folder-style -o, which --dry-run must not do. Returns
|
|
54
|
-
(resolved_output_path, folder_or_None) – folder is set when this
|
|
55
|
-
is the auto-created-folder case, so the caller can validate it
|
|
56
|
-
without creating it.
|
|
52
|
+
Returns (resolved_output_path, folder_or_None). No directory is created.
|
|
57
53
|
"""
|
|
58
|
-
|
|
59
|
-
return _default_output_path(input_path, output_format), None
|
|
60
|
-
is_folder = is_batch or output_arg.endswith(("/", "\\")) or os.path.isdir(output_arg)
|
|
61
|
-
if is_folder:
|
|
62
|
-
stem = os.path.splitext(os.path.basename(input_path))[0]
|
|
63
|
-
return os.path.join(output_arg, f"{stem}.{output_format}"), output_arg
|
|
64
|
-
return output_arg, None
|
|
54
|
+
return _resolve_output_target(output_arg, input_path, is_batch, output_format)
|
|
65
55
|
|
|
66
56
|
|
|
67
57
|
def _nearest_existing_dir(path: str) -> str:
|
|
@@ -96,45 +86,35 @@ def _check_output_folder_creatable(folder: str) -> None:
|
|
|
96
86
|
raise OutputPathError(f"Output directory is not writable: {target}")
|
|
97
87
|
|
|
98
88
|
|
|
99
|
-
def
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
yet (validate_output_path() would otherwise reject it for a
|
|
106
|
-
reason a real run would just fix by creating the folder).
|
|
107
|
-
"""
|
|
108
|
-
input_abs = validate_input_file(input_path)
|
|
89
|
+
def _dry_run_validate_job(job, output_format: str) -> None:
|
|
90
|
+
"""Validate one planned job without writing anything."""
|
|
91
|
+
if job.page_number is not None:
|
|
92
|
+
input_abs = validate_input_file(job.source_path)
|
|
93
|
+
else:
|
|
94
|
+
input_abs = validate_input_file(job.input_path)
|
|
109
95
|
validate_tesseract_environment()
|
|
110
|
-
if
|
|
111
|
-
_check_output_folder_creatable(
|
|
96
|
+
if job.output_dir is not None:
|
|
97
|
+
_check_output_folder_creatable(job.output_dir)
|
|
112
98
|
else:
|
|
113
|
-
validate_output_path(output_path, expected_ext=f".{output_format}")
|
|
114
|
-
|
|
115
|
-
|
|
99
|
+
validate_output_path(job.output_path, expected_ext=f".{output_format}")
|
|
100
|
+
if job.page_number is None:
|
|
101
|
+
validate_image_readable(input_abs)
|
|
116
102
|
|
|
117
|
-
def _run_dry_run(
|
|
118
|
-
expanded_inputs: list[str], args: argparse.Namespace, log
|
|
119
|
-
) -> int:
|
|
120
|
-
"""Validate a batch (files exist/readable, Tesseract reachable,
|
|
121
|
-
output paths writable) without running OCR or writing anything.
|
|
122
103
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
own exit code immediately, multi-input runs collect every
|
|
126
|
-
failure and return EXIT_PARTIAL_BATCH if any file failed.
|
|
104
|
+
def _run_dry_run(plan, args: argparse.Namespace, log) -> int:
|
|
105
|
+
"""Validate a batch plan without OCR, rasterization, or output writes.
|
|
127
106
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
fast on the first bad page, no EXIT_PARTIAL_BATCH here).
|
|
107
|
+
Non-merge: per-file failures are collected; a single job returns its own
|
|
108
|
+
exit code, multiple jobs return EXIT_PARTIAL_BATCH.
|
|
109
|
+
--merge: fail fast on the first bad input, matching convert_merge().
|
|
132
110
|
"""
|
|
133
|
-
|
|
111
|
+
total = len(plan.jobs) + len(plan.failures)
|
|
134
112
|
|
|
135
113
|
if args.merge:
|
|
136
|
-
|
|
137
|
-
|
|
114
|
+
if plan.failures:
|
|
115
|
+
path, exc = plan.failures[0]
|
|
116
|
+
log_error(log, f"'{path}': {exc}")
|
|
117
|
+
return _exit_code_for(exc)
|
|
138
118
|
try:
|
|
139
119
|
validate_output_path(args.output, expected_ext=".pdf")
|
|
140
120
|
except ValidationError as exc:
|
|
@@ -146,46 +126,52 @@ def _run_dry_run(
|
|
|
146
126
|
log_error(log, f"'--merge': {exc}")
|
|
147
127
|
return _exit_code_for(exc)
|
|
148
128
|
|
|
149
|
-
for
|
|
129
|
+
for job in plan.jobs:
|
|
150
130
|
try:
|
|
151
|
-
|
|
152
|
-
|
|
131
|
+
if job.page_number is not None:
|
|
132
|
+
validate_input_file(job.source_path)
|
|
133
|
+
else:
|
|
134
|
+
input_abs = validate_input_file(job.input_path)
|
|
135
|
+
validate_image_readable(input_abs)
|
|
153
136
|
except ValidationError as exc:
|
|
154
|
-
log_error(log, f"'{
|
|
137
|
+
log_error(log, f"'{job.source_path}': {exc}")
|
|
155
138
|
return _exit_code_for(exc)
|
|
156
139
|
|
|
157
140
|
log.info(
|
|
158
|
-
f"dry-run: {len(
|
|
141
|
+
f"dry-run: {len(plan.jobs)} page/file(s) OK for --merge "
|
|
159
142
|
f"into {args.output}, no output written."
|
|
160
143
|
)
|
|
161
144
|
return EXIT_OK
|
|
162
145
|
|
|
163
|
-
failures
|
|
146
|
+
failures = 0
|
|
164
147
|
last_exit_code = EXIT_OK
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
148
|
+
for path, exc in plan.failures:
|
|
149
|
+
code = _exit_code_for(exc)
|
|
150
|
+
log_error(log, f"'{path}': {exc}")
|
|
151
|
+
failures += 1
|
|
152
|
+
last_exit_code = code
|
|
153
|
+
if total <= 1:
|
|
154
|
+
return last_exit_code
|
|
155
|
+
|
|
156
|
+
for job in plan.jobs:
|
|
170
157
|
try:
|
|
171
|
-
|
|
158
|
+
_dry_run_validate_job(job, args.format)
|
|
172
159
|
except Exception as exc:
|
|
173
160
|
code = _exit_code_for(exc)
|
|
174
|
-
log_error(log, f"'{
|
|
175
|
-
failures
|
|
161
|
+
log_error(log, f"'{job.source_path}': {exc}")
|
|
162
|
+
failures += 1
|
|
176
163
|
last_exit_code = code
|
|
177
|
-
if
|
|
164
|
+
if total <= 1:
|
|
178
165
|
return last_exit_code
|
|
179
166
|
|
|
180
167
|
if failures:
|
|
181
|
-
if
|
|
168
|
+
if total > 1:
|
|
182
169
|
log_error(
|
|
183
170
|
log,
|
|
184
|
-
f"dry-run: {
|
|
185
|
-
f"file(s) failed validation.",
|
|
171
|
+
f"dry-run: {failures}/{total} file(s) failed validation.",
|
|
186
172
|
)
|
|
187
173
|
return EXIT_PARTIAL_BATCH
|
|
188
174
|
return last_exit_code
|
|
189
175
|
|
|
190
|
-
log.info(f"dry-run: {
|
|
176
|
+
log.info(f"dry-run: {total} file(s) OK, no output written.")
|
|
191
177
|
return EXIT_OK
|
|
@@ -85,6 +85,14 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
85
85
|
"and OCR output are the same. Ignored without --merge. "
|
|
86
86
|
"Equivalent to configure(merge_workers=N).",
|
|
87
87
|
)
|
|
88
|
+
io_group.add_argument(
|
|
89
|
+
"--batch-workers", type=int, default=None, metavar="N",
|
|
90
|
+
help="Non-merge batches: process up to N files concurrently "
|
|
91
|
+
f"(default {config.BATCH_WORKERS}; 1 = sequential). Capped by "
|
|
92
|
+
"input count and CPU count. The global OCR budget still limits "
|
|
93
|
+
"simultaneous Tesseract passes. Ignored with --merge. "
|
|
94
|
+
"Equivalent to configure(batch_workers=N).",
|
|
95
|
+
)
|
|
88
96
|
io_group.add_argument(
|
|
89
97
|
"--config", default=None,
|
|
90
98
|
help="Path to a .yaml/.yml/.json config profile applied via "
|
|
@@ -137,11 +145,16 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
137
145
|
ocr_group.add_argument(
|
|
138
146
|
"--whitelist", default=None,
|
|
139
147
|
help="Allowed characters for OCR, e.g. "
|
|
140
|
-
"'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'"
|
|
148
|
+
"'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'. Include a "
|
|
149
|
+
"space to preserve word boundaries; punctuation excluded "
|
|
150
|
+
"this way is left out of the word, not used to drop it.",
|
|
141
151
|
)
|
|
142
152
|
ocr_group.add_argument(
|
|
143
153
|
"--blacklist", default=None,
|
|
144
|
-
help="Forbidden characters for OCR, e.g. '|`~'"
|
|
154
|
+
help="Forbidden characters for OCR, e.g. '|`~'. A "
|
|
155
|
+
"punctuation-only blacklist keeps the affected word; an "
|
|
156
|
+
"alphanumeric blacklist can make Tesseract discard whole "
|
|
157
|
+
"words because their confidence drops to 0.",
|
|
145
158
|
)
|
|
146
159
|
ocr_group.add_argument(
|
|
147
160
|
"--font", default=None,
|