Skip to content

Commit 0f96b37

Browse files
authored
Merge pull request #16 from adrien-berchet/defaults
Fix defaults, update build process and add CI
2 parents 7df9bcc + 0af52ca commit 0f96b37

File tree

5 files changed

+125
-50
lines changed

5 files changed

+125
-50
lines changed

.github/workflows/run-tox.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Run all tox jobs using Python3
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
workflow_dispatch:
9+
10+
jobs:
11+
tests:
12+
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
python-version: ["3.9", "3.10", "3.11", "3.12"]
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
- name: Cache APT Packages
25+
uses: awalsh128/cache-apt-pkgs-action@latest
26+
with:
27+
packages: imagemagick
28+
version: 1.0
29+
execute_install_scripts: true
30+
- name: Run tox
31+
run: |
32+
python -m pip install --upgrade pip setuptools
33+
pip install tox-gh-actions
34+
tox
35+
- name: JUnit Report Action
36+
uses: mikepenz/action-junit-report@v4
37+
if: always() # always run even if the previous step fails
38+
with:
39+
report_paths: 'reports/pytest-*.xml'
40+
- name: Upload test artifacts
41+
uses: actions/upload-artifact@v4
42+
if: always()
43+
with:
44+
name: tests-${{ matrix.python-version }}
45+
retention-days: 4
46+
path: |
47+
.tox/py*/tmp
48+
reports

diff_pdf_visually/diff.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99

1010
import os.path, pathlib, subprocess, sys, tempfile, time
1111
from concurrent.futures import ThreadPoolExecutor
12+
from . import constants
1213
from .polyfill import nullcontext
13-
from .constants import DEFAULT_THRESHOLD, DEFAULT_VERBOSITY, DEFAULT_DPI
1414
from .constants import VERB_PRINT_REASON, VERB_PRINT_TMPDIR
1515
from .constants import VERB_PERPAGE, VERB_PRINT_CMD, VERB_ROUGH_PROGRESS
16-
from .constants import DEFAULT_NUM_THREADS, MAX_REPORT_PAGENOS
1716

1817
from . import external_programs
1918
from .external_programs import verbose_run
@@ -28,7 +27,7 @@ def pdftopng(sourcepath, destdir, basename, verbosity, dpi):
2827
raise ValueError("destdir not clean: " + repr(destdir))
2928

