Skip to content

Commit 8b0c526

Browse files
committed
cuda_core: recognize 12.9.6 enum docstrings
Treat the 12.9.6 backport line as docstring-capable and reuse the same version predicate in tests so error explanations follow the bindings releases that already expose usable enum docs. Made-with: Cursor
1 parent 4cbe3f3 commit 8b0c526

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

cuda_core/cuda/core/_utils/enum_explanations_helpers.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
"""Internal support for error-enum explanations.
55
66
``cuda_core`` keeps frozen 13.1.1 fallback tables for older ``cuda-bindings``
7-
releases. Starting with ``cuda-bindings`` 13.2.0, driver/runtime error enums
8-
carry usable ``__doc__`` text. This module decides which source to use and
9-
normalizes generated docstrings so user-facing ``CUDAError`` messages stay
7+
releases. Driver/runtime error enums carry usable ``__doc__`` text starting in
8+
the 12.x backport line at ``cuda-bindings`` 12.9.6, and in the mainline 13.x
9+
series at ``cuda-bindings`` 13.2.0. This module decides which source to use
10+
and normalizes generated docstrings so user-facing ``CUDAError`` messages stay
1011
close to the long-form explanation prose.
1112
1213
The cleanup rules here were derived while validating docstring-vs-dict parity
@@ -20,7 +21,8 @@
2021
import re
2122
from typing import Any
2223

23-
_MIN_BINDING_VERSION_FOR_ENUM_DOCSTRINGS = (13, 2, 0)
24+
_MIN_12X_BINDING_VERSION_FOR_ENUM_DOCSTRINGS = (12, 9, 6)
25+
_MIN_13X_BINDING_VERSION_FOR_ENUM_DOCSTRINGS = (13, 2, 0)
2426

2527

2628
# ``version.pyx`` cannot be reused here (circular import via ``cuda_utils``).
@@ -33,6 +35,14 @@ def _binding_version() -> tuple[int, int, int]:
3335
return tuple(int(v) for v in parts)
3436

3537

38+
def _binding_version_has_usable_enum_docstrings(version: tuple[int, int, int]) -> bool:
39+
"""Whether released bindings are known to carry usable error-enum ``__doc__`` text."""
40+
return (
41+
_MIN_12X_BINDING_VERSION_FOR_ENUM_DOCSTRINGS <= version < (13, 0, 0)
42+
or version >= _MIN_13X_BINDING_VERSION_FOR_ENUM_DOCSTRINGS
43+
)
44+
45+
3646
def _strip_doxygen_double_colon_prefixes(s: str) -> str:
3747
"""Remove Doxygen-style ``::`` before CUDA identifiers (not C++ ``Foo::Bar`` scope).
3848
@@ -119,9 +129,10 @@ def get_best_available_explanations(
119129
) -> DocstringBackedExplanations | dict[int, str | tuple[str, ...]]:
120130
"""Pick one explanation source per bindings version.
121131
122-
``cuda-bindings`` < 13.2.0: use the frozen 13.1.1 fallback tables.
123-
``cuda-bindings`` >= 13.2.0: use enum-member ``__doc__`` exclusively.
132+
Use enum-member ``__doc__`` only for bindings versions known to expose
133+
usable per-member text (12.9.6+ in the 12.x backport line, 13.2.0+ in the
134+
13.x mainline). Otherwise keep using the frozen 13.1.1 fallback tables.
124135
"""
125-
if _binding_version() < _MIN_BINDING_VERSION_FOR_ENUM_DOCSTRINGS:
136+
if not _binding_version_has_usable_enum_docstrings(_binding_version()):
126137
return fallback
127138
return DocstringBackedExplanations(enum_type)

cuda_core/tests/test_cuda_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212

1313

1414
def _skip_if_bindings_pre_enum_docstrings():
15+
from cuda.core._utils.enum_explanations_helpers import _binding_version_has_usable_enum_docstrings
1516
from cuda.core._utils.version import binding_version
1617

17-
if binding_version() < (13, 2, 0):
18-
pytest.skip("cuda-bindings < 13.2.0 may not expose enum __doc__ strings")
18+
if not _binding_version_has_usable_enum_docstrings(binding_version()):
19+
pytest.skip("cuda-bindings version does not expose usable enum __doc__ strings")
1920

2021

2122
def test_check_driver_error():

cuda_core/tests/test_utils_enum_explanations_helpers.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from cuda.core._utils.enum_explanations_helpers import (
88
DocstringBackedExplanations,
9+
_binding_version_has_usable_enum_docstrings,
910
_strip_doxygen_double_colon_prefixes,
1011
clean_enum_member_docstring,
1112
)
@@ -96,25 +97,43 @@ def test_docstring_backed_get_returns_default_for_missing_docstring_without_fall
9697
assert lut.get(7, default="sentinel") == "sentinel"
9798

9899

99-
def test_get_best_available_explanations_uses_fallback_before_13_2(monkeypatch):
100-
import cuda.core._utils.enum_explanations_helpers as cleanup
101-
102-
fallback = {7: "fallback text"}
103-
monkeypatch.setattr(cleanup, "_binding_version", lambda: (13, 1, 1))
104-
assert cleanup.get_best_available_explanations(_FakeEnumType({7: _FakeEnumMember("doc")}), fallback) is fallback
100+
@pytest.mark.parametrize(
101+
("version", "expected"),
102+
[
103+
pytest.param((12, 9, 5), False, id="before_12_9_6"),
104+
pytest.param((12, 9, 6), True, id="from_12_9_6"),
105+
pytest.param((13, 0, 0), False, id="13_0_mainline_gap"),
106+
pytest.param((13, 1, 1), False, id="13_1_1"),
107+
pytest.param((13, 2, 0), True, id="from_13_2_0"),
108+
],
109+
)
110+
def test_binding_version_has_usable_enum_docstrings(version, expected):
111+
assert _binding_version_has_usable_enum_docstrings(version) is expected
105112

106113

107-
def test_get_best_available_explanations_prefers_docstrings_from_13_2(monkeypatch):
114+
@pytest.mark.parametrize(
115+
("version", "expects_docstrings"),
116+
[
117+
pytest.param((12, 9, 5), False, id="before_12_9_6"),
118+
pytest.param((12, 9, 6), True, id="from_12_9_6"),
119+
pytest.param((13, 0, 0), False, id="13_0_mainline_gap"),
120+
pytest.param((13, 2, 0), True, id="from_13_2_0"),
121+
],
122+
)
123+
def test_get_best_available_explanations_switches_by_version(monkeypatch, version, expects_docstrings):
108124
import cuda.core._utils.enum_explanations_helpers as cleanup
109125

110126
fallback = {7: "fallback text"}
111-
monkeypatch.setattr(cleanup, "_binding_version", lambda: (13, 2, 0))
127+
monkeypatch.setattr(cleanup, "_binding_version", lambda: version)
112128
expl = cleanup.get_best_available_explanations(
113129
_FakeEnumType({7: _FakeEnumMember("clean me")}),
114130
fallback,
115131
)
116-
assert isinstance(expl, DocstringBackedExplanations)
117-
assert expl.get(7) == "clean me"
132+
if expects_docstrings:
133+
assert isinstance(expl, DocstringBackedExplanations)
134+
assert expl.get(7) == "clean me"
135+
else:
136+
assert expl is fallback
118137

119138

120139
def test_driver_cu_result_explanations_get_matches_clean_docstring():

0 commit comments

Comments
 (0)