Skip to content

Commit 0f217b6

Browse files
julian-smith-artifex-comJorjMcKie
authored andcommitted
scripts/sysinstall.py: fix recent failure on Github.
We need to use system packages for psutil and pillow, instead of `sudo pip install`.
1 parent 62fd12c commit 0f217b6

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

scripts/sysinstall.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,20 @@ def run(command, env_extra=None):
235235
if pip == 'sudo':
236236
log('## Installing Python packages required for building MuPDF and PyMuPDF.')
237237
#run(f'sudo pip install --upgrade pip') # Breaks on Github see: https://github.com/pypa/get-pip/issues/226.
238+
# We need to install psutil and pillow as system packages, otherwise things like `import psutil`
239+
# fail, seemingly because of pip warning:
240+
#
241+
# WARNING: Running pip as the 'root' user can result in broken
242+
# permissions and conflicting behaviour with the system package
243+
# manager. It is recommended to use a virtual environment instead:
244+
# https://pip.pypa.io/warnings/venv
245+
#
238246
names = test_py.wrap_get_requires_for_build_wheel(f'{__file__}/../..')
247+
names = names.split(' ')
248+
names = [n for n in names if n not in ('psutil', 'pillow')]
249+
names = ' '.join(names)
239250
run(f'sudo pip install {names}')
251+
run(f'sudo apt install python3-psutil python3-pillow')
240252

241253
log('## Build and install MuPDF.')
242254
command = f'cd {mupdf_dir}'
@@ -345,7 +357,7 @@ def run(command):
345357
#
346358
log('## Run PyMuPDF pytest tests.')
347359
def run(command, env_extra=None):
348-
return run_command(command, doit=pytest_do, env_extra=env_extra)
360+
return run_command(command, doit=pytest_do, env_extra=env_extra, caller=1)
349361
import gh_release
350362
if pip == 'venv':
351363
# Create venv.
@@ -356,7 +368,11 @@ def run(command, env_extra=None):
356368
command += f' && pip install --upgrade {gh_release.test_packages}'
357369
run(command)
358370
elif pip == 'sudo':
359-
run(f'sudo pip install --upgrade {gh_release.test_packages}')
371+
names = gh_release.test_packages
372+
names = names.split(' ')
373+
names = [n for n in names if n not in ('psutil', 'pillow')]
374+
names = ' '.join(names)
375+
run(f'sudo pip install --upgrade {names}')
360376
else:
361377
log(f'Not installing packages for testing because {pip=}.')
362378
# Run pytest.
@@ -403,9 +419,9 @@ def run(command, env_extra=None):
403419
run(command, env_extra=dict(PYMUPDF_SYSINSTALL_TEST='1'))
404420

405421

406-
def run_command(command, capture=False, check=True, doit=True, env_extra=None):
422+
def run_command(command, capture=False, check=True, doit=True, env_extra=None, caller=0):
407423
if doit:
408-
return pipcl.run(command, capture=capture, check=check, caller=2, env_extra=env_extra)
424+
return pipcl.run(command, capture=capture, check=check, caller=caller+2, env_extra=env_extra)
409425
else:
410426
log(f'## Would have run: {command}', caller=2)
411427

0 commit comments

Comments
 (0)