Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21cacad93b | ||
|
|
3589f4e7d1 | ||
|
|
1cdc2591e5 | ||
|
|
e05f9575a8 | ||
|
|
10c703e119 | ||
|
|
0ac15dd0b2 | ||
|
|
808b24d59f |
@@ -18,6 +18,13 @@ tagged yet.
|
|||||||
|
|
||||||
.. |OCRmyPDF PyPI| image:: https://img.shields.io/pypi/v/ocrmypdf.svg
|
.. |OCRmyPDF PyPI| image:: https://img.shields.io/pypi/v/ocrmypdf.svg
|
||||||
|
|
||||||
|
v13.4.7
|
||||||
|
=======
|
||||||
|
|
||||||
|
- Fixed PermissionError when cleaning up temporary files in rare cases. :issue:`974`
|
||||||
|
- Fixed PermissionError when calling ``os.nice`` on platforms that lack it. :issue:`973`
|
||||||
|
- Suppressed some warnings from libxmp during tests.
|
||||||
|
|
||||||
v13.4.6
|
v13.4.6
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
|
from contextlib import suppress
|
||||||
from multiprocessing import set_start_method
|
from multiprocessing import set_start_method
|
||||||
|
|
||||||
from ocrmypdf import __version__
|
from ocrmypdf import __version__
|
||||||
@@ -34,7 +35,7 @@ def sigbus(*args):
|
|||||||
def run(args=None):
|
def run(args=None):
|
||||||
_parser, options, plugin_manager = get_parser_options_plugins(args=args)
|
_parser, options, plugin_manager = get_parser_options_plugins(args=args)
|
||||||
|
|
||||||
if hasattr(os, 'nice'):
|
with suppress(AttributeError, PermissionError):
|
||||||
os.nice(5)
|
os.nice(5)
|
||||||
|
|
||||||
verbosity = options.verbose
|
verbosity = options.verbose
|
||||||
|
|||||||
@@ -13,11 +13,11 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import shlex
|
import shlex
|
||||||
|
import sys
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from subprocess import PIPE, STDOUT
|
from subprocess import PIPE, STDOUT
|
||||||
from tempfile import TemporaryDirectory
|
|
||||||
from typing import Iterator, List, Optional, Tuple, Union
|
from typing import Iterator, List, Optional, Tuple, Union
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
@@ -25,6 +25,23 @@ from PIL import Image
|
|||||||
from ocrmypdf.exceptions import MissingDependencyError, SubprocessOutputError
|
from ocrmypdf.exceptions import MissingDependencyError, SubprocessOutputError
|
||||||
from ocrmypdf.subprocess import get_version, run
|
from ocrmypdf.subprocess import get_version, run
|
||||||
|
|
||||||
|
if sys.version_info >= (3, 10):
|
||||||
|
from tempfile import TemporaryDirectory
|
||||||
|
else:
|
||||||
|
from tempfile import TemporaryDirectory as _TemporaryDirectory
|
||||||
|
|
||||||
|
# Consume the ignore_cleanup_errors kwarg in Python 3.9 and older, without acting
|
||||||
|
# on this keyword. Users who need this issue full resolved should upgrade to Python
|
||||||
|
# 3.10.
|
||||||
|
# See: https://github.com/python/cpython/pull/24793
|
||||||
|
|
||||||
|
class TemporaryDirectory(_TemporaryDirectory):
|
||||||
|
def __init__(self, ignore_cleanup_errors=False, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
del _TemporaryDirectory
|
||||||
|
|
||||||
|
|
||||||
UNPAPER_IMAGE_PIXEL_LIMIT = 256 * 1024 * 1024
|
UNPAPER_IMAGE_PIXEL_LIMIT = 256 * 1024 * 1024
|
||||||
|
|
||||||
DecFloat = Union[Decimal, float]
|
DecFloat = Union[Decimal, float]
|
||||||
@@ -82,7 +99,7 @@ def _setup_unpaper_io(input_file: Path) -> Iterator[Tuple[Path, Path, Path]]:
|
|||||||
raise UnpaperImageTooLargeError(w=im.width, h=im.height)
|
raise UnpaperImageTooLargeError(w=im.width, h=im.height)
|
||||||
im, im_modified, suffix = _convert_image(im)
|
im, im_modified, suffix = _convert_image(im)
|
||||||
|
|
||||||
with TemporaryDirectory() as tmpdir:
|
with TemporaryDirectory(ignore_cleanup_errors=True) as tmpdir:
|
||||||
tmppath = Path(tmpdir)
|
tmppath = Path(tmpdir)
|
||||||
if im_modified or input_file.suffix != '.pnm':
|
if im_modified or input_file.suffix != '.pnm':
|
||||||
input_pnm = tmppath / 'input.pnm'
|
input_pnm = tmppath / 'input.pnm'
|
||||||
|
|||||||
+19
-9
@@ -6,10 +6,10 @@
|
|||||||
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import warnings
|
||||||
from datetime import timezone
|
from datetime import timezone
|
||||||
from os import fspath
|
from os import fspath
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
import pikepdf
|
import pikepdf
|
||||||
import pytest
|
import pytest
|
||||||
@@ -173,6 +173,19 @@ def test_creation_date_preserved(output_type, resources, infile, outpdf):
|
|||||||
assert seconds_between_dates(date_after, datetime.datetime.now(timezone.utc)) < 1000
|
assert seconds_between_dates(date_after, datetime.datetime.now(timezone.utc)) < 1000
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def libxmp_file_to_dict():
|
||||||
|
try:
|
||||||
|
with warnings.catch_warnings():
|
||||||
|
warnings.simplefilter("ignore", DeprecationWarning)
|
||||||
|
from libxmp.utils import (
|
||||||
|
file_to_dict, # pylint: disable=import-outside-toplevel
|
||||||
|
)
|
||||||
|
except Exception: # pylint: disable=broad-except
|
||||||
|
pytest.skip("libxmp not available or libexempi3 not installed")
|
||||||
|
return file_to_dict
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'test_file,output_type',
|
'test_file,output_type',
|
||||||
[
|
[
|
||||||
@@ -182,15 +195,12 @@ def test_creation_date_preserved(output_type, resources, infile, outpdf):
|
|||||||
('3small.pdf', 'pdfa'),
|
('3small.pdf', 'pdfa'),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_xml_metadata_preserved(test_file, output_type, resources, outpdf):
|
def test_xml_metadata_preserved(
|
||||||
|
libxmp_file_to_dict, test_file, output_type, resources, outpdf
|
||||||
|
):
|
||||||
input_file = resources / test_file
|
input_file = resources / test_file
|
||||||
|
|
||||||
try:
|
before = libxmp_file_to_dict(str(input_file))
|
||||||
from libxmp.utils import file_to_dict # pylint: disable=import-outside-toplevel
|
|
||||||
except Exception: # pylint: disable=broad-except
|
|
||||||
pytest.skip("libxmp not available or libexempi3 not installed")
|
|
||||||
|
|
||||||
before = file_to_dict(str(input_file))
|
|
||||||
|
|
||||||
check_ocrmypdf(
|
check_ocrmypdf(
|
||||||
input_file,
|
input_file,
|
||||||
@@ -202,7 +212,7 @@ def test_xml_metadata_preserved(test_file, output_type, resources, outpdf):
|
|||||||
'tests/plugins/tesseract_noop.py',
|
'tests/plugins/tesseract_noop.py',
|
||||||
)
|
)
|
||||||
|
|
||||||
after = file_to_dict(str(outpdf))
|
after = libxmp_file_to_dict(str(outpdf))
|
||||||
|
|
||||||
equal_properties = [
|
equal_properties = [
|
||||||
'dc:contributor',
|
'dc:contributor',
|
||||||
|
|||||||
Reference in New Issue
Block a user