From 20f35acb4f8540d177be13c30ac9e126cfdd9320 Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Sat, 24 Feb 2024 23:24:28 +0000 Subject: [PATCH] setup.py tests/: install a `pumupdf` command that runs fitz/__main__.py. This uses pipcl.py's new `entry_points` support. Note that direct installation with `setup.py install` does not implement this. tests/test_general.py: test_cli() - basic test of command-line `pymupdf` command. Addresses #3199. --- setup.py | 7 +++++++ tests/test_general.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/setup.py b/setup.py index fe56d0e93..9048a2cec 100755 --- a/setup.py +++ b/setup.py @@ -1114,6 +1114,13 @@ def sdist(): ('Tracker, https://github.com/pymupdf/PyMuPDF/issues'), ('Changelog, https://pymupdf.readthedocs.io/en/latest/changes.html'), ], + + # Create a `fitz` command. + entry_points = textwrap.dedent(''' + [console_scripts] + pymupdf = fitz.__main__:main + '''), + fn_build=build, fn_sdist=sdist, diff --git a/tests/test_general.py b/tests/test_general.py index f3886379a..9b1f5475c 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -916,3 +916,10 @@ def next_fd(): fd2 = next_fd() assert fd2 == fd1, f'{fd1=} {fd2=}' os.remove(oldfile) + +def test_cli(): + if not hasattr(fitz, 'mupdf'): + print('test_cli(): Not running on classic because of fitz_old.') + return + import subprocess + subprocess.run(f'pymupdf -h', shell=1, check=1)