Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ repos:
files: ^cuda_bindings/
types: [text]

- id: check-generated-file-ctk-version
name: Check generated-file CTK version ceiling
entry: python ./toolshed/check_generated_file_ctk_version.py
language: python
files: ^cuda_bindings/
types: [text]
exclude: ^cuda_bindings/cuda/bindings/_internal/_fast_enum\.py$
additional_dependencies: [pyyaml]

- id: no-markdown-in-docs-source
name: Prevent markdown files in docs/source directories
entry: bash -c
Expand Down
44 changes: 44 additions & 0 deletions toolshed/check_generated_file_ctk_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

import re
import sys
from pathlib import Path

import yaml

_GENERATED_MARKER = "CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE:"
_VERSION_RE = re.compile(r"(?:generated across versions from \S+ to|generated with version) (?P<ver>\d+\.\d+)")


def major_minor(version_str):
major, minor = version_str.split(".")[:2]
return (int(major), int(minor))


def main(argv):
data = yaml.safe_load(Path("ci/versions.yml").read_text())
latest_mm = major_minor(data["cuda"]["build"]["version"])

failed = False
for path in map(Path, argv):
content = path.read_text(encoding="utf-8", errors="replace")
if _GENERATED_MARKER not in content:
continue
m = _VERSION_RE.search(content)
if m and major_minor(m.group("ver")) > latest_mm:
print(
f"ERROR: {path}: generated up to CTK {m.group('ver')}, which exceeds "
f"ci/versions.yml cuda.build.version {'.'.join(str(x) for x in latest_mm)}. "
f"Update ci/versions.yml if a new CTK release is intended."
)
failed = True
elif not m:
print(f"ERROR: {path}: could not find CTK version in generated file.")
failed = True

return int(failed)


if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))