diff --git a/.github/workflows/run-tox.yml b/.github/workflows/run-tox.yml new file mode 100644 index 0000000..c656039 --- /dev/null +++ b/.github/workflows/run-tox.yml @@ -0,0 +1,48 @@ +name: Run all tox jobs using Python3 + +on: + pull_request: + push: + branches: + - main + workflow_dispatch: + +jobs: + tests: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9", "3.10", "3.11", "3.12"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Cache APT Packages + uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: imagemagick + version: 1.0 + execute_install_scripts: true + - name: Run tox + run: | + python -m pip install --upgrade pip setuptools + pip install tox-gh-actions + tox + - name: JUnit Report Action + uses: mikepenz/action-junit-report@v4 + if: always() # always run even if the previous step fails + with: + report_paths: 'reports/pytest-*.xml' + - name: Upload test artifacts + uses: actions/upload-artifact@v4 + if: always() + with: + name: tests-${{ matrix.python-version }} + retention-days: 4 + path: | + .tox/py*/tmp + reports diff --git a/diff_pdf_visually/diff.py b/diff_pdf_visually/diff.py index 7d01b69..969c612 100644 --- a/diff_pdf_visually/diff.py +++ b/diff_pdf_visually/diff.py @@ -28,7 +28,7 @@ def pdftopng(sourcepath, destdir, basename, verbosity, dpi): raise ValueError("destdir not clean: " + repr(destdir)) verbose_run( - (verbosity > VERB_PRINT_CMD), + (verbosity >= VERB_PRINT_CMD), [ "pdftocairo", "-png", @@ -136,6 +136,17 @@ def pdfdiff_pages( assert os.path.isfile(a), "file {} must exist".format(a) assert os.path.isfile(b), "file {} must exist".format(b) + if threshold is None: + threshold = DEFAULT_THRESHOLD + if verbosity is None: + verbosity = DEFAULT_VERBOSITY + if dpi is None: + dpi = DEFAULT_DPI + if num_threads is None: + num_threads = DEFAULT_NUM_THREADS + if max_report_pagenos is None: + max_report_pagenos = MAX_REPORT_PAGENOS + if tempdir == None: path_context = tempfile.TemporaryDirectory(prefix="diffpdf-") else: @@ -188,7 +199,7 @@ def pdfdiff_pages( diffpath = p / "diff-{}.png".format(pageno) logpath = p / "log-{}.txt".format(pageno) s = imgdiff( - pageapath, pagebpath, diffpath, logpath, (verbosity > VERB_PRINT_CMD) + pageapath, pagebpath, diffpath, logpath, (verbosity >= VERB_PRINT_CMD) ) if verbosity >= VERB_PERPAGE: print("- Page {}: significance={}".format(pageno, s)) diff --git a/pyproject.toml b/pyproject.toml index 9000678..49450cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,13 +1,45 @@ [project] -name = 'diff-pdf-visually' -description = 'Quickly check whether there is a visible difference between two PDFs, using ImageMagick and pdftocairo.' -authors = [{name = 'Bram Geron', email = 'bram@bram.xyz'}] -license = {text = 'MIT/Apache-2.0'} +name = "diff-pdf-visually" +description = "Quickly check whether there is a visible difference between two PDFs, using ImageMagick and pdftocairo." readme = "README.rst" -urls.Homepage = 'https://github.com/bgeron/diff-pdf-visually' -urls.Source = 'https://github.com/bgeron/diff-pdf-visually' +authors = [{name = "Bram Geron", email = "bram@bram.xyz"}] +maintainers = [{name = "Bram Geron", email = "bram@bram.xyz"}] +license = {text = "MIT/Apache-2.0"} +classifiers = [ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'License :: OSI Approved :: Apache Software License', + 'Natural Language :: English', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy', +] +dependencies = [] +requires-python = ">=3.6" dynamic = ["version"] +[project.optional-dependencies] +test = [ + "coverage", + "pytest", +] + +[project.urls] +Homepage = "https://github.com/bgeron/diff-pdf-visually" +Source = "https://github.com/bgeron/diff-pdf-visually" + +[project.scripts] +diff-pdf-visually = "diff_pdf_visually.__main__:main" + +[tool.setuptools.packages.find] +include = ["diff_pdf_visually*"] + [requires] python_version = ['3.6', '3.7', '3.8', '3.9', '3.10'] diff --git a/setup.py b/setup.py index 0376af7..d29f219 100644 --- a/setup.py +++ b/setup.py @@ -18,39 +18,8 @@ with open('README.rst', 'r', encoding='utf-8') as f: readme = f.read() -REQUIRES = [] - kwargs = { - 'name': 'diff-pdf-visually', 'version': version, - 'description': '', - 'long_description': readme, - 'author': 'Bram Geron', - 'author_email': 'bram@bram.xyz', - 'maintainer': 'Bram Geron', - 'maintainer_email': 'bram@bram.xyz', - 'url': 'https://github.com/bgeron/diff-pdf-visually', - 'license': 'MIT/Apache-2.0', - 'classifiers': [ - 'Development Status :: 4 - Beta', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'License :: OSI Approved :: Apache Software License', - 'Natural Language :: English', - 'Operating System :: OS Independent', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy', - ], - 'install_requires': REQUIRES, - 'tests_require': ['coverage', 'pytest'], - 'packages': find_packages(exclude=('tests', 'tests.*')), - 'entry_points': { - 'console_scripts': ['diff-pdf-visually=diff_pdf_visually.__main__:main'], - }, } #################### BEGIN USER OVERRIDES #################### diff --git a/tox.ini b/tox.ini index cc8c7de..9fde7f3 100644 --- a/tox.ini +++ b/tox.ini @@ -1,14 +1,30 @@ [tox] envlist = - py310 + py{39,310,311,312} [testenv] -passenv = * +extras = + test deps = coverage pytest commands = - python setup.py --quiet clean develop - coverage run --parallel-mode -m pytest + coverage run --parallel-mode -m pytest {posargs} coverage combine --append coverage report -m + +[testenv:check-packaging] +skip_install = true +deps = + build + twine +commands = + python -m build -o {envtmpdir}/dist + twine check {envtmpdir}/dist/* + +[gh-actions] +python = + 3.9: py39 + 3.10: py310, check-packaging + 3.11: py311 + 3.12: py312