Skip to content

Commit 7a2e683

Browse files
committed
Fix checkpoint subprocess imports in CI
1 parent 376acc7 commit 7a2e683

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

cuda_core/tests/test_checkpoint.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
import signal
1818
import subprocess
1919
import sys
20+
import tempfile
2021
import textwrap
2122
from contextlib import suppress
23+
from pathlib import Path
2224

2325
import pytest
2426

@@ -46,6 +48,7 @@ def _checkpoint_available():
4648

4749

4850
_SCENARIO_SKIP_EXIT_CODE = 77
51+
_CUDA_CORE_SOURCE_ROOT = Path(__file__).resolve().parents[1]
4952

5053
_SCENARIO_COMMON = r"""
5154
import os
@@ -181,6 +184,8 @@ def _run_checkpoint_scenario_or_skip(body: str, *, timeout: int = 90) -> None:
181184
script = _SCENARIO_COMMON + "\n" + textwrap.dedent(body)
182185
proc = subprocess.Popen( # noqa: S603 - controlled test subprocess using this Python executable.
183186
[sys.executable, "-c", script],
187+
cwd=tempfile.gettempdir(),
188+
env=_checkpoint_scenario_env(),
184189
stdout=subprocess.PIPE,
185190
stderr=subprocess.PIPE,
186191
text=True,
@@ -206,6 +211,28 @@ def _run_checkpoint_scenario_or_skip(body: str, *, timeout: int = 90) -> None:
206211
)
207212

208213

214+
def _checkpoint_scenario_env() -> dict[str, str]:
215+
"""Avoid source-tree shadowing when wheel jobs spawn a child Python."""
216+
env = os.environ.copy()
217+
pythonpath = env.get("PYTHONPATH")
218+
if pythonpath is None:
219+
return env
220+
221+
filtered = []
222+
for entry in pythonpath.split(os.pathsep):
223+
if not entry:
224+
continue
225+
if Path(entry).resolve() == _CUDA_CORE_SOURCE_ROOT:
226+
continue
227+
filtered.append(entry)
228+
229+
if filtered:
230+
env["PYTHONPATH"] = os.pathsep.join(filtered)
231+
else:
232+
env.pop("PYTHONPATH", None)
233+
return env
234+
235+
209236
# -- Input validation (no GPU / driver needed) -----------------------------
210237

211238

0 commit comments

Comments
 (0)