Skip to content

Commit

Permalink
Merge pull request #16 from adrien-berchet/defaults
Browse files Browse the repository at this point in the history
Fix defaults, update build process and add CI
  • Loading branch information
bgeron authored Nov 29, 2024
2 parents 7df9bcc + 0af52ca commit 0f96b37
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 50 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/run-tox.yml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 19 additions & 9 deletions diff_pdf_visually/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

import os.path, pathlib, subprocess, sys, tempfile, time
from concurrent.futures import ThreadPoolExecutor
from . import constants
from .polyfill import nullcontext
from .constants import DEFAULT_THRESHOLD, DEFAULT_VERBOSITY, DEFAULT_DPI
from .constants import VERB_PRINT_REASON, VERB_PRINT_TMPDIR
from .constants import VERB_PERPAGE, VERB_PRINT_CMD, VERB_ROUGH_PROGRESS
from .constants import DEFAULT_NUM_THREADS, MAX_REPORT_PAGENOS

from . import external_programs
from .external_programs import verbose_run
Expand All @@ -28,7 +27,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",
Expand Down Expand Up @@ -102,13 +101,13 @@ def pdfdiff(*args, **kw):
def pdfdiff_pages(
a,
b,
threshold=DEFAULT_THRESHOLD,
verbosity=DEFAULT_VERBOSITY,
dpi=DEFAULT_DPI,
threshold=None,
verbosity=None,
dpi=None,
tempdir=None,
time_to_inspect=0,
num_threads=DEFAULT_NUM_THREADS,
max_report_pagenos=MAX_REPORT_PAGENOS,
num_threads=None,
max_report_pagenos=None,
):
"""
Find visual differences between two PDFs; return the page numbers with
Expand Down Expand Up @@ -136,6 +135,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 = constants.DEFAULT_THRESHOLD
if verbosity is None:
verbosity = constants.DEFAULT_VERBOSITY
if dpi is None:
dpi = constants.DEFAULT_DPI
if num_threads is None:
num_threads = constants.DEFAULT_NUM_THREADS
if max_report_pagenos is None:
max_report_pagenos = constants.MAX_REPORT_PAGENOS

if tempdir == None:
path_context = tempfile.TemporaryDirectory(prefix="diffpdf-")
else:
Expand Down Expand Up @@ -188,7 +198,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))
Expand Down
44 changes: 38 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = '[email protected]'}]
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 = "[email protected]"}]
maintainers = [{name = "Bram Geron", email = "[email protected]"}]
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']

Expand Down
31 changes: 0 additions & 31 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': '[email protected]',
'maintainer': 'Bram Geron',
'maintainer_email': '[email protected]',
'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 ####################
Expand Down
24 changes: 20 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0f96b37

Please sign in to comment.