From 4030258bbcc05a5c4fdee10d3d4d00b4e4da7911 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Wed, 9 Jun 2021 00:47:39 -0700 Subject: [PATCH] Modernize build system to use setup.cfg For now, keep but deprecate the requirements/*.txt files. --- .docker/Dockerfile | 7 +-- .github/workflows/build.yml | 6 +- .gitignore | 1 + docs/batch.rst | 2 +- docs/installation.rst | 3 +- pyproject.toml | 5 +- requirements/main.txt | 4 +- requirements/test.txt | 1 + requirements/watcher.txt | 1 + requirements/webservice.txt | 1 + setup.cfg | 108 +++++++++++++++++++++++++++++++++--- setup.py | 74 +----------------------- src/ocrmypdf/RELEASE.md | 2 +- 13 files changed, 118 insertions(+), 97 deletions(-) diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 4700004e..c55fcd7c 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -37,12 +37,7 @@ COPY . /app WORKDIR /app -RUN pip3 install --no-cache-dir \ - -r requirements/main.txt \ - -r requirements/webservice.txt \ - -r requirements/test.txt \ - -r requirements/watcher.txt \ - . +RUN pip3 install --no-cache-dir .[test,webservice,watcher] FROM base diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cad70f3f..cba6c85e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,7 +67,7 @@ jobs: - name: Install Python packages run: | - python -m pip install -r requirements/main.txt -r requirements/test.txt . + python -m pip install .[test] - name: Report versions run: | @@ -124,7 +124,7 @@ jobs: - name: Install Python packages run: | python -m pip install --upgrade pip - python -m pip install -r requirements/main.txt -r requirements/test.txt . + python -m pip install .[test] - name: Report versions run: | @@ -174,7 +174,7 @@ jobs: - name: Install Python packages run: | python -m pip install --upgrade pip - python -m pip install -r requirements/main.txt -r requirements/test.txt . + python -m pip install .[test] - name: Test run: | diff --git a/.gitignore b/.gitignore index 60de406b..39ace52f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ !.pre-commit-config.yaml !.readthedocs.yml !.github/ +!.docker/ # Dev scratch *.ipynb diff --git a/docs/batch.rst b/docs/batch.rst index e8e97374..e66388df 100644 --- a/docs/batch.rst +++ b/docs/batch.rst @@ -111,7 +111,7 @@ Users may need to customize the script to meet their requirements. .. code-block:: bash - pip3 install -r requirements/watcher.txt + pip3 install ocrmypdf[watcher] env OCR_INPUT_DIRECTORY=/mnt/input-pdfs \ OCR_OUTPUT_DIRECTORY=/mnt/output-pdfs \ diff --git a/docs/installation.rst b/docs/installation.rst index 6d096996..5b42f11f 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -812,8 +812,7 @@ To install all of the development and test requirements: python3 -m venv source venv/bin/activate cd OCRmyPDF - pip install -e . - pip install -r requirements/dev.txt -r requirements/test.txt + pip install -e .[test] To add JBIG2 encoding, see :ref:`jbig2`. diff --git a/pyproject.toml b/pyproject.toml index a28f55c0..8791923e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,11 +3,14 @@ requires = [ "setuptools >= 30.3.0", "wheel", "cffi", - "setuptools_scm", + "setuptools_scm[toml] >= 3.4", "setuptools_scm_git_archive" ] build-backend = "setuptools.build_meta" +[tool.setuptools_scm] +version_scheme = "post-release" + [tool.black] line-length = 88 target-version = ["py36", "py37", "py38"] diff --git a/requirements/main.txt b/requirements/main.txt index a49cf9fa..9d347f6f 100644 --- a/requirements/main.txt +++ b/requirements/main.txt @@ -1,6 +1,4 @@ -# requirements.txt can be used to replicate the developer's build environment -# setup.py lists a separate set of requirements that are looser to simplify -# installation +# Deprecated and not maintained; use "pip install ocrmypdf" instead cffi == 1.14.5 coloredlogs == 15.0 # technically optional img2pdf == 0.4.0 diff --git a/requirements/test.txt b/requirements/test.txt index 72225e2d..db7cb14e 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,3 +1,4 @@ +# Deprecated and not maintained; use "pip install ocrmypdf[test]" instead pytest >= 6.0.0 pytest-xdist >= 2.2.0 pytest-cov >= 2.11.1 diff --git a/requirements/watcher.txt b/requirements/watcher.txt index 660d7af4..b4a2b744 100644 --- a/requirements/watcher.txt +++ b/requirements/watcher.txt @@ -1 +1,2 @@ +# Deprecated and not maintained; use "pip install ocrmypdf[watcher]" instead watchdog == 1.0.2 diff --git a/requirements/webservice.txt b/requirements/webservice.txt index f6e3c4e6..7f8e08de 100644 --- a/requirements/webservice.txt +++ b/requirements/webservice.txt @@ -1 +1,2 @@ +# Deprecated and not maintained; use "pip install ocrmypdf[webservice]" instead Flask >= 1, < 2 diff --git a/setup.cfg b/setup.cfg index 36545d66..98bce9fa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,8 +1,101 @@ +[metadata] +name = ocrmypdf +description = OCRmyPDF adds an OCR text layer to scanned PDF files, allowing them to be searched +long_description = file: README.md +long_description_content_type = text/markdown; charset=UTF-8 +url = https://github.com/jbarlow83/OCRmyPDF +author = James R. Barlow +author_email = james@purplerock.ca +license_files = + LICENSE +keywords = + PDF + OCR + optical character recognition + PDF/A + scanning +classifiers = + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Development Status :: 5 - Production/Stable + Environment :: Console + Intended Audience :: End Users/Desktop + Intended Audience :: Science/Research + Intended Audience :: System Administrators + License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0) + Operating System :: MacOS :: MacOS X + Operating System :: Microsoft :: Windows :: Windows 10 + Operating System :: POSIX + Operating System :: POSIX :: BSD + Operating System :: POSIX :: Linux + Topic :: Scientific/Engineering :: Image Recognition + Topic :: Text Processing :: Indexing + Topic :: Text Processing :: Linguistic +project_urls = + Documentation = https://ocrmypdf.readthedocs.io/ + Source = https://github.com/jbarlow83/ocrmypdf + Tracker = https://github.com/jbarlow83/ocrmypdf/issues + +[options] +zip_safe = False +packages = find: +package_dir = + =src +platforms = any +include_package_data=True +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, so track HEAD closely + pdfminer.six >= 20191110, != 20200720, <= 20201018 + pikepdf >= 2.10.0 + Pillow >= 8.2.0 + pluggy >= 0.13.0, < 1.0 + reportlab >= 3.5.66 + setuptools + tqdm >= 4 +python_requires = >= 3.6 +setup_requires = # can be removed whenever we can drop pip 9 support + cffi >= 1.9.1 # to build the leptonica module + setuptools_scm # so that version will work + setuptools_scm_git_archive # enable version from github tarballs + +[options.package_data] +ocrmypdf = + data/sRGB.icc + py.typed + +[options.packages.find] +where = src + +[options.extras_require] +test = + pytest >= 6.0.0 + pytest-xdist >= 2.2.0 + pytest-cov >= 2.11.1 + python-xmp-toolkit == 2.0.1 # also requires apt-get install libexempi3 + # or brew install exempi +docs = + sphinx + sphinx_rtd_theme +extended_test = + PyMuPDF == 1.13.4 +watcher = + watchdog >= 1.0.2, < 2 +webservice = + Flask >= 1, < 2 + +[options.entry_points] +console_scripts = + ocrmypdf = ocrmypdf.__main__:run + [bdist_wheel] python-tag = py36 [aliases] -test=pytest +test = pytest [check-manifest] ignore = @@ -19,17 +112,14 @@ addopts = -n auto [isort] -multi_line_output=3 -include_trailing_comma=True -force_grid_wrap=0 -use_parentheses=True -line_length=88 +multi_line_output = 3 +include_trailing_comma = True +force_grid_wrap = 0 +use_parentheses = True +line_length = 88 known_first_party = ocrmypdf known_third_party = PIL,_cffi_backend,cffi,flask,img2pdf,pdfminer,pikepdf,pkg_resources,pluggy,pytest,reportlab,setuptools,sphinx_rtd_theme,tqdm,watchdog,werkzeug -[metadata] -license_file = LICENSE - [coverage:paths] source = src/ocrmypdf diff --git a/setup.py b/setup.py index e2342651..86f1ae36 100644 --- a/setup.py +++ b/setup.py @@ -1,62 +1,16 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# © 2015 James R. Barlow: github.com/jbarlow83 +# © 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/. -from __future__ import print_function, unicode_literals - -import sys - -from setuptools import find_packages, setup - -if sys.version_info < (3, 6): - print("Python 3.6 or newer is required", file=sys.stderr) - sys.exit(1) - -tests_require = open('requirements/test.txt', encoding='utf-8').read().splitlines() - - -def readme(): - with open('README.md', encoding='utf-8') as f: - return f.read() - +from setuptools import setup +# Minimal setup to support older setuptools/setuptools_scm setup( - name='ocrmypdf', - description='OCRmyPDF adds an OCR text layer to scanned PDF files, allowing them to be searched', - long_description=readme(), - long_description_content_type='text/markdown', - url='https://github.com/jbarlow83/OCRmyPDF', - author='James R. Barlow', - author_email='james@purplerock.ca', - packages=find_packages('src', exclude=["tests", "tests.*"]), - package_dir={'': 'src'}, - keywords=['PDF', 'OCR', 'optical character recognition', 'PDF/A', 'scanning'], - classifiers=[ - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Development Status :: 5 - Production/Stable", - "Environment :: Console", - "Intended Audience :: End Users/Desktop", - "Intended Audience :: Science/Research", - "Intended Audience :: System Administrators", - "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", - "Operating System :: MacOS :: MacOS X", - "Operating System :: Microsoft :: Windows :: Windows 10", - "Operating System :: POSIX", - "Operating System :: POSIX :: BSD", - "Operating System :: POSIX :: Linux", - "Topic :: Scientific/Engineering :: Image Recognition", - "Topic :: Text Processing :: Indexing", - "Topic :: Text Processing :: Linguistic", - ], - python_requires=' >= 3.6', setup_requires=[ # can be removed whenever we can drop pip 9 support 'cffi >= 1.9.1', # to build the leptonica module 'setuptools_scm', # so that version will work @@ -64,26 +18,4 @@ setup( ], use_scm_version={'version_scheme': 'post-release'}, cffi_modules=['src/ocrmypdf/lib/compile_leptonica.py:ffibuilder'], - 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, so track HEAD closely - 'pdfminer.six >= 20191110, != 20200720, <= 20201018', - "pikepdf >= 2.10.0", - 'Pillow >= 8.1.2', - 'pluggy >= 0.13.0, < 1.0', - 'reportlab >= 3.5.66', - 'setuptools', - 'tqdm >= 4', - ], - tests_require=tests_require, - entry_points={'console_scripts': ['ocrmypdf = ocrmypdf.__main__:run']}, - package_data={'ocrmypdf': ['data/sRGB.icc', 'py.typed']}, - include_package_data=True, - zip_safe=False, - project_urls={ - 'Documentation': 'https://ocrmypdf.readthedocs.io/', - 'Source': 'https://github.com/jbarlow83/ocrmypdf', - 'Tracker': 'https://github.com/jbarlow83/ocrmypdf/issues', - }, ) diff --git a/src/ocrmypdf/RELEASE.md b/src/ocrmypdf/RELEASE.md index 41a40e97..2cb89b78 100644 --- a/src/ocrmypdf/RELEASE.md +++ b/src/ocrmypdf/RELEASE.md @@ -28,7 +28,7 @@ - Search for deprecation: search all files for deprec*, etc. -- Check requirements/* +- Check requirements in setup.cfg - Delete `tests/cache`, do `pytest --runslow`, and update cache.