scanlayer 1.1.0__tar.gz → 1.2.0__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.
Files changed (53) hide show
  1. {scanlayer-1.1.0/scanlayer.egg-info → scanlayer-1.2.0}/PKG-INFO +52 -16
  2. {scanlayer-1.1.0 → scanlayer-1.2.0}/README.md +47 -15
  3. {scanlayer-1.1.0 → scanlayer-1.2.0}/pyproject.toml +3 -2
  4. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/__init__.py +1 -1
  5. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/cli/dry_run.py +50 -64
  6. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/cli/parser.py +8 -0
  7. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/cli/run.py +107 -67
  8. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/config.py +11 -0
  9. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/main.py +603 -82
  10. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/ocr/engine.py +175 -75
  11. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/pdf/builder.py +74 -24
  12. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/preprocessing/enhance.py +168 -43
  13. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/utils/logger.py +28 -0
  14. scanlayer-1.2.0/scanlayer/utils/resources.py +35 -0
  15. {scanlayer-1.1.0 → scanlayer-1.2.0/scanlayer.egg-info}/PKG-INFO +52 -16
  16. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer.egg-info/SOURCES.txt +9 -0
  17. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer.egg-info/requires.txt +5 -0
  18. scanlayer-1.2.0/tests/test_batch_parallel.py +213 -0
  19. scanlayer-1.2.0/tests/test_batch_planning.py +317 -0
  20. scanlayer-1.2.0/tests/test_benchmark_helpers.py +46 -0
  21. {scanlayer-1.1.0 → scanlayer-1.2.0}/tests/test_config.py +6 -0
  22. {scanlayer-1.1.0 → scanlayer-1.2.0}/tests/test_merge_workers.py +1 -0
  23. scanlayer-1.2.0/tests/test_ocr_optimizations.py +245 -0
  24. scanlayer-1.2.0/tests/test_pdf_optimizations.py +215 -0
  25. scanlayer-1.2.0/tests/test_pdf_streaming.py +249 -0
  26. scanlayer-1.2.0/tests/test_preprocess_optimizations.py +115 -0
  27. scanlayer-1.2.0/tests/test_resources.py +179 -0
  28. {scanlayer-1.1.0 → scanlayer-1.2.0}/LICENSE.md +0 -0
  29. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/__main__.py +0 -0
  30. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/cli/__init__.py +0 -0
  31. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/fonts/DejaVuSans.ttf +0 -0
  32. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/layout/__init__.py +0 -0
  33. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/layout/columns.py +0 -0
  34. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/ocr/__init__.py +0 -0
  35. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/ocr/export.py +0 -0
  36. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/pdf/__init__.py +0 -0
  37. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/pdf/fonts.py +0 -0
  38. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/preprocessing/__init__.py +0 -0
  39. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/utils/__init__.py +0 -0
  40. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/utils/debug_image.py +0 -0
  41. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/utils/errors.py +0 -0
  42. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer/utils/validators.py +0 -0
  43. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer.egg-info/dependency_links.txt +0 -0
  44. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer.egg-info/entry_points.txt +0 -0
  45. {scanlayer-1.1.0 → scanlayer-1.2.0}/scanlayer.egg-info/top_level.txt +0 -0
  46. {scanlayer-1.1.0 → scanlayer-1.2.0}/setup.cfg +0 -0
  47. {scanlayer-1.1.0 → scanlayer-1.2.0}/tests/test_columns.py +0 -0
  48. {scanlayer-1.1.0 → scanlayer-1.2.0}/tests/test_dry_run.py +0 -0
  49. {scanlayer-1.1.0 → scanlayer-1.2.0}/tests/test_export.py +0 -0
  50. {scanlayer-1.1.0 → scanlayer-1.2.0}/tests/test_fonts.py +0 -0
  51. {scanlayer-1.1.0 → scanlayer-1.2.0}/tests/test_main_integration.py +0 -0
  52. {scanlayer-1.1.0 → scanlayer-1.2.0}/tests/test_pdf_builder.py +0 -0
  53. {scanlayer-1.1.0 → scanlayer-1.2.0}/tests/test_validators.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scanlayer
