From b7eb93eb79a581e4c2afef4c26d211c10564ca05 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Fri, 14 Apr 2023 00:19:17 -0700 Subject: [PATCH] Adopt ruff and fix prelim lints --- docs/conf.py | 3 ++- pyproject.toml | 7 +++++++ src/ocrmypdf/_exec/tesseract.py | 6 ++++-- src/ocrmypdf/_graft.py | 3 ++- src/ocrmypdf/_pipeline.py | 4 ++-- src/ocrmypdf/_validation.py | 11 +++++------ tests/plugins/tesseract_debug_rotate.py | 6 ++++-- tests/plugins/tesseract_noop.py | 6 ++++-- tests/test_validation.py | 2 +- 9 files changed, 31 insertions(+), 17 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index ee636db6..a90813cf 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,6 +2,8 @@ # SPDX-FileCopyrightText: 2022 James R. Barlow # SPDX-License-Identifier: CC-BY-SA-4.0 +# ruff: noqa: E402 + # ocrmypdf documentation build configuration file, created by # sphinx-quickstart on Sun Sep 4 14:29:43 2016. # @@ -78,7 +80,6 @@ author = 'James R. Barlow' import os from importlib.metadata import version as package_version - on_rtd = os.environ.get('READTHEDOCS') == 'True' if on_rtd: diff --git a/pyproject.toml b/pyproject.toml index dda01034..4ee6f0fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -188,3 +188,10 @@ ignore_missing_imports = true good-names = ["i", "j", "k", "ex", "Run", "_", "e", "p", "im", "w", "h", "m", "x", "y", "a", "b", "fp", "n", "f", "s", "v", "q", "dx", "dy"] logging-format-style = "old" disable = ["raw-checker-failed", "bad-inline-option", "locally-disabled", "file-ignored", "suppressed-message", "useless-suppression", "deprecated-pragma", "use-symbolic-message-instead", "logging-fstring-interpolation", "missing-function-docstring", "too-few-public-methods"] + +[tool.ruff] +src = ["src"] +select = ["E"] + +[tool.ruff.pydocstyle] +convention = "google" \ No newline at end of file diff --git a/src/ocrmypdf/_exec/tesseract.py b/src/ocrmypdf/_exec/tesseract.py index db4b209e..99a0715a 100644 --- a/src/ocrmypdf/_exec/tesseract.py +++ b/src/ocrmypdf/_exec/tesseract.py @@ -34,10 +34,12 @@ HOCR_TEMPLATE = """ - + -
+
diff --git a/src/ocrmypdf/_graft.py b/src/ocrmypdf/_graft.py index ebefcac4..73a9cc92 100644 --- a/src/ocrmypdf/_graft.py +++ b/src/ocrmypdf/_graft.py @@ -131,7 +131,8 @@ class OcrGrafter: text_misaligned = (text_rotation - content_rotation) % 360 log.debug( f"Text rotation: (text, autorotate, content) -> text misalignment = " - f"({text_rotation}, {autorotate_correction}, {content_rotation}) -> {text_misaligned}" + f"({text_rotation}, {autorotate_correction}, {content_rotation}) -> " + f"{text_misaligned}" ) if textpdf and self.font: diff --git a/src/ocrmypdf/_pipeline.py b/src/ocrmypdf/_pipeline.py index bdfc4d84..f284f399 100644 --- a/src/ocrmypdf/_pipeline.py +++ b/src/ocrmypdf/_pipeline.py @@ -315,8 +315,8 @@ def is_ocr_required(page_context: PageContext) -> bool: log.warning( "page has no images - " "all vector content will be " - f"rasterized at {VECTOR_PAGE_DPI} DPI, losing some resolution and likely " - "increasing file size. Use --oversample to adjust the " + f"rasterized at {VECTOR_PAGE_DPI} DPI, losing some resolution and " + "likely increasing file size. Use --oversample to adjust the " "DPI." ) else: diff --git a/src/ocrmypdf/_validation.py b/src/ocrmypdf/_validation.py index 977ea14e..c88fbc24 100644 --- a/src/ocrmypdf/_validation.py +++ b/src/ocrmypdf/_validation.py @@ -109,12 +109,10 @@ def check_options_output(options: Namespace) -> None: def check_options_sidecar(options: Namespace) -> None: if options.sidecar == '\0': if options.output_file == '-': - raise BadArgsError( - "--sidecar filename must be specified when output file is stdout." - ) + raise BadArgsError("--sidecar filename needed when output file is stdout.") elif options.output_file == os.devnull: raise BadArgsError( - "--sidecar filename must be specified when output file is /dev/null or NUL." + "--sidecar filename needed when output file is /dev/null or NUL." ) options.sidecar = options.output_file + '.txt' if options.sidecar == options.input_file or options.sidecar == options.output_file: @@ -276,7 +274,8 @@ def create_input_file(options: Namespace, work_folder: Path) -> tuple[Path, str] "permissions correctly.\n" "You may find it easier to use stdin/stdout:" "\n" - "\tdocker run -i --rm jbarlow83/ocrmypdf - - output.pdf\n" + "\tdocker run -i --rm jbarlow83/ocrmypdf - - output.pdf" + "\n" ) raise InputFileError(msg) from e @@ -333,7 +332,7 @@ def report_output_file_size( for arg in image_preproc: if getattr(options, arg, False): reasons.append( - f"The argument --{arg.replace('_', '-')} was issued, causing transcoding." + f"--{arg.replace('_', '-')} was issued, causing transcoding." ) reasons.extend(optimize_messages) diff --git a/tests/plugins/tesseract_debug_rotate.py b/tests/plugins/tesseract_debug_rotate.py index 1e10cfb7..65655e2b 100644 --- a/tests/plugins/tesseract_debug_rotate.py +++ b/tests/plugins/tesseract_debug_rotate.py @@ -28,13 +28,15 @@ HOCR_TEMPLATE = ''' - +

- + +

diff --git a/tests/plugins/tesseract_noop.py b/tests/plugins/tesseract_noop.py index 68a0bfe6..5bb66053 100644 --- a/tests/plugins/tesseract_noop.py +++ b/tests/plugins/tesseract_noop.py @@ -26,13 +26,15 @@ HOCR_TEMPLATE = ''' - +

- + +

diff --git a/tests/test_validation.py b/tests/test_validation.py index d181e85a..5c6ceeb6 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -219,7 +219,7 @@ def test_version_comparison(): vd.check_external_program( program="tesseract", package="tesseract", - version_checker=lambda: 'v4.1.1.20181030', # Some Windows builds use this format + version_checker=lambda: 'v4.1.1.20181030', # Used in some Windows builds need_version='4.1.1', version_parser=TesseractVersion, )