Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions scripts/release/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,34 @@
Path,
)
import subprocess
import sys
from tempfile import (
TemporaryDirectory,
)
import venv


def get_pip_exe(venv_path: Path) -> Path:
"""Get the path to pip executable for the given virtual environment."""
if sys.platform == "win32":
return venv_path / "Scripts" / "pip.exe"
else:
return venv_path / "bin" / "pip"


def create_venv(parent_path: Path) -> Path:
venv_path = parent_path / "package-smoke-test"
venv.create(venv_path, with_pip=True)
subprocess.run(
[venv_path / "bin" / "pip", "install", "-U", "pip", "setuptools"], check=True
)
pip_exe = get_pip_exe(venv_path)
subprocess.run([pip_exe, "install", "-U", "pip", "setuptools"], check=True)
return venv_path


def find_wheel(project_path: Path) -> Path:
wheels = list(project_path.glob("dist/*.whl"))

if len(wheels) != 1:
raise Exception(
raise ValueError(
f"Expected one wheel. Instead found: {wheels} "
f"in project {project_path.absolute()}"
)
Expand All @@ -30,10 +38,8 @@ def find_wheel(project_path: Path) -> Path:


def install_wheel(venv_path: Path, wheel_path: Path) -> None:
subprocess.run(
[venv_path / "bin" / "pip", "install", f"{wheel_path}"],
check=True,
)
pip_exe = get_pip_exe(venv_path)
subprocess.run([pip_exe, "install", f"{wheel_path}"], check=True)


def test_install_local_wheel() -> None:
Expand All @@ -42,7 +48,10 @@ def test_install_local_wheel() -> None:
wheel_path = find_wheel(Path("."))
install_wheel(venv_path, wheel_path)
print("Installed", wheel_path.absolute(), "to", venv_path)
print(f"Activate with `source {venv_path}/bin/activate`")
if sys.platform == "win32":
print(f"Activate with `{venv_path}\\Scripts\\activate`")
else:
print(f"Activate with `source {venv_path}/bin/activate`")
input("Press enter when the test has completed. The directory will be deleted.")


Expand Down