If python3-gi is installed, we check fix for #3493, where importing gi would load an older version of libjpeg than is used in MuPDF, and break MuPDF. This test is excluded by default in sysinstall tests, because running commands in a new venv does not seem to pick up pymupd
()
| 269 | |
| 270 | |
| 271 | def test_3493(): |
| 272 | ''' |
| 273 | If python3-gi is installed, we check fix for #3493, where importing gi |
| 274 | would load an older version of libjpeg than is used in MuPDF, and break |
| 275 | MuPDF. |
| 276 | |
| 277 | This test is excluded by default in sysinstall tests, because running |
| 278 | commands in a new venv does not seem to pick up pymupdf as expected. |
| 279 | ''' |
| 280 | if platform.system() != 'Linux': |
| 281 | print(f'Not running because not Linux: {platform.system()=}') |
| 282 | return |
| 283 | |
| 284 | import subprocess |
| 285 | |
| 286 | root = os.path.abspath(f'{__file__}/../..') |
| 287 | in_path = f'{root}/tests/resources/test_3493.epub' |
| 288 | |
| 289 | def run(command, check=1, stdout=None): |
| 290 | print(f'Running with {check=}: {command}') |
| 291 | return subprocess.run(command, shell=1, check=check, stdout=stdout, text=1) |
| 292 | |
| 293 | def run_code(code, code_path, *, check=True, venv=None, venv_args='', pythonpath=None, stdout=None): |
| 294 | code = textwrap.dedent(code) |
| 295 | with open(code_path, 'w') as f: |
| 296 | f.write(code) |
| 297 | prefix = f'PYTHONPATH={pythonpath} ' if pythonpath else '' |
| 298 | if venv: |
| 299 | # Have seen this fail on Github in a curious way: |
| 300 | # |
| 301 | # Running: /tmp/tmp.fBeKNLJQKk/venv/bin/python -m venv --system-site-packages /project/tests/resources/test_3493_venv |
| 302 | # Error: [Errno 2] No such file or directory: '/project/tests/resources/test_3493_venv/bin/python' |
| 303 | # |
| 304 | r = run(f'{sys.executable} -m venv {venv_args} {venv}', check=check) |
| 305 | if r.returncode: |
| 306 | return r |
| 307 | r = run(f'. {venv}/bin/activate && {prefix}python {code_path}', check=check, stdout=stdout) |
| 308 | else: |
| 309 | r = run(f'{prefix}{sys.executable} {code_path}', check=check, stdout=stdout) |
| 310 | return r |
| 311 | |
| 312 | # Find location of system install of `gi`. |
| 313 | r = run_code( |
| 314 | ''' |
| 315 | from gi.repository import GdkPixbuf |
| 316 | import gi |
| 317 | print(gi.__file__) |
| 318 | ''' |
| 319 | , |
| 320 | f'{root}/tests/resources/test_3493_gi.py', |
| 321 | check=0, |
| 322 | venv=f'{root}/tests/resources/test_3493_venv', |
| 323 | venv_args='--system-site-packages', |
| 324 | stdout=subprocess.PIPE, |
| 325 | ) |
| 326 | if r.returncode: |
| 327 | print(f'test_3493(): Not running test because --system-site-packages venv cannot import gi.') |
| 328 | return |