Skip to content

Commit 74c51bc

Browse files
committed
Try to determine CUDA_PATH etc.
1 parent 05e87cd commit 74c51bc

2 files changed

Lines changed: 46 additions & 47 deletions

File tree

cuda_core/examples/thread_block_cluster.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def main():
7171

7272
cuda_path = os.environ.get("CUDA_PATH", os.environ.get("CUDA_HOME"))
7373
if cuda_path is None:
74+
print(os.environ)
7475
print("this example requires a valid CUDA_PATH environment variable set", file=sys.stderr)
7576
sys.exit(1)
7677
cuda_include = os.path.join(cuda_path, "include")

cuda_core/tests/example_tests/test_basic_examples.py

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -81,50 +81,48 @@ def uv_installed() -> bool:
8181

8282

8383
@pytest.mark.parametrize("example", sample_files)
84-
class TestExamples:
85-
def test_example(self, example):
86-
package_requirements = PACKAGE_REQUIREMENTS.get(example, [])
87-
for package in package_requirements:
88-
try:
89-
__import__(package)
90-
except ImportError:
91-
pytest.skip(f"Skipping {example} due to missing package requirement: {package}")
92-
93-
system_requirement = SYSTEM_REQUIREMENTS.get(example, lambda: True)
94-
if not system_requirement():
95-
pytest.skip(f"Skipping {example} due to unmet system requirement")
96-
97-
example_path = os.path.join(samples_path, example)
98-
process = subprocess.run([sys.executable, example_path], capture_output=True) # noqa: S603
99-
if process.returncode != 0:
100-
if process.stdout:
101-
print(process.stdout.decode())
102-
if process.stderr:
103-
print(process.stderr.decode(), file=sys.stderr)
104-
raise AssertionError(f"`{example}` failed ({process.returncode})")
105-
106-
@pytest.mark.skipif(not uv_installed(), reason="uv is required to test PEP 723 metadata installation")
107-
def test_example_pep723(self, example):
108-
system_requirement = SYSTEM_REQUIREMENTS.get(example, lambda: True)
109-
if not system_requirement():
110-
pytest.skip(f"Skipping {example} due to unmet system requirement")
111-
112-
example_path = os.path.join(samples_path, example)
113-
114-
# Have uv use the same version of Python that is running the test suite,
115-
# not because they have to match but to give Python version coverage in CI.
116-
version_info = sys.version_info
117-
py_version = f"{version_info.major}.{version_info.minor}"
118-
119-
process = subprocess.run(["uv", "run", "--python", py_version, example_path], capture_output=True) # noqa: S603, S607
120-
if process.returncode != 0:
121-
# This example requires a development version of cuda_core, so requirements can't be met.
122-
# That's ok, it was tested in the other test, so we just skip it instead of failing.
123-
if re.search("Because only cuda-(core)|(bindings)", process.stderr.decode()):
124-
pytest.skip(f"Skipping {example} due to unmet PEP 723 requirement")
125-
126-
if process.stdout:
127-
print(process.stdout.decode())
128-
if process.stderr:
129-
print(process.stderr.decode(), file=sys.stderr)
130-
raise AssertionError(f"`uv run {example}` failed ({process.returncode})")
84+
def test_example(example):
85+
package_requirements = PACKAGE_REQUIREMENTS.get(example, [])
86+
for package in package_requirements:
87+
pytest.importorskip(package, reason=f"Skipping {example} due to missing package requirement: {package}")
88+
89+
system_requirement = SYSTEM_REQUIREMENTS.get(example, lambda: True)
90+
if not system_requirement():
91+
pytest.skip(f"Skipping {example} due to unmet system requirement")
92+
93+
example_path = os.path.join(samples_path, example)
94+
process = subprocess.run([sys.executable, example_path], capture_output=True) # noqa: S603
95+
if process.returncode != 0:
96+
if process.stdout:
97+
print(process.stdout.decode())
98+
if process.stderr:
99+
print(process.stderr.decode(), file=sys.stderr)
100+
raise AssertionError(f"`{example}` failed ({process.returncode})")
101+
102+
103+
@pytest.mark.parametrize("example", sample_files)
104+
@pytest.mark.skipif(not uv_installed(), reason="uv is required to test PEP 723 metadata installation")
105+
def test_example_pep723(example):
106+
system_requirement = SYSTEM_REQUIREMENTS.get(example, lambda: True)
107+
if not system_requirement():
108+
pytest.skip(f"Skipping {example} due to unmet system requirement")
109+
110+
example_path = os.path.join(samples_path, example)
111+
112+
# Have uv use the same version of Python that is running the test suite,
113+
# not because they have to match but to give Python version coverage in CI.
114+
version_info = sys.version_info
115+
py_version = f"{version_info.major}.{version_info.minor}"
116+
117+
process = subprocess.run(["uv", "run", "--python", py_version, example_path], capture_output=True) # noqa: S603, S607
118+
if process.returncode != 0:
119+
# This example requires a development version of cuda_core, so requirements can't be met.
120+
# That's ok, it was tested in the other test, so we just skip it instead of failing.
121+
if re.search("Because only cuda-(core)|(bindings)", process.stderr.decode()):
122+
pytest.skip(f"Skipping {example} due to unmet PEP 723 requirement")
123+
124+
if process.stdout:
125+
print(process.stdout.decode())
126+
if process.stderr:
127+
print(process.stderr.decode(), file=sys.stderr)
128+
raise AssertionError(f"`uv run {example}` failed ({process.returncode})")

0 commit comments

Comments
 (0)