Overhaul version checkers to prefer Version to str

This commit is contained in:
James R. Barlow
2023-09-25 00:59:44 -07:00
parent bd4d44e182
commit ea36aedb5f
12 changed files with 57 additions and 39 deletions
+3 -4
View File
@@ -70,8 +70,8 @@ log.addFilter(DuplicateFilter(log))
GS = 'gswin64c' if os.name == 'nt' else 'gs'
def version():
return get_version(GS)
def version() -> Version:
return Version(get_version(GS))
def _gs_error_reported(stream) -> bool:
@@ -216,8 +216,7 @@ def generate_pdfa(
"-dAutoFilterGrayImages=true",
]
strategy = 'LeaveColorUnchanged'
gs_version = Version(version())
gs_version = version()
if gs_version == Version('9.56.0'):
# 9.56.0 breaks our OCR, should be fixed in 9.56.1
# https://bugs.ghostscript.com/show_bug.cgi?id=705187
+4 -2
View File
@@ -7,12 +7,14 @@ from __future__ import annotations
from subprocess import PIPE
from packaging.version import Version
from ocrmypdf.exceptions import MissingDependencyError
from ocrmypdf.subprocess import get_version, run
def version():
return get_version('jbig2', regex=r'jbig2enc (\d+(\.\d+)*).*')
def version() -> Version:
return Version(get_version('jbig2', regex=r'jbig2enc (\d+(\.\d+)*).*'))
def available():
+3 -2
View File
@@ -10,14 +10,15 @@ from io import BytesIO
from pathlib import Path
from subprocess import PIPE
from packaging.version import Version
from PIL import Image
from ocrmypdf.exceptions import MissingDependencyError
from ocrmypdf.subprocess import get_version, run
def version():
return get_version('pngquant', regex=r'(\d+(\.\d+)*).*')
def version() -> Version:
return Version(get_version('pngquant', regex=r'(\d+(\.\d+)*).*'))
def available():
+3 -3
View File
@@ -113,13 +113,13 @@ class TesseractVersion(Version):
)
def version() -> str:
return get_version('tesseract', regex=r'tesseract\s(.+)')
def version() -> Version:
return TesseractVersion(get_version('tesseract', regex=r'tesseract\s(.+)'))
def has_thresholding() -> bool:
"""Does Tesseract have -c thresholding method capability?"""
return version() >= '5.0'
return version() >= Version('5.0')
def get_languages() -> set[str]:
+3 -2
View File
@@ -15,6 +15,7 @@ from pathlib import Path
from subprocess import PIPE, STDOUT
from typing import Iterator, Union
from packaging.version import Version
from PIL import Image
from ocrmypdf.exceptions import MissingDependencyError, SubprocessOutputError
@@ -67,8 +68,8 @@ class UnpaperImageTooLargeError(Exception):
super().__init__(self.message)
def version() -> str:
return get_version('unpaper')
def version() -> Version:
return Version(get_version('unpaper'))
SUPPORTED_MODES = {'1', 'L', 'RGB'}