diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a34c046b..23820f1b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,6 +6,7 @@ on: - master - ci - release/* + - feature/* tags: - v* paths-ignore: diff --git a/docs/conf.py b/docs/conf.py index bc77b700..a17933cd 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -56,7 +56,7 @@ master_doc = 'index' # General information about the project. project = 'ocrmypdf' copyright = ( - '2020, James R. Barlow. Licensed under Creative Commons Attribution-ShareAlike 4.0.' + '2021, James R. Barlow. Licensed under Creative Commons Attribution-ShareAlike 4.0.' ) author = 'James R. Barlow' @@ -88,11 +88,10 @@ if on_rtd: ] sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES) - -from pkg_resources import get_distribution, DistributionNotFound +from importlib_metadata import version as package_version # The full version, including alpha/beta/rc tags. -release = get_distribution('ocrmypdf').version +release = package_version('ocrmypdf').version version = '.'.join(release.split('.')[:2]) diff --git a/setup.cfg b/setup.cfg index 34569e80..42e362d5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -49,12 +49,13 @@ install_requires = cffi>=1.9.1 # must be a setup and install requirement coloredlogs>=14.0 # strictly optional img2pdf>=0.3.0,<0.5 # pure Python + importlib-metadata>=4 # until Python 3.8 + importlib-resources>=5 # until Python 3.9 pdfminer.six!=20200720,>=20191110,<=20201018 pikepdf>=2.10.0 pikepdf<3;implementation_name=="pypy" and python_version=='3.6' pluggy>=0.13.0,<2 reportlab>=3.5.66 - setuptools tqdm>=4 python_requires = >=3.6 include_package_data = True diff --git a/src/ocrmypdf/_version.py b/src/ocrmypdf/_version.py index 6751fede..091eacf9 100644 --- a/src/ocrmypdf/_version.py +++ b/src/ocrmypdf/_version.py @@ -5,9 +5,9 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. -import pkg_resources +from importlib_metadata import version as _package_version PROGRAM_NAME = 'ocrmypdf' # Official PEP 396 -__version__ = pkg_resources.get_distribution('ocrmypdf').version +__version__ = _package_version('ocrmypdf') diff --git a/src/ocrmypdf/data/__init__.py b/src/ocrmypdf/data/__init__.py new file mode 100644 index 00000000..ad56a522 --- /dev/null +++ b/src/ocrmypdf/data/__init__.py @@ -0,0 +1,8 @@ +# © 2021 James R. Barlow: github.com/jbarlow83 +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + +"""Data files used to generate certain PDFs.""" diff --git a/src/ocrmypdf/pdfa.py b/src/ocrmypdf/pdfa.py index 4eaee8f1..cc34f906 100644 --- a/src/ocrmypdf/pdfa.py +++ b/src/ocrmypdf/pdfa.py @@ -13,13 +13,17 @@ import base64 from pathlib import Path from typing import Dict, Iterator, Union +import importlib_resources import pikepdf -import pkg_resources +import pkg_resources # deprecated +# Deprecated ICC_PROFILE_RELPATH = 'data/sRGB.icc' - +# Deprecated SRGB_ICC_PROFILE = pkg_resources.resource_filename('ocrmypdf', ICC_PROFILE_RELPATH) +SRGB_ICC_PROFILE_NAME = 'sRGB.icc' + def _postscript_objdef( alias: str, @@ -97,12 +101,12 @@ def generate_pdfa_ps(target_filename: Path, icc: str = 'sRGB'): References: Adobe PDFMARK Reference: https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdfmark_reference.pdf """ - if icc == 'sRGB': - icc_profile = SRGB_ICC_PROFILE - else: + if icc != 'sRGB': raise NotImplementedError("Only supporting sRGB") - bytes_icc_profile = Path(icc_profile).read_bytes() + bytes_icc_profile = importlib_resources.read_binary( + 'ocrmypdf.data', SRGB_ICC_PROFILE_NAME + ) ps = '\n'.join(_make_postscript(icc, bytes_icc_profile, 3)) # We should have encoded everything to pure ASCII by this point, and