3029
verbose_run(
31-
(verbosity > VERB_PRINT_CMD),
30+
(verbosity >= VERB_PRINT_CMD),
3231
[
3332
"pdftocairo",
3433
"-png",
@@ -102,13 +101,13 @@ def pdfdiff(*args, **kw):
102101
def pdfdiff_pages(
103102
a,
104103
b,
105-
threshold=DEFAULT_THRESHOLD,
106-
verbosity=DEFAULT_VERBOSITY,
107-
dpi=DEFAULT_DPI,
104+
threshold=None,
105+
verbosity=None,
106+
dpi=None,
108107
tempdir=None,
109108
time_to_inspect=0,
110-
num_threads=DEFAULT_NUM_THREADS,
111-
max_report_pagenos=MAX_REPORT_PAGENOS,
109+
num_threads=None,
110+
max_report_pagenos=None,
112111
):
113112
"""
114113
Find visual differences between two PDFs; return the page numbers with
@@ -136,6 +135,17 @@ def pdfdiff_pages(
136135
assert os.path.isfile(a), "file {} must exist".format(a)
137136
assert os.path.isfile(b), "file {} must exist".format(b)
138137

138+
if threshold is None:
139+
threshold = constants.DEFAULT_THRESHOLD
140+
if verbosity is None:
141+
verbosity = constants.DEFAULT_VERBOSITY
142+
if dpi is None:
143+
dpi = constants.DEFAULT_DPI
144+
if num_threads is None:
145+
num_threads = constants.DEFAULT_NUM_THREADS
146+
if max_report_pagenos is None:
147+
max_report_pagenos = constants.MAX_REPORT_PAGENOS
148+
139149
if tempdir == None:
140150
path_context = tempfile.TemporaryDirectory(prefix="diffpdf-")
141151
else:
@@ -188,7 +198,7 @@ def pdfdiff_pages(
188198
diffpath = p / "diff-{}.png".format(pageno)
189199
logpath = p / "log-{}.txt".format(pageno)
190200
s = imgdiff(
191-
pageapath, pagebpath, diffpath, logpath, (verbosity > VERB_PRINT_CMD)
201+
pageapath, pagebpath, diffpath, logpath, (verbosity >= VERB_PRINT_CMD)
192202
)
193203
if verbosity >= VERB_PERPAGE:
194204
print("- Page {}: significance={}".format(pageno, s))

pyproject.toml

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,45 @@
11
[project]
2-
name = 'diff-pdf-visually'
3-
description = 'Quickly check whether there is a visible difference between two PDFs, using ImageMagick and pdftocairo.'
4-
authors = [{name = 'Bram Geron', email = '[email protected]'}]
5-
license = {text = 'MIT/Apache-2.0'}
2+
name = "diff-pdf-visually"
3+
description = "Quickly check whether there is a visible difference between two PDFs, using ImageMagick and pdftocairo."
64
readme = "README.rst"
7-
urls.Homepage = 'https://github.com/bgeron/diff-pdf-visually'
8-
urls.Source = 'https://github.com/bgeron/diff-pdf-visually'
5+
authors = [{name = "Bram Geron", email = "[email protected]"}]
6+
maintainers = [{name = "Bram Geron", email = "[email protected]"}]
7+
license = {text = "MIT/Apache-2.0"}
8+
classifiers = [
9+
'Development Status :: 4 - Beta',
10+
'Intended Audience :: Developers',
11+
'License :: OSI Approved :: MIT License',
12+
'License :: OSI Approved :: Apache Software License',
13+
'Natural Language :: English',
14+
'Operating System :: OS Independent',
15+
'Programming Language :: Python :: 3.6',
16+
'Programming Language :: Python :: 3.7',
17+
'Programming Language :: Python :: 3.8',
18+
'Programming Language :: Python :: 3.9',
19+
'Programming Language :: Python :: 3.10',
20+
'Programming Language :: Python :: Implementation :: CPython',
21+
'Programming Language :: Python :: Implementation :: PyPy',
22+
]
23+
dependencies = []
24+
requires-python = ">=3.6"
925
dynamic = ["version"]
1026

27+
[project.optional-dependencies]
28+
test = [
29+
"coverage",
30+
"pytest",
31+
]
32+
33+
[project.urls]
34+
Homepage = "https://github.com/bgeron/diff-pdf-visually"
35+
Source = "https://github.com/bgeron/diff-pdf-visually"
36+
37+
[project.scripts]
38+
diff-pdf-visually = "diff_pdf_visually.__main__:main"
39+
40+
[tool.setuptools.packages.find]
41+
include = ["diff_pdf_visually*"]
42+
1143
[requires]
1244
python_version = ['3.6', '3.7', '3.8', '3.9', '3.10']
1345

setup.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,8 @@
1818
with open('README.rst', 'r', encoding='utf-8') as f:
1919
readme = f.read()
2020

21-
REQUIRES = []
22-
2321
kwargs = {
24-
'name': 'diff-pdf-visually',
2522
'version': version,
26-
'description': '',
27-
'long_description': readme,
28-
'author': 'Bram Geron',
29-
'author_email': '[email protected]',
30-
'maintainer': 'Bram Geron',
31-
'maintainer_email': '[email protected]',
32-
'url': 'https://github.com/bgeron/diff-pdf-visually',
33-
'license': 'MIT/Apache-2.0',
34-
'classifiers': [
35-
'Development Status :: 4 - Beta',
36-
'Intended Audience :: Developers',
37-
'License :: OSI Approved :: MIT License',
38-
'License :: OSI Approved :: Apache Software License',
39-
'Natural Language :: English',
40-
'Operating System :: OS Independent',
41-
'Programming Language :: Python :: 3.6',
42-
'Programming Language :: Python :: 3.7',
43-
'Programming Language :: Python :: 3.8',
44-
'Programming Language :: Python :: 3.9',
45-
'Programming Language :: Python :: Implementation :: CPython',
46-
'Programming Language :: Python :: Implementation :: PyPy',
47-
],
48-
'install_requires': REQUIRES,
49-
'tests_require': ['coverage', 'pytest'],
50-
'packages': find_packages(exclude=('tests', 'tests.*')),
51-
'entry_points': {
52-
'console_scripts': ['diff-pdf-visually=diff_pdf_visually.__main__:main'],
53-
},
5423
}
5524

5625
#################### BEGIN USER OVERRIDES ####################

tox.ini

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
[tox]
22
envlist =
3-
py310
3+
py{39,310,311,312}
44

55
[testenv]
6-
passenv = *
6+
extras =
7+
test
78
deps =
89
coverage
910
pytest
1011
commands =
11-
python setup.py --quiet clean develop
12-
coverage run --parallel-mode -m pytest
12+
coverage run --parallel-mode -m pytest {posargs}
1313
coverage combine --append
1414
coverage report -m
15+
16+
[testenv:check-packaging]
17+
skip_install = true
18+
deps =
19+
build
20+
twine
21+
commands =
22+
python -m build -o {envtmpdir}/dist
23+
twine check {envtmpdir}/dist/*
24+
25+
[gh-actions]
26+
python =
27+
3.9: py39
28+
3.10: py310, check-packaging
29+
3.11: py311
30+
3.12: py312

0 commit comments

Comments
 (0)