Skip to content

Commit 0dadc89

Browse files
committed
Standardize _validate_git_tags_available() across all three packages
Make _validate_git_tags_available() take tag_pattern as parameter and ensure all three implementations (cuda-core, cuda-pathfinder, cuda-bindings) are identical. Add sync comments to remind maintainers to keep them in sync. Also fix ruff noqa comments: S603 on subprocess.run() line, S607 on list argument line.
1 parent f8cb7a5 commit 0dadc89

3 files changed

Lines changed: 42 additions & 32 deletions

File tree

cuda_bindings/setup.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@
2525

2626

2727
# ----------------------------------------------------------------------
28+
# Please keep the implementations in cuda-pathfinder, cuda-bindings, cuda-core in sync.
2829
# Validate git tags are available (fail early before setuptools-scm runs)
29-
def _validate_git_tags_available():
30-
"""Verify that git tags are available for setuptools-scm version detection."""
30+
def _validate_git_tags_available(tag_pattern: str) -> None:
31+
"""Verify that git tags are available for setuptools-scm version detection.
32+
33+
Args:
34+
tag_pattern: Git tag pattern to match (e.g., "v*[0-9]*")
35+
"""
3136
import subprocess
3237

3338
# Check if git is available
@@ -39,24 +44,14 @@ def _validate_git_tags_available():
3944
"Please ensure git is installed and available in your PATH."
4045
) from None
4146

42-
# Check if we're in a git repository
43-
try:
44-
subprocess.run(
45-
["git", "rev-parse", "--git-dir"], # noqa: S607
46-
capture_output=True,
47-
check=True,
48-
timeout=5,
49-
)
50-
except subprocess.CalledProcessError:
51-
raise RuntimeError(
52-
"Not in a git repository. setuptools-scm requires git tags to determine version.\n"
53-
"Please run this from within the cuda-python git repository."
54-
) from None
47+
# Find git repository root (setuptools_scm root='..')
48+
repo_root = os.path.dirname(os.path.dirname(__file__))
5549

