|
| 1 | +from pathlib import Path |
| 2 | +import subprocess |
| 3 | +from tempfile import TemporaryDirectory |
| 4 | +import venv |
| 5 | + |
| 6 | + |
| 7 | +def create_venv(parent_path): |
| 8 | + venv_path = parent_path / 'package-smoke-test' |
| 9 | + venv.create(venv_path, with_pip=True) |
| 10 | + subprocess.run([venv_path / 'bin' / 'pip', 'install', '-U', 'pip', 'setuptools'], check=True) |
| 11 | + return venv_path |
| 12 | + |
| 13 | + |
| 14 | +def find_wheel(project_path): |
| 15 | + wheels = list(project_path.glob('dist/*.whl')) |
| 16 | + |
| 17 | + if len(wheels) != 1: |
| 18 | + raise Exception( |
| 19 | + f"Expected one wheel. Instead found: {wheels} in project {project_path.absolute()}" |
| 20 | + ) |
| 21 | + |
| 22 | + return wheels[0] |
| 23 | + |
| 24 | + |
| 25 | +def install_wheel(venv_path, wheel_path, extras=tuple()): |
| 26 | + if extras: |
| 27 | + extra_suffix = f"[{','.join(extras)}]" |
| 28 | + else: |
| 29 | + extra_suffix = "" |
| 30 | + |
| 31 | + subprocess.run( |
| 32 | + [ |
| 33 | + venv_path / 'bin' / 'pip', |
| 34 | + 'install', |
| 35 | + f"{wheel_path}{extra_suffix}" |
| 36 | + ], |
| 37 | + check=True, |
| 38 | + ) |
| 39 | + |
| 40 | + |
| 41 | +def test_install_local_wheel(): |
| 42 | + temporary_dir = TemporaryDirectory() |
| 43 | + venv_path = create_venv(Path(temporary_dir.name)) |
| 44 | + wheel_path = find_wheel(Path('.')) |
| 45 | + install_wheel(venv_path, wheel_path, extras=['p2p', 'trinity']) |
| 46 | + print("Installed", wheel_path.absolute(), "to", venv_path) |
| 47 | + print(f"Activate with `source {venv_path}/bin/activate`") |
| 48 | + input("Press enter when the test has completed. The directory will be deleted.") |
| 49 | + temporary_dir.cleanup() |
| 50 | + |
| 51 | + |
| 52 | +if __name__ == '__main__': |
| 53 | + test_install_local_wheel() |
0 commit comments