Contributing
The full guide lives at CONTRIBUTING.md in the repository root; this page mirrors the essentials.
pytest after installing the test extra; CI also uploads coverage to Codecov. A few of the newer or trickier modules still have no coverage, see Adding tests below.
Development setup
git clone https://github.com/Hyacinthe-primus/scanlayer.git
cd scanlayer
python -m venv .venv
source .venv/bin/activate # .venv\Scripts\activate on Windows
# development + test tooling (pytest, pytest-cov, pypdf)
pip install -e ".[test]"
# optional: benchmark harness dependencies (psutil, pypdf)
pip install -e ".[test,bench]"
You will also need Tesseract OCR (and poppler, for PDF-input work), see Installation.
Project layout
scanlayer/
├── __init__.py # public API: convert, convert_batch, convert_merge, configure
├── main.py # the top-level convert()/convert_batch()/convert_merge()
├── config.py # all tunables, Tesseract/poppler discovery
├── cli/ # argparse CLI: parser.py, run.py, dry_run.py
├── preprocessing/enhance.py # EXIF/OSD/deskew, illumination, denoise, CLAHE, sharpen
├── ocr/engine.py # PSM candidate racing, Tesseract invocation, OCR ceiling
├── ocr/export.py # txt/json/tsv/hocr exporters
├── layout/columns.py # multi-column reading-order reconstruction
├── pdf/builder.py # searchable PDF construction (single + multi-page)
├── pdf/fonts.py # automatic font selection
└── utils/ # validators, exceptions, logging, resources, debug-image
The repository root also contains benchmarks/ (opt-in harness) and
tests/ (pytest suite), neither of which is part of the installed package.
Benchmarks
The benchmarks/ directory is a separate, opt-in harness. It is not part of
the default pytest run: it generates a deterministic synthetic corpus and reports stage
timings, end-to-end timings, and batch throughput.
pip install -e ".[test,bench]"
# batch throughput: sequential vs bounded parallel
python -m benchmarks.bench_batch --repeats 2 --batch-workers 1
python -m benchmarks.bench_batch --repeats 2 --batch-workers 2
# full pipeline on the synthetic corpus
python -m benchmarks.bench_pipeline --repeats 2 --warmup 1 --psm 3
See benchmarks/README.md in the repository for the corpus, every flag, and
the caveats (thermal variance, synthetic pages, and why the PDF streaming path trades
startup cost for memory).
Making a change
- Open an issue first for anything non-trivial (new flags, a changed default, anything touching the exception hierarchy). Small, obviously-correct fixes can go straight to a PR.
- Keep the CLI and library in sync: every capability should be
reachable both ways, with matching parameter names (
--lang↔lang=). - Respect the two-tier exception hierarchy: a failed precondition is a
ValidationErrorsubclass; an operational failure mid-stage is aPipelineErrorsubclass. Map any new exception to a CLI exit code. See Library API → Exceptions. - Never let OCR-only processing touch the visual background:
backgroundandocr_imagestay separate throughoutpreprocessing/enhance.py. - Update the docs in the same PR: new CLI flag → CLI Reference; new library parameter → Library API; new default → Configuration; new capability → Feature Catalog.
Adding tests
The tests/ directory covers config.py, utils/validators.py,
layout/columns.py, ocr/export.py, pdf/fonts.py,
pdf/builder.py, the --dry-run flag, batch planning and parallel
execution, incremental PDF streaming, resource guards, and an end-to-end convert()
test (skipped automatically without a real Tesseract install). Run it with pytest
after pip install -e ".[test]"; CI also uploads coverage to Codecov. Coverage
gaps worth closing next, in priority order:
- End-to-end cases with real Tesseract on a genuine multi-column sample, a rotated sample, and a blank-page sample, asserting on word-count/confidence ranges rather than exact OCR text (which shifts across Tesseract versions).
- Merge failure paths, especially a page failing after earlier pages have already completed, and the interaction between merge workers and the global OCR ceiling.
- Concurrency isolation: independent
convert_batch()calls in one process are a documented limitation, so a test that pins the intended single-batch contract (and the documented failure mode) would prevent silent regressions. - Platform coverage: Tesseract discovery is unit-tested with mocked paths; a CI job on macOS and Windows would exercise the real binaries end to end.
Submitting
- One logical change per PR.
- Describe what you tested it against (image type, OS, Tesseract version); CI runs the suite on push, but a manual check of your actual scenario is still welcome.
- Reference the issue you opened, if applicable.
By contributing, you agree your contribution is licensed under this project's MIT License.