5650
# Check if git describe works (this is what setuptools-scm uses)
5751
try:
58-
result = subprocess.run(
59-
["git", "describe", "--tags", "--long", "--match", "v*[0-9]*"], # noqa: S607
52+
result = subprocess.run( # noqa: S603
53+
["git", "describe", "--tags", "--long", "--match", tag_pattern], # noqa: S607
54+
cwd=repo_root,
6055
capture_output=True,
6156
text=True,
6257
timeout=5,
@@ -75,7 +70,7 @@ def _validate_git_tags_available():
7570
f"To fix:\n"
7671
f" git fetch --tags\n"
7772
f"\n"
78-
f"To debug, run: git describe --tags --long --match 'v*[0-9]*'"
73+
f"To debug, run: git describe --tags --long --match '{tag_pattern}'"
7974
) from None
8075
except subprocess.TimeoutExpired:
8176
raise RuntimeError(
@@ -84,7 +79,7 @@ def _validate_git_tags_available():
8479
) from None
8580

8681

87-
_validate_git_tags_available()
82+
_validate_git_tags_available("v*[0-9]*")
8883

8984
# ----------------------------------------------------------------------
9085
# Fetch configuration options

cuda_core/build_hooks.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,13 @@ def _determine_cuda_major_version() -> str:
8686
_extensions = None
8787

8888

89-
def _build_cuda_core():
90-
# Validate git tags are available (fail early before setuptools-scm runs)
89+
# Please keep the implementations in cuda-pathfinder, cuda-bindings, cuda-core in sync.
90+
def _validate_git_tags_available(tag_pattern: str) -> None:
91+
"""Verify that git tags are available for setuptools-scm version detection.
92+
93+
Args:
94+
tag_pattern: Git tag pattern to match (e.g., "v*[0-9]*")
95+
"""
9196
import subprocess
9297

9398
# Check if git is available
@@ -104,8 +109,8 @@ def _build_cuda_core():
104109

105110
# Check if git describe works (this is what setuptools-scm uses)
106111
try:
107-
result = subprocess.run(
108-
["git", "describe", "--tags", "--long", "--match", "cuda-core-v*[0-9]*"], # noqa: S607
112+
result = subprocess.run( # noqa: S603
113+
["git", "describe", "--tags", "--long", "--match", tag_pattern], # noqa: S607
109114
cwd=repo_root,
110115
capture_output=True,
111116
text=True,
@@ -125,14 +130,19 @@ def _build_cuda_core():
125130
f"To fix:\n"
126131
f" git fetch --tags\n"
127132
f"\n"
128-
f"To debug, run: git describe --tags --long --match 'cuda-core-v*[0-9]*'"
133+
f"To debug, run: git describe --tags --long --match '{tag_pattern}'"
129134
) from None
130135
except subprocess.TimeoutExpired:
131136
raise RuntimeError(
132137
"git describe command timed out. This may indicate git repository issues.\n"
133138
"Please check your git repository state."
134139
) from None
135140

141+
142+
def _build_cuda_core():
143+
# Validate git tags are available (fail early before setuptools-scm runs)
144+
_validate_git_tags_available("cuda-core-v*[0-9]*")
145+
136146
# Customizing the build hooks is needed because we must defer cythonization until cuda-bindings,
137147
# now a required build-time dependency that's dynamically installed via the other hook below,
138148
# is installed. Otherwise, cimport any cuda.bindings modules would fail!

cuda_pathfinder/build_hooks.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010
"""
1111

1212
import os
13-
import subprocess
1413

1514

16-
# Validate tags before importing setuptools.build_meta (which will use setuptools-scm)
17-
def _validate_git_tags_available():
18-
"""Verify that git tags are available for setuptools-scm version detection."""
15+
# Please keep the implementations in cuda-pathfinder, cuda-bindings, cuda-core in sync.
16+
def _validate_git_tags_available(tag_pattern: str) -> None:
17+
"""Verify that git tags are available for setuptools-scm version detection.
18+
19+
Args:
20+
tag_pattern: Git tag pattern to match (e.g., "v*[0-9]*")
21+
"""
22+
import subprocess
23+
1924
# Check if git is available
2025
try:
2126
subprocess.run(["git", "--version"], capture_output=True, check=True, timeout=5) # noqa: S607
@@ -30,8 +35,8 @@ def _validate_git_tags_available():
3035

3136
# Check if git describe works (this is what setuptools-scm uses)
3237
try:
33-
result = subprocess.run(
34-
["git", "describe", "--tags", "--long", "--match", "cuda-pathfinder-v*[0-9]*"], # noqa: S607
38+
result = subprocess.run( # noqa: S603
39+
["git", "describe", "--tags", "--long", "--match", tag_pattern], # noqa: S607
3540
cwd=repo_root,
3641
capture_output=True,
3742
text=True,
@@ -51,7 +56,7 @@ def _validate_git_tags_available():
5156
f"To fix:\n"
5257
f" git fetch --tags\n"
5358
f"\n"
54-
f"To debug, run: git describe --tags --long --match 'cuda-pathfinder-v*[0-9]*'"
59+
f"To debug, run: git describe --tags --long --match '{tag_pattern}'"
5560
) from None
5661
except subprocess.TimeoutExpired:
5762
raise RuntimeError(
@@ -61,7 +66,7 @@ def _validate_git_tags_available():
6166

6267

6368
# Validate tags before any build operations
64-
_validate_git_tags_available()
69+
_validate_git_tags_available("cuda-pathfinder-v*[0-9]*")
6570

6671
# Import and re-export all PEP 517 hooks from setuptools.build_meta
6772
from setuptools.build_meta import * # noqa: F403, E402

0 commit comments

Comments
 (0)