James R. Barlow
3d291e72c0
Enable check_untyped_defs and make mypy hook blocking
...
Fix the 13 errors that surfaced under mypy --check-untyped-defs so the
flag can be turned on permanently in pyproject.toml, and drop the
advisory exit-0 wrapper on the mypy pre-commit hook now that the tree is
clean.
- _plugin_manager: rename colliding loop vars (module/name were reused
with conflicting types) and guard spec/spec.loader from
spec_from_file_location; call __init__ via the class in __setstate__.
- __main__: pass Verbosity(options.verbose), not a bare int.
- subprocess/_check: widen package to str | Mapping[str, str] to match
_error_trailer's existing per-platform handling.
- optimize.main: annotate the standalone PdfContext(..., None, None) that
only ever reads context.options.
2026-07-07 15:02:32 -07:00
James R. Barlow
a13d27bfb5
Protect stdout from corruption when writing PDF to standard output
...
Writing the output PDF to stdout (ocrmypdf in.pdf -) previously relied on
an honor system: no in-process code -- third-party libraries, plugins, or
stray print() calls -- was supposed to write to stdout, enforced only
indirectly. A single accidental write to fd 1 would silently corrupt the
output PDF.
Enforce this at the OS level. At CLI startup, before plugins load or any
worker process/thread starts, save the real stdout via os.dup() and point
fd 1 at stderr, so stray writes are diverted to stderr while only the final
"produce the PDF" step writes to the preserved descriptor. Exposed as the
opt-in public API function configure_stdout_protection(), mirroring
configure_logging(); it is not enabled inside ocr() so in-process library
users keep their own stdout.
Also fix check_requested_output_file() to test the preserved real stdout
for tty-ness, since after the redirect sys.stdout reports stderr's status.
Fold unreleased v17.7.2 notes into v17.8.0.
2026-06-28 12:02:34 -07:00
James R. Barlow
b7737446e4
cli: push up imports
2025-12-21 12:21:48 -08:00
James R. Barlow and aider
4f9c4c3e52
refactor: reorganize CLI and options initialization
...
Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat >
2025-12-21 12:21:48 -08:00
James R. Barlow and aider
d0a46a0359
feat: convert CLI Namespace to OCROptions in main entry point
...
Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat >
2025-12-21 12:21:47 -08:00
James R. Barlow
61163c2aa9
Fix stupid Python runtimeerror
2025-06-13 01:46:30 -07:00
James R. Barlow
332369f1b0
Adjust set_start_method decision, changing fork to forkserver for platforms other than win32, darwin
2025-06-13 01:22:01 -07:00
James R. Barlow
db3df13e95
Remove ocrmypdf._sync
2023-10-24 00:54:31 -07:00
James R. Barlow
b9646b6f85
Enable multiprocessing freeze_support (for Windows) and enable forkserver
...
Since we use a thread for logging among other possibilities, we were
never able to use threads safely when forking. forkserver will do the job.
2023-10-24 00:54:30 -07:00
James R. Barlow
e8ae370ceb
Eliminate api= kwarg and implicit creation of pluginmanager
2023-10-24 00:54:30 -07:00
James R. Barlow
4924b11b6b
Additional ruff fixes
2023-04-14 01:25:16 -07:00
James R. Barlow
9b8d14d16e
Accept most of ruff's delinting
2023-04-14 00:45:34 -07:00
James R. Barlow
8a3b82e364
Make Python 3.8 minimum requirement
2022-08-02 14:46:01 -07:00
James R. Barlow
80ed2117cc
Change to SPDX license tracking
2022-07-28 01:10:07 -07:00
James R. Barlow
dc6f1a266a
Modernize type annotations
2022-07-23 00:39:24 -07:00
James R. Barlow
b17fb61389
Configure pylint in pyproject and delint
2022-06-12 00:30:44 -07:00
James R. Barlow
d640c2ded3
Tidy some if condition -> EAFP
2022-06-11 00:21:21 -07:00
Robert Schütz and GitHub
808b24d59f
ignore PermissionError when calling os.nice() ( #973 )
2022-05-28 18:07:54 -07:00
James R. Barlow
380b981763
Remove most Python 3.6 special casing
2021-11-13 00:27:48 -08:00
James R. Barlow
b1da09f141
Add plugin for setting logging console
...
So that we are not tied to tqdm.
2021-01-31 02:29:11 -08:00
James R. Barlow
aa0ec40102
Change license of all GPLv3 files to MPL-2.0
...
https://github.com/jbarlow83/OCRmyPDF/issues/600
2020-08-05 00:44:42 -07:00
James R. Barlow
addc2cbad0
Enable pikepdf mmap and set up signal handlers
2020-07-22 00:19:50 -07:00
James R. Barlow
64891c2fc3
Pre-release delinting
2020-06-09 15:27:14 -07:00
James R. Barlow
9bccff4f88
Move Tesseract specific arguments to plugin
2020-05-16 03:24:31 -07:00
James R. Barlow
2bd586e093
Compare requested languages to OCR engine instead of tesseract directly
...
Also refactoring to facilitating validation needing the plugin manager.
2020-05-16 01:50:37 -07:00
James R. Barlow
39888ae8c9
Rename install_cli to add_options
2020-05-06 01:10:09 -07:00
James R. Barlow
c85278b31d
Delinting
2020-05-03 00:53:29 -07:00
James R. Barlow
e02f6c1e97
Support plugin invocation with API
2020-05-02 03:34:31 -07:00
James R. Barlow
23d558ad8c
Allow plugins to add command line arguments
2020-05-02 01:37:24 -07:00
James R. Barlow
2c07515907
macOS - use spawn for multiprocessing
...
See bpo-33725. This is the default for 3.8, opt-in for 3.7 and older.
2020-04-26 03:49:40 -07:00
James R. Barlow
d146d2b65c
The Great Logging Refactor
...
Remove all instances of logger object being passed as parameters.
This was a holdover from ruffus, and complicated a lot of simple things.
2020-04-14 23:59:33 -07:00
James R. Barlow
5f00e4f9d8
Sort imports
2019-07-27 04:51:52 -07:00
James R. Barlow
eb5200d26a
Change most tests to use ocrmypdf API instead of subprocess
...
The main benefit of this is code coverage gains can actually follow it.
Also removes most ugly os.environ hacks.
2019-06-03 01:45:27 -07:00
James R. Barlow
ed236e0c27
Begin API documentation
2019-05-24 01:05:32 -07:00
James R. Barlow
805aa776ad
Re-disable progress bar when not connected to tty
2019-05-23 02:00:35 -07:00
James R. Barlow
09ca1bee97
Add progress bar to optimize and add option to disable it
2019-05-22 15:31:48 -07:00
James R. Barlow
32a076c039
Refactor validation and exceptions
...
CLI now tracks check_options exceptions. API now works more like
an API, without an exception handler,
because the caller should provide one.
2019-05-20 18:01:17 -07:00
James R. Barlow
2fdaa76a0d
Refactor configure_logging
2019-05-20 14:54:34 -07:00
James R. Barlow
7ee0c52a57
Refactor cli into basic high level api
2019-05-19 22:34:45 -07:00
James R. Barlow
24da92d39e
Fix extra blank lines in output messages in Python 3.6
2019-05-17 14:56:33 -07:00
James R. Barlow
13ab23ba54
Refactor weave_layers, introduce progress bar
...
Fixes a bug in this branch where --sidecar would fail by trying to iterator
the executor futures twice.
2019-05-16 14:57:31 -07:00
James R. Barlow
19263f00c6
Additional logging fixes; silence extremely verbose pdfminer logging
2019-05-16 13:44:44 -07:00
James R. Barlow
471cdea232
Move app specific settings a library may not want to __main__
2019-05-16 01:29:26 -07:00
James R. Barlow
9d750828c7
Make logging format consistent with v8.3.0
2019-05-16 00:48:40 -07:00
James R. Barlow
5e025c3382
Reinstate log level in messages to be closer to old behavior
2019-05-15 15:46:36 -07:00
James R. Barlow
4410503349
More fixes to logging and disabled tests
2019-05-15 03:08:09 -07:00
James R. Barlow
c904b430b6
Merge master into api branch; all test pass
2019-05-14 16:33:02 -07:00
James R. Barlow
91cb092aa0
Remove PyCharm debugger hack
2019-04-18 10:15:02 -07:00
mawi
1c44fd4f3b
fix: typo
2019-04-08 15:01:04 +02:00
mawi
c92ccc6134
fix: tests
2019-04-08 14:57:42 +02:00