Fix --jpeg-quality/--jpg-quality being dropped by the CLI (closes #1723)
namespace_to_options() only copied argparse namespace keys that were literal members of OcrOptions.model_fields. The CLI dest for both --jpeg-quality and --jpg-quality was jpeg_quality, but the pydantic field was named jpg_quality (jpeg_quality existed only as a compatibility property, absent from model_fields). The value was silently dropped into extra_attrs, and the optimizer always fell back to its own hardcoded default regardless of the flag. The same alias mismatch also affected the Python API: create_options() uses the same model_fields-matching logic as namespace_to_options(), so ocrmypdf.ocr(jpeg_quality=...) was silently dropped too - only the canonical jpg_quality= kwarg worked. Rather than patch around the mismatch, consolidate on a single canonical name: OcrOptions.jpeg_quality (matching the primary --jpeg-quality CLI flag and the already-consistent naming in OptimizeOptions). jpg_quality becomes a deprecated compatibility property, and ocrmypdf.ocr(jpg_quality=) is a deprecated alias that warns and forwards to jpeg_quality via a new create_options() remap step. --jpg-quality remains a working (already hidden) CLI alias with no code-path divergence, since it now shares an argparse dest that matches the field name directly.
This commit is contained in:
@@ -89,8 +89,15 @@ def test_mutex_options():
|
||||
make_ocr_opts(redo_ocr=True, force_ocr=True)
|
||||
|
||||
|
||||
def test_optimizing(caplog):
|
||||
vd.check_options(*make_opts_pm(optimize=0, png_quality=18, jpeg_quality=10))
|
||||
def test_optimizing_png_quality_warns(caplog):
|
||||
vd.check_options(*make_opts_pm(optimize=0, png_quality=18))
|
||||
assert 'will be ignored because' in caplog.text
|
||||
|
||||
|
||||
def test_optimizing_jpeg_quality_warns(caplog):
|
||||
# Isolated from png_quality so this actually exercises the jpeg_quality
|
||||
# path rather than being confounded by png_quality also being set.
|
||||
vd.check_options(*make_opts_pm(optimize=0, jpeg_quality=10))
|
||||
assert 'will be ignored because' in caplog.text
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user