|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Smoke-test the built pyontoenv shim against the ontoenv wheel. |
| 4 | +
|
| 5 | +Expected wheel locations (relative to repo root): |
| 6 | + - python/target/wheels/ontoenv-*.whl |
| 7 | + - pyontoenv-shim/dist/pyontoenv-*.whl |
| 8 | +""" |
| 9 | + |
| 10 | +from __future__ import annotations |
| 11 | + |
| 12 | +import argparse |
| 13 | +import subprocess |
| 14 | +import sys |
| 15 | +import tempfile |
| 16 | +from pathlib import Path |
| 17 | + |
| 18 | +ROOT = Path(__file__).resolve().parents[2] |
| 19 | + |
| 20 | + |
| 21 | +def pick_wheel(path: Path, pattern: str) -> Path: |
| 22 | + matches = sorted(path.glob(pattern)) |
| 23 | + if not matches: |
| 24 | + raise SystemExit(f"no wheels match '{pattern}' under {path}") |
| 25 | + return matches[-1] |
| 26 | + |
| 27 | + |
| 28 | +def run(cmd: list[str], **kwargs) -> None: |
| 29 | + print("+", " ".join(cmd), flush=True) |
| 30 | + subprocess.run(cmd, check=True, **kwargs) |
| 31 | + |
| 32 | + |
| 33 | +def main() -> None: |
| 34 | + parser = argparse.ArgumentParser() |
| 35 | + parser.add_argument("--ontoenv-wheel", type=Path, default=None) |
| 36 | + parser.add_argument("--shim-wheel", type=Path, default=None) |
| 37 | + args = parser.parse_args() |
| 38 | + |
| 39 | + ontoenv_wheel = ( |
| 40 | + args.ontoenv_wheel |
| 41 | + if args.ontoenv_wheel |
| 42 | + else pick_wheel(ROOT / "python" / "target" / "wheels", "ontoenv-*.whl") |
| 43 | + ) |
| 44 | + shim_wheel = ( |
| 45 | + args.shim_wheel |
| 46 | + if args.shim_wheel |
| 47 | + else pick_wheel(ROOT / "pyontoenv-shim" / "dist", "pyontoenv-*.whl") |
| 48 | + ) |
| 49 | + |
| 50 | + with tempfile.TemporaryDirectory(prefix="pyontoenv-test-") as tmp: |
| 51 | + venv_dir = Path(tmp) / "venv" |
| 52 | + run([sys.executable, "-m", "venv", str(venv_dir)]) |
| 53 | + |
| 54 | + if sys.platform == "win32": |
| 55 | + python = venv_dir / "Scripts" / "python.exe" |
| 56 | + pip = venv_dir / "Scripts" / "pip.exe" |
| 57 | + else: |
| 58 | + python = venv_dir / "bin" / "python" |
| 59 | + pip = venv_dir / "bin" / "pip" |
| 60 | + |
| 61 | + run([str(pip), "install", "--no-deps", str(ontoenv_wheel), str(shim_wheel)]) |
| 62 | + run( |
| 63 | + [ |
| 64 | + str(python), |
| 65 | + "-c", |
| 66 | + "import pyontoenv, ontoenv; " |
| 67 | + "from pyontoenv import OntoEnv; " |
| 68 | + "assert pyontoenv is ontoenv; " |
| 69 | + "assert callable(OntoEnv); " |
| 70 | + "print('pyontoenv version', pyontoenv.__version__)", |
| 71 | + ] |
| 72 | + ) |
| 73 | + run([str(python), "-m", "ontoenv._cli", "--help"], stdout=subprocess.DEVNULL) |
| 74 | + |
| 75 | + |
| 76 | +if __name__ == "__main__": |
| 77 | + main() |
0 commit comments