Skip to content

Commit eabaf4b

Browse files
authored
Unify ruff config and apply lint fixes across all sub-repos (#1703)
* Unify ruff config across sub-repos Merge cuda_pathfinder's [tool.ruff] into the top-level ruff.toml and remove the duplicate. The unified config is the union of all lint rules (adding ARG, Q, N, C4, PIE, T20, RUF, PT, DTZ) with sane per-file ignores for tests, examples, benchmarks, scripts, and CUDA naming conventions in cuda_bindings. Made-with: Cursor * Add ruff to pixi dependencies Made-with: Cursor * Update ruff config with review feedback - Remove combine-as-imports (keep as-imports separate from bare imports) - Add C408 to global ignores (dict()/list()/tuple() calls are fine) - Add RUF005 to global ignores (list concatenation is fine) - Add E402, F403, F405 to __init__.py per-file-ignores - Add E702, B028 to test per-file-ignores - Add T201 for canary_probe_subprocess.py Made-with: Cursor * fix(ruff/cuda_core): I001 sort imports - I001: unsorted imports — 48 fixed across 48 files Made-with: Cursor * fix(ruff/cuda_core): RUF100 remove stale noqa comments - RUF100: unused-noqa — 80 fixed across 24 files Made-with: Cursor * fix(ruff/cuda_core): C4 simplify comprehensions - C416: unnecessary-comprehension — use set()/list() directly - C401: unnecessary-generator-set — use set comprehension - C419: unnecessary-comprehension-in-call — use generator in all()/any() - C400: unnecessary-generator-list — use list comprehension - C414: unnecessary-double-cast-or-process — remove redundant list() - C420: unnecessary-dict-comprehension — use dict.fromkeys() 40 fixed across 10 files Made-with: Cursor * fix(ruff/cuda_core): PIE misc cleanup - PIE808: unnecessary-range-start — remove redundant range(0, n) - PIE790: unnecessary-placeholder — remove pass after docstring - PIE810: multiple-starts-ends-with — consolidate into tuple arg 3 fixed across 3 files Made-with: Cursor * fix(ruff/cuda_core): PT pytest-style fixes - PT003: extraneous-scope-function — remove default scope="function" - PT022: pytest-useless-yield-fixture — convert yield fixture to return - PT001: pytest-fixture-incorrect-parentheses — remove empty parentheses - PT013: pytest-incorrect-pytest-import — use pytest.param instead of from pytest import param 18 fixed across 4 files Made-with: Cursor * fix(ruff/cuda_core): RUF ruff-specific fixes - RUF022: unsorted-dunder-all — sort __all__ entries (4 fixes across 4 files) - RUF023: unsorted-dunder-slots — sort __slots__ entries (3 fixes across 1 file) - RUF012: mutable-class-default — suppress with noqa for lookup tables (5 fixes in 1 file) Made-with: Cursor * fix(ruff/cuda_core): E pycodestyle fixes - E711: none-comparison — use 'is not None' instead of '!= None' (1 fix in 1 file) Made-with: Cursor * fix(ruff/cuda_core): N naming convention fixes - N806: non-lowercase-variable-in-function — rename CUDA_PATH to cuda_path (2 fixes in 1 file) - N816: mixed-case-variable-in-global-scope — suppress for CUDA API naming (1 noqa in 1 file) - N801: invalid-class-name — suppress for setuptools convention (1 noqa in 1 file) Made-with: Cursor * fix(ruff/cuda_core): ARG unused argument suppression - ARG002: unused-method-argument — suppress for interface method (1 noqa in 1 file) Made-with: Cursor * fix(ruff/cuda_core): F pyflakes fixes - F401: unused-import — suppress for re-exports and side-effect imports (4 noqa in 2 files) Made-with: Cursor * fix(ruff/cuda_core): B bugbear fixes - B018: useless-expression — suppress for property access expected to raise (2 noqa in 1 file) Made-with: Cursor * fix(ruff/cuda_core): S bandit security suppressions - S110: try-except-pass — suppress for best-effort cleanup (5 noqa in 2 files) - S102: exec-builtin — suppress in test code (2 noqa in 2 files) - S301: suspicious-pickle-usage — suppress in test code (3 noqa in 3 files) Made-with: Cursor * fix(ruff/cuda_bindings): I001 sort imports - I001: unsorted imports — 42 fixed across NFILES files Made-with: Cursor * fix(ruff/cuda_bindings): RUF100 remove stale noqa comments - RUF100: unused-noqa — 16 fixed across 9 files Made-with: Cursor * fix(ruff/cuda_bindings): C4 simplify comprehensions - C416: unnecessary-comprehension — use set()/list() directly - C401: unnecessary-generator-set — use set comprehension - C419: unnecessary-comprehension-in-call — use generator in all()/any() - C400: unnecessary-generator-list — use list comprehension - C414: unnecessary-double-cast-or-process — remove redundant list() - C420: unnecessary-dict-comprehension — use dict.fromkeys() 9 fixed across 3 files Made-with: Cursor * fix(ruff/cuda_bindings): PIE misc cleanup - PIE808: unnecessary-range-start — remove redundant range(0, n) - PIE790: unnecessary-placeholder — remove pass after docstring - PIE810: multiple-starts-ends-with — consolidate into tuple arg 5 fixed across 4 files Made-with: Cursor * fix(ruff/cuda_bindings): PT pytest-style fixes - PT003: extraneous-scope-function — remove default scope="function" (4 fixes) - PT001: pytest-fixture-incorrect-parentheses — remove empty parentheses 4 fixed across 1 files Made-with: Cursor * fix(ruff/cuda_bindings): F pyflakes fixes - F401: unused-import — suppress for intentional re-exports and side-effect imports (2 noqa in 2 files) Made-with: Cursor * fix(ruff/cuda_bindings): S bandit security suppressions - S110: try-except-pass — suppress for best-effort cleanup (2 noqa in 1 file) - S603: subprocess-without-shell-equals-true — suppress at call site (5 noqa in 4 files) - S607: start-process-with-partial-path — suppress at call site (3 noqa in 2 files) Made-with: Cursor * fix(ruff/cuda_pathfinder): RUF100 remove stale noqa comments - RUF100: unused-noqa — 12 fixed across 7 files Made-with: Cursor * fix(ruff/cuda_pathfinder): SIM simplify code - SIM102: collapsible-if — merge nested if statements (1 fix in 1 file) - SIM105: suppressible-exception — use contextlib.suppress instead of try/except/pass (1 fix in 1 file) Made-with: Cursor * fix(ruff/cuda_pathfinder): S bandit security suppressions - S110: try-except-pass — suppress for best-effort cleanup (1 noqa in 1 file) Made-with: Cursor * fix(ruff/cuda_python_test_helpers): I001 sort imports - I001: unsorted imports — across 1 files Made-with: Cursor * fix(ruff/cuda_python_test_helpers): RUF100 remove stale noqa comments - RUF100: unused-noqa — 1 fixed across 1 files Made-with: Cursor * fix(ruff/cuda_python_test_helpers): RUF ruff-specific fixes - RUF059: unused-unpacked-variable — prefix unused vars with underscore (2 fixes in 1 file) Made-with: Cursor * fix(ruff/toolshed): I001 sort imports - I001: unsorted imports — across 2 files Made-with: Cursor * fix(ruff/toolshed): RUF100 remove stale noqa comments - RUF100: unused-noqa — 2 fixed across 1 files Made-with: Cursor * fix(ruff/toolshed): DTZ datetime timezone fixes - DTZ011: call-date-today — use timezone-aware datetime.now(tz=utc) (1 fix in 1 file) Made-with: Cursor * fix(ruff/toolshed): N naming convention fixes - N806: non-lowercase-variable-in-function — rename TILE_SIZE to tile_size (1 fix in 1 file) Made-with: Cursor * fix(ruff/toolshed): S bandit security suppressions - S603: subprocess-without-shell-equals-true — suppress at call site (1 noqa in 1 file) - S607: start-process-with-partial-path — suppress at call site (1 noqa in 1 file) Made-with: Cursor * fix(ruff/ci): RUF100 remove stale noqa comments - RUF100: unused-noqa — 1 fixed across 1 files Made-with: Cursor * fix(ruff/ci): RUF ruff-specific fixes - RUF013: implicit-optional — annotate as T | None explicitly (2 fixes in 1 file) Made-with: Cursor * fix(ruff/ci): S bandit security suppressions - S603: subprocess-without-shell-equals-true — suppress at call site (1 noqa in 1 file) Made-with: Cursor * fix(ruff/root): ARG unused argument suppression - ARG001: unused-function-argument — suppress for pytest hook signature (1 noqa in 1 file) Made-with: Cursor * fixup: correct S noqa placement for multiline calls Made-with: Cursor * fix(ruff): apply ruff formatting - 2 files reformatted (cuda_core/cuda/core/system/__init__.py, cuda_core/tests/test_utils.py) Made-with: Cursor * fix(ruff): add RUF012 to test/benchmark per-file-ignores ctypes Structure._fields_ is a standard pattern, not a mutable default concern Made-with: Cursor * fix(core): use CUmemAllocationType for VMM allocation enums Read CU_MEM_ALLOCATION_TYPE_* from CUmemAllocationType instead of CUmemAccess_flags so cuda.core imports correctly in test/docs CI jobs. Made-with: Cursor * fix(tests): use pytest.param in test_utils Switch test parametrization calls to pytest.param so collection succeeds under current pytest and the pixi cuda_core suite runs end-to-end. Made-with: Cursor
1 parent 21c46f0 commit eabaf4b

File tree

126 files changed

+1403
-361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+1403
-361
lines changed

ci/tools/merge_cuda_core_wheels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from typing import List
3131

3232

33-
def run_command(cmd: List[str], cwd: Path = None, env: dict = os.environ) -> subprocess.CompletedProcess:
33+
def run_command(cmd: List[str], cwd: Path | None = None, env: dict = os.environ) -> subprocess.CompletedProcess:
3434
"""Run a command with error handling."""
3535
print(f"Running: {' '.join(cmd)}")
3636
if cwd:
@@ -47,7 +47,7 @@ def run_command(cmd: List[str], cwd: Path = None, env: dict = os.environ) -> sub
4747
return result
4848

4949

50-
def print_wheel_directory_structure(wheel_path: Path, filter_prefix: str = "cuda/core/", label: str = None):
50+
def print_wheel_directory_structure(wheel_path: Path, filter_prefix: str = "cuda/core/", label: str | None = None):
5151
"""Print the directory structure of a wheel file, similar to unzip -l output.
5252
5353
Args:

conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77

88

9-
def pytest_collection_modifyitems(config, items):
9+
def pytest_collection_modifyitems(config, items): # noqa: ARG001
1010
cuda_home = os.environ.get("CUDA_HOME")
1111
for item in items:
1212
nodeid = item.nodeid.replace("\\", "/")

cuda_bindings/benchmarks/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import numpy as np
55
import pytest
6+
67
from cuda.bindings import driver as cuda
78
from cuda.bindings import nvrtc
89
from cuda.bindings import runtime as cudart
@@ -22,7 +23,7 @@ def ASSERT_DRV(err):
2223
raise RuntimeError(f"Unknown error type: {err}")
2324

2425

25-
@pytest.fixture(scope="function")
26+
@pytest.fixture
2627
def init_cuda():
2728
# Initialize
2829
(err,) = cuda.cuInit(0)
@@ -44,7 +45,7 @@ def init_cuda():
4445
ASSERT_DRV(err)
4546

4647

47-
@pytest.fixture(scope="function")
48+
@pytest.fixture
4849
def load_module():
4950
module = None
5051

cuda_bindings/benchmarks/test_launch_latency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import ctypes
55

66
import pytest
7-
from cuda.bindings import driver as cuda
87
from kernels import kernel_string
98

109
from conftest import ASSERT_DRV
10+
from cuda.bindings import driver as cuda
1111

1212

1313
def launch(kernel, stream, args=(), arg_types=()):

cuda_bindings/benchmarks/test_pointer_attributes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import random
55

66
import pytest
7-
from cuda.bindings import driver as cuda
87

98
from conftest import ASSERT_DRV
9+
from cuda.bindings import driver as cuda
1010

1111
random.seed(0)
1212

cuda_bindings/build_hooks.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,20 @@ def _parse_headers(header_dict, include_path_list, parser_caching):
176176
CUDA_VERSION = parser.defs["macros"].get("CUDA_VERSION", "Unknown")
177177
print(f"Found CUDA_VERSION: {CUDA_VERSION}", flush=True)
178178

179-
found_types += {key for key in parser.defs["types"]}
180-
found_types += {key for key in parser.defs["structs"]}
181-
found_types += {key for key in parser.defs["unions"]}
182-
found_types += {key for key in parser.defs["enums"]}
183-
found_functions += {key for key in parser.defs["functions"]}
184-
found_values += {key for key in parser.defs["values"]}
179+
found_types += set(parser.defs["types"])
180+
found_types += set(parser.defs["structs"])
181+
found_types += set(parser.defs["unions"])
182+
found_types += set(parser.defs["enums"])
183+
found_functions += set(parser.defs["functions"])
184+
found_values += set(parser.defs["values"])
185185

186186
for key, value in parser.defs["structs"].items():
187187
struct_list[key] = _Struct(key, value["members"])
188188
for key, value in parser.defs["unions"].items():
189189
struct_list[key] = _Struct(key, value["members"])
190190

191191
for key, value in struct_list.items():
192-
if key.startswith("anon_union") or key.startswith("anon_struct"):
192+
if key.startswith(("anon_union", "anon_struct")):
193193
continue
194194

195195
found_struct += [key]
@@ -408,7 +408,7 @@ def _cleanup_dst_files():
408408
)
409409

410410
# Cythonize
411-
cython_directives = dict(language_level=3, embedsignature=True, binding=True, freethreading_compatible=True)
411+
cython_directives = {"language_level": 3, "embedsignature": True, "binding": True, "freethreading_compatible": True}
412412
if compile_for_coverage:
413413
cython_directives["linetrace"] = True
414414

cuda_bindings/cuda/bindings/_test_helpers/arch_check.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from functools import cache
77

88
import pytest
9+
910
from cuda.bindings import nvml
1011

1112

cuda_bindings/examples/0_Introduction/clock_nvrtc_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
from common import common
88
from common.helper_cuda import checkCudaErrors, findCudaDevice
9+
910
from cuda.bindings import driver as cuda
1011

1112
clock_nvrtc = """\
@@ -67,7 +68,7 @@ def main():
6768
timer = np.empty(NUM_BLOCKS * 2, dtype="int64")
6869
hinput = np.empty(NUM_THREADS * 2, dtype="float32")
6970

70-
for i in range(0, NUM_THREADS * 2):
71+
for i in range(NUM_THREADS * 2):
7172
hinput[i] = i
7273

7374
devID = findCudaDevice()
@@ -105,7 +106,7 @@ def main():
105106

106107
avgElapsedClocks = 0.0
107108

108-
for i in range(0, NUM_BLOCKS):
109+
for i in range(NUM_BLOCKS):
109110
avgElapsedClocks += timer[i + NUM_BLOCKS] - timer[i]
110111

111112
avgElapsedClocks = avgElapsedClocks / NUM_BLOCKS

cuda_bindings/examples/0_Introduction/simpleCubemapTexture_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import numpy as np
99
from common import common
1010
from common.helper_cuda import checkCudaErrors, findCudaDevice
11+
1112
from cuda.bindings import driver as cuda
1213
from cuda.bindings import runtime as cudart
1314

cuda_bindings/examples/0_Introduction/simpleP2P_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import numpy as np
99
from common import common
1010
from common.helper_cuda import checkCudaErrors
11+
1112
from cuda.bindings import driver as cuda
1213
from cuda.bindings import runtime as cudart
1314

0 commit comments

Comments
 (0)