99import pytest
1010import virtualenv as _virtualenv # type: ignore[import-untyped]
1111
12+ # Root test directory and path to the test package
1213DIR = Path (__file__ ).parent .resolve ()
1314BASE = DIR / "packages" / "find_package"
15+ ROOT = DIR .parent
1416
1517
1618class VEnv :
19+ """Manages an isolated virtual environment for testing"""
20+
1721 def __init__ (self , env_dir : Path , * , wheelhouse : Path | None = None ) -> None :
22+ # Create a virtual environment without setuptools and wheel
1823 cmd = [str (env_dir ), "--no-setuptools" , "--no-wheel" , "--activators" , "" ]
1924 result = _virtualenv .cli_run (cmd , setup_logging = False )
2025 self .wheelhouse = wheelhouse
2126 self .executable = Path (result .creator .exe )
2227 self .env_dir = env_dir .resolve ()
28+
29+ # Retrieve install locations (used for debugging or inspection)
2330 self .platlib = Path (
2431 self .execute ("import sysconfig; print(sysconfig.get_path('platlib'))" )
2532 )
@@ -35,11 +42,15 @@ def run(self, *args: str, capture: Literal[False] = ...) -> None: ...
3542
3643 def run (self , * args : str , capture : bool = False ) -> str | None :
3744 __tracebackhide__ = True
45+
46+ # Prepare environment variables for subprocess
3847 env = os .environ .copy ()
3948 paths = {str (self .executable .parent )}
4049 env ["PATH" ] = os .pathsep .join ([* paths , env ["PATH" ]])
4150 env ["VIRTUAL_ENV" ] = str (self .env_dir )
4251 env ["PIP_DISABLE_PIP_VERSION_CHECK" ] = "ON"
52+
53+ # Use local wheelhouse if provided
4354 if self .wheelhouse is not None :
4455 env ["PIP_NO_INDEX" ] = "ON"
4556 env ["PIP_FIND_LINKS" ] = str (self .wheelhouse )
@@ -50,6 +61,7 @@ def run(self, *args: str, capture: bool = False) -> str | None:
5061 if str_args [0 ] in {"python" , "python3" }:
5162 str_args [0 ] = str (self .executable )
5263
64+ # Run and optionally capture output
5365 if capture :
5466 result = subprocess .run (
5567 str_args ,
@@ -88,17 +100,20 @@ def install(self, *args: str, isolated: bool = True) -> None:
88100
89101@pytest .fixture ()
90102def virtualenv (tmp_path : Path ) -> VEnv :
103+ """Provides a fresh virtualenv for each test run"""
91104 path = tmp_path / "venv"
92105 return VEnv (path )
93106
94107
95- ROOT = DIR .parent
96-
97-
98108def test_find_package (virtualenv : VEnv , tmp_path : Path ):
109+ """Ensure that the VTK SDK can be found using find_package inside CMake"""
110+
111+ # Step 1: Build the test wheel using scikit-build-core and VTK SDK
99112 virtualenv .run (
100113 "python" , "-m" , "pip" , "wheel" , str (ROOT ), "--wheel-dir" , str (tmp_path )
101114 )
115+
116+ # Step 2: Install the wheel built from the test project (using find_package(VTK))
102117 virtualenv .run (
103118 "python" , "-m" , "pip" , "install" , "--find-links" , str (tmp_path ), str (BASE )
104119 )
0 commit comments