| 11 | |
| 12 | |
| 13 | def run_in_venv(venv_pth:str, cmd, stdin:bytes=b'', aura_path=None): |
| 14 | env = os.environ.copy() |
| 15 | |
| 16 | if aura_path is None: |
| 17 | aura_path = shutil.which('aura') |
| 18 | |
| 19 | # Get the original $PATH value, works on POSIX compliant systems |
| 20 | pth = subprocess.getoutput('getconf PATH') |
| 21 | |
| 22 | env['VIRTUAL_ENV'] = venv_pth |
| 23 | env['PYTHONPATH'] = venv_pth |
| 24 | env['__PYVENV_LAUNCHER__'] = f'{venv_pth}/bin/python' # Needed for mac |
| 25 | env['PATH'] = f'{venv_pth}/bin:{pth}' |
| 26 | env['AURA_PATH'] = aura_path |
| 27 | env['PIP_DISABLE_PIP_VERSION_CHECK'] = '1' |
| 28 | env['PIP_REQUIRE_VIRTUALENV'] = '1' |
| 29 | env["PYTHONWARNINGS"] = "ignore" |
| 30 | |
| 31 | cwd = os.getcwd() |
| 32 | os.chdir(venv_pth) |
| 33 | |
| 34 | p = subprocess.Popen( |
| 35 | cmd, |
| 36 | env=env, |
| 37 | stdin=subprocess.PIPE, |
| 38 | stdout=subprocess.PIPE, |
| 39 | stderr=subprocess.STDOUT, |
| 40 | shell=True |
| 41 | ) |
| 42 | if stdin: |
| 43 | p.stdin.write(stdin) |
| 44 | p.stdin.close() |
| 45 | p.wait() |
| 46 | os.chdir(cwd) |
| 47 | return (p.stdout.read().decode(), p.returncode) |
| 48 | |
| 49 | |
| 50 | @pytest.mark.e2e |