Skip to content

Commit

Permalink
scripts/sysinstall.py: fix sysinstall test on github.
Browse files Browse the repository at this point in the history
On Github's ubuntu-latest, `python -m installer` seems to install into
opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages. No idea
how to predict where things are getting put, so we now set PYTHONPATH to all
`site-packages` and `dist-packages` directories within `root`.
  • Loading branch information
julian-smith-artifex-com committed Jan 5, 2024
1 parent 62cc377 commit 83aeb53
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions scripts/sysinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import platform
import subprocess
import sys
import sysconfig


# Requirements for a system build and install:
Expand Down Expand Up @@ -86,6 +87,7 @@ def main():
print(f'{platform.python_version()=}')
print(f'{__file__=}')
print(f'{sys.argv=}')
print(f'{sysconfig.get_path("platlib")=}')

# Set default behaviour.
#
Expand Down Expand Up @@ -215,8 +217,8 @@ def run(command):
pv = '.'.join(platform.python_version_tuple()[:2])
p = f'{root_prefix}/lib/python{pv}'
# `python -m installer` fails to overwrite existing files.
run(f'{sudo}rm -r {p}/site-packages/fitz')
run(f'{sudo}rm -r {p}/site-packages/PyMuPDF-*.dist-info')
run(f'{sudo}rm -r {p}/site-packages/fitz || true')
run(f'{sudo}rm -r {p}/site-packages/PyMuPDF-*.dist-info || true')
run(f'{sudo}{venv}/bin/python -m installer --destdir {root} --prefix {prefix} {wheel}')
# It seems that MuPDF Python bindings are installed into
# `.../dist-packages` (from mupdf:Mafile's call of `$(shell python3
Expand All @@ -226,20 +228,27 @@ def run(command):
# This might be because `sysconfig.get_path('platlib')` returns
# `.../site-packages` if run in a venv, otherwise `.../dist-packages`.
#
# So we set pythonpath (used later) to import from both these paths.
# And on github ubuntu-latest, sysconfig.get_path("platlib") is
# /opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages
#
pythonpath1 = glob.glob(f'{p}/site-packages')
pythonpath2 = glob.glob(f'{p}/dist-packages')
assert len(pythonpath1) == 1, f'{pythonpath1=}'
assert len(pythonpath2) == 1, f'{pythonpath2=}'
pythonpath = f'{pythonpath1[0]}:{pythonpath2[0]}'
# So we set pythonpath (used later) to import from all `site-packages/`
# and `dist-packages` directories within `root`:
#
pythonpath = list()
for dirpath, dirnames, filenames in os.walk(root):
for leaf in 'site-packages', 'dist-packages':
if leaf in dirnames:
pythonpath.append(os.path.join(dirpath, leaf))
pythonpath = ':'.join(pythonpath)
print(f'{pythonpath=}')
else:
command = f'{env} pip install -vv --root {root} {os.path.abspath(pymupdf_dir)}'
run( command)
sys.path.insert(0, pymupdf_dir)
import pipcl
del sys.path[0]
pythonpath = pipcl.install_dir(root)
run(f'find {root}')

# Run pytest tests.
#
Expand Down

0 comments on commit 83aeb53

Please sign in to comment.