Skip to content

Jules - fixes for sysinstall tests on Github. #4607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
- uses: actions/setup-python@v5
- name: valgrind
run:
python scripts/test.py ${{matrix.args}} -P 1 --valgrind 1 build test
python scripts/test.py ${{matrix.args}} -P 1 -T valgrind build test
24 changes: 20 additions & 4 deletions scripts/sysinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,20 @@ def run(command, env_extra=None):
if pip == 'sudo':
log('## Installing Python packages required for building MuPDF and PyMuPDF.')
#run(f'sudo pip install --upgrade pip') # Breaks on Github see: https://github.com/pypa/get-pip/issues/226.
# We need to install psutil and pillow as system packages, otherwise things like `import psutil`
# fail, seemingly because of pip warning:
#
# WARNING: Running pip as the 'root' user can result in broken
# permissions and conflicting behaviour with the system package
# manager. It is recommended to use a virtual environment instead:
# https://pip.pypa.io/warnings/venv
#
names = test_py.wrap_get_requires_for_build_wheel(f'{__file__}/../..')
names = names.split(' ')
names = [n for n in names if n not in ('psutil', 'pillow')]
names = ' '.join(names)
run(f'sudo pip install {names}')
run(f'sudo apt install python3-psutil python3-pillow')

log('## Build and install MuPDF.')
command = f'cd {mupdf_dir}'
Expand Down Expand Up @@ -345,7 +357,7 @@ def run(command):
#
log('## Run PyMuPDF pytest tests.')
def run(command, env_extra=None):
return run_command(command, doit=pytest_do, env_extra=env_extra)
return run_command(command, doit=pytest_do, env_extra=env_extra, caller=1)
import gh_release
if pip == 'venv':
# Create venv.
Expand All @@ -356,7 +368,11 @@ def run(command, env_extra=None):
command += f' && pip install --upgrade {gh_release.test_packages}'
run(command)
elif pip == 'sudo':
run(f'sudo pip install --upgrade {gh_release.test_packages}')
names = gh_release.test_packages
names = names.split(' ')
names = [n for n in names if n not in ('psutil', 'pillow')]
names = ' '.join(names)
run(f'sudo pip install --upgrade {names}')
else:
log(f'Not installing packages for testing because {pip=}.')
# Run pytest.
Expand Down Expand Up @@ -403,9 +419,9 @@ def run(command, env_extra=None):
run(command, env_extra=dict(PYMUPDF_SYSINSTALL_TEST='1'))


def run_command(command, capture=False, check=True, doit=True, env_extra=None):
def run_command(command, capture=False, check=True, doit=True, env_extra=None, caller=0):
if doit:
return pipcl.run(command, capture=capture, check=check, caller=2, env_extra=env_extra)
return pipcl.run(command, capture=capture, check=check, caller=caller+2, env_extra=env_extra)
else:
log(f'## Would have run: {command}', caller=2)

Expand Down
51 changes: 29 additions & 22 deletions scripts/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,23 @@

-m <location> | --mupdf <location>
Location of local mupdf/ directory or 'git:...' to be used
when building PyMuPDF. [This sets environment variable
PYMUPDF_SETUP_MUPDF_BUILD, which is used by PyMuPDF/setup.py. If not
specified PyMuPDF will download its default mupdf .tgz.]
when building PyMuPDF.

This sets environment variable PYMUPDF_SETUP_MUPDF_BUILD, which is used
by PyMuPDF/setup.py. If not specified PyMuPDF will download its default
mupdf .tgz.

Additionally if <location> starts with ':' we use the remaining text as
the branch name and add https://github.com/ArtifexSoftware/mupdf.git.

For example:

-m "git:--branch master https://github.com/ArtifexSoftware/mupdf.git"
-m :master

-m "git:--branch 1.26.x https://github.com/ArtifexSoftware/mupdf.git"
-m :1.26.x


-M 0|1
--build-mupdf 0|1
Expand Down Expand Up @@ -181,8 +195,11 @@
--timeout <seconds>
Sets timeout when running tests.

-T <command> | --pytest-prefix <command>
Use specified prefix when running pytest. E.g. `gdb --args`.
-T <prefix>
Use specified prefix when running pytest, must be one of:
gdb
helgrind
vagrind

-v 0|1|2
0 - do not use a venv.
Expand All @@ -192,10 +209,6 @@
2 - Use venv
The default is 2.

--valgrind 0|1
Use valgrind in `test` or `buildtest`.
This will run `sudo apt update` and `sudo apt install valgrind`.

Commands:

build
Expand Down Expand Up @@ -376,12 +389,6 @@ def main(argv):
elif arg == '-f':
test_fitz = int(next(args))

elif arg == '--gdb':
_gdb = int(next(args))
if _gdb == 1:
pytest_prefix = 'gdb'
warnings += f'{arg=} is deprecated, use `-T gdb`.'

elif arg in ('-h', '--help'):
show_help = True

Expand All @@ -395,6 +402,10 @@ def main(argv):
_mupdf = next(args)
if _mupdf == '-':
_mupdf = None
elif _mupdf.startswith(':'):
_branch = _mupdf[1:]
_mupdf = 'git:--branch {_branch} https://github.com/ArtifexSoftware/mupdf.git'
os.environ['PYMUPDF_SETUP_MUPDF_BUILD'] = _mupdf
elif _mupdf.startswith('git:') or '://' in _mupdf:
os.environ['PYMUPDF_SETUP_MUPDF_BUILD'] = _mupdf
else:
Expand Down Expand Up @@ -439,19 +450,15 @@ def main(argv):
elif arg == '--timeout':
test_timeout = float(next(args))

elif arg in ('-T', '--pytest-prefix'):
elif arg == '-T':
pytest_prefix = next(args)
assert pytest_prefix in ('gdb', 'helgrind', 'valgrind'), \
f'Unrecognised {pytest_prefix=}, should be one of: gdb valgrind helgrind.'

elif arg == '-v':
venv = int(next(args))
assert venv in (0, 1, 2), f'Invalid {venv=} should be 0, 1 or 2.'

elif arg == '--valgrind':
_valgrind = int(next(args))
if _valgrind == 1:
pytest_prefix = 'valgrind'
warnings += f'{arg=} is deprecated, use `-T _valgrind`.'

elif arg in ('build', 'cibw', 'pyodide', 'test', 'wheel'):
commands.append(arg)

Expand Down
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,12 +807,11 @@ def build_mupdf_windows(
devenv = os.environ.get('PYMUPDF_SETUP_DEVENV')
if not devenv:
try:
# Prefer VS-2019 as that is what MuPDF's project/solution files are
# written for.
log(f'Looking for Visual Studio 2019.')
vs = pipcl.wdev.WindowsVS(year=2019)
# Prefer VS-2022 as that is what Github provide in windows-2022.
log(f'Looking for Visual Studio 2022.')
vs = pipcl.wdev.WindowsVS(year=2022)
except Exception as e:
log(f'Failed to find VS-2019:\n'
log(f'Failed to find VS-2022:\n'
f'{textwrap.indent(traceback.format_exc(), " ")}'
)
log(f'Looking for any Visual Studio.')
Expand Down