| 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( |