3
- Version: 1.1.0
3
+ Version: 1.2.0
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
- [![PyPI version](https://badge.fury.io/py/scanlayer.svg)](https://badge.fury.io/py/scanlayer)
38
- [![codecov](https://codecov.io/gh/Hyacinthe-primus/scanlayer/branch/main/graph/badge.svg)](https://codecov.io/gh/Hyacinthe-primus/scanlayer)
39
- [![Python](https://img.shields.io/badge/python-3.9%2B-3776AB)](#)
40
- ![Platforms](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey)
41
- [![](https://img.shields.io/badge/-documentation-green)](https://Hyacinthe-primus.github.io/scanlayer/)
42
- [![GitHub last commit](https://img.shields.io/github/last-commit/Hyacinthe-primus/scanlayer)](https://github.com/Hyacinthe-primus/scanlayer)
43
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE.md)
41
+ [![PyPI version](https://img.shields.io/badge/pypi-v1.2.0-blue?style=for-the-badge)](https://badge.fury.io/py/scanlayer)
42
+ [![codecov](https://img.shields.io/codecov/c/github/Hyacinthe-primus/scanlayer?style=for-the-badge)](https://codecov.io/gh/Hyacinthe-primus/scanlayer)
43
+ [![Python](https://img.shields.io/badge/python-3.9%2B-3776AB?style=for-the-badge)](#)
44
+ ![Platforms](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey?style=for-the-badge)
45
+ [![](https://img.shields.io/badge/docs-documentation-green?style=for-the-badge)](https://Hyacinthe-primus.github.io/scanlayer/)
46
+ [![GitHub last commit](https://img.shields.io/github/last-commit/Hyacinthe-primus/scanlayer?style=for-the-badge)](https://github.com/Hyacinthe-primus/scanlayer)
47
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](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 in one call, merge pages into one PDF, or `--dry-run` a batch before spending time on OCR |
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
- result = scanlayer.convert_batch(["*.jpg"], "./converted/")
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. There is a `tests/`
214
- directory (now including `utils/validators.py` and the `--dry-run` flag, with
215
- cross-platform coverage for Tesseract discovery on Windows/macOS/Linux) and it runs with `pytest` automatically in CI on every push and pull request; see [Roadmap & Limitations](https://Hyacinthe-primus.github.io/scanlayer/roadmap.html) and the [Adding tests](CONTRIBUTING.md#adding-tests) section of the contributing guide for where coverage is thinnest.
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
- [![PyPI version](https://badge.fury.io/py/scanlayer.svg)](https://badge.fury.io/py/scanlayer)
12
- [![codecov](https://codecov.io/gh/Hyacinthe-primus/scanlayer/branch/main/graph/badge.svg)](https://codecov.io/gh/Hyacinthe-primus/scanlayer)
13
- [![Python](https://img.shields.io/badge/python-3.9%2B-3776AB)](#)
14
- ![Platforms](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey)
15
- [![](https://img.shields.io/badge/-documentation-green)](https://Hyacinthe-primus.github.io/scanlayer/)
16
- [![GitHub last commit](https://img.shields.io/github/last-commit/Hyacinthe-primus/scanlayer)](https://github.com/Hyacinthe-primus/scanlayer)
17
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE.md)
11
+ [![PyPI version](https://img.shields.io/badge/pypi-v1.2.0-blue?style=for-the-badge)](https://badge.fury.io/py/scanlayer)
12
+ [![codecov](https://img.shields.io/codecov/c/github/Hyacinthe-primus/scanlayer?style=for-the-badge)](https://codecov.io/gh/Hyacinthe-primus/scanlayer)
13
+ [![Python](https://img.shields.io/badge/python-3.9%2B-3776AB?style=for-the-badge)](#)
14
+ ![Platforms](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey?style=for-the-badge)
15
+ [![](https://img.shields.io/badge/docs-documentation-green?style=for-the-badge)](https://Hyacinthe-primus.github.io/scanlayer/)
16
+ [![GitHub last commit](https://img.shields.io/github/last-commit/Hyacinthe-primus/scanlayer?style=for-the-badge)](https://github.com/Hyacinthe-primus/scanlayer)
17
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](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 in one call, merge pages into one PDF, or `--dry-run` a batch before spending time on OCR |
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
- result = scanlayer.convert_batch(["*.jpg"], "./converted/")
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. There is a `tests/`
188
- directory (now including `utils/validators.py` and the `--dry-run` flag, with
189
- cross-platform coverage for Tesseract discovery on Windows/macOS/Linux) and it runs with `pytest` automatically in CI on every push and pull request; see [Roadmap & Limitations](https://Hyacinthe-primus.github.io/scanlayer/roadmap.html) and the [Adding tests](CONTRIBUTING.md#adding-tests) section of the contributing guide for where coverage is thinnest.
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.0"
7
+ version = "1.2.0"
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]
@@ -29,4 +29,4 @@ __all__ = [
29
29
  "convert_merge",
30
30
  ]
31
31
 
32
- __version__ = "1.0.0"
32
+ __version__ = "1.2.0"
@@ -8,7 +8,7 @@ import argparse
8
8
  import os
9
9
  from typing import Optional
10
10
 
11
- from scanlayer.main import _default_output_path
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
- """Like _resolve_output_path(), but never touches the filesystem.
50
+ """Pure output-path resolution used by dry-run.
51
51
 
52
- _resolve_output_path() calls os.makedirs() as a side effect for
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
- if output_arg is None:
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 _dry_run_validate_one(
100
- input_path: str, output_path: str, folder: "Optional[str]", output_format: str
101
- ) -> None:
102
- """Same checks as validate_all(), fastest first, but uses the
103
- dry-run folder check instead of validate_output_path() when the
104
- output path is an auto-created batch folder that may not exist
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 folder is not None:
111
- _check_output_folder_creatable(folder)
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
- validate_image_readable(input_abs)
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
- Non-merge: mirrors the exit-code behavior of the real conversion
124
- loop in main() – a single input's failure returns that failure's
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
- --merge: mirrors convert_merge(), which combines all pages into
129
- ONE output and aborts on the first bad page rather than
130
- collecting per-file failures, so dry-run does the same (fail
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
- is_batch = len(expanded_inputs) > 1
111
+ total = len(plan.jobs) + len(plan.failures)
134
112
 
135
113
  if args.merge:
136
- # main() already rejects args.merge with args.output is None
137
- # before _run_dry_run is reached.
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 input_path in expanded_inputs:
129
+ for job in plan.jobs:
150
130
  try:
151
- input_abs = validate_input_file(input_path)
152
- validate_image_readable(input_abs)
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"'{input_path}': {exc}")
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(expanded_inputs)} file(s) OK for --merge "
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: list[tuple[str, str]] = []
146
+ failures = 0
164
147
  last_exit_code = EXIT_OK
165
-
166
- for input_path in expanded_inputs:
167
- output_path, folder = _dry_run_resolve_output_path(
168
- args.output, input_path, is_batch, args.format
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
- _dry_run_validate_one(input_path, output_path, folder, args.format)
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"'{input_path}': {exc}")
175
- failures.append((input_path, str(exc)))
161
+ log_error(log, f"'{job.source_path}': {exc}")
162
+ failures += 1
176
163
  last_exit_code = code
177
- if not is_batch:
164
+ if total <= 1:
178
165
  return last_exit_code
179
166
 
180
167
  if failures:
181
- if is_batch:
168
+ if total > 1:
182
169
  log_error(
183
170
  log,
184
- f"dry-run: {len(failures)}/{len(expanded_inputs)} "
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: {len(expanded_inputs)} file(s) OK, no output written.")
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 "