Skip to content

Commit 6718a70

Browse files
committed
pre-commit fixes (automatic, trivial)
1 parent 4f34fdd commit 6718a70

3 files changed

Lines changed: 54 additions & 33 deletions

File tree

.spdx-ignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ requirements*.txt
1010
cuda_bindings/examples/*
1111

1212
# Vendored
13-
cuda_core/cuda/core/experimental/include/dlpack.h
13+
cuda_core/cuda/core/include/dlpack.h

cuda_core/cuda/core/experimental/__init__.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
def _warn_deprecated():
5151
"""Emit a deprecation warning for using the experimental namespace.
52-
52+
5353
Note: This warning is only when the experimental module is first imported.
5454
Subsequent accesses to attributes (like utils, Device, etc.) do not trigger
5555
additional warnings since they are already set in the module namespace.
@@ -71,6 +71,7 @@ def _warn_deprecated():
7171
_warn_deprecated()
7272

7373
from cuda.core import utils # noqa: E402
74+
7475
# Make utils accessible as a submodule for backward compatibility
7576
__import__("sys").modules[__spec__.name + ".utils"] = utils
7677
from cuda.core._device import Device # noqa: E402
@@ -103,17 +104,34 @@ def _warn_deprecated():
103104
__import__("sys").modules[__spec__.name + ".system"] = system
104105
del System
105106

107+
106108
# Also create forwarding stubs for submodules
107109
# These will be imported lazily when accessed
108110
def __getattr__(name):
109111
"""Forward attribute access to the new location with deprecation warning."""
110-
if name in ("_device", "_event", "_graph", "_launch_config", "_launcher",
111-
"_linker", "_memory", "_module", "_program", "_stream", "_system",
112-
"_utils", "_context", "_dlpack", "_kernel_arg_handler",
113-
"_launch_config", "_memoryview"):
112+
if name in (
113+
"_device",
114+
"_event",
115+
"_graph",
116+
"_launch_config",
117+
"_launcher",
118+
"_linker",
119+
"_memory",
120+
"_module",
121+
"_program",
122+
"_stream",
123+
"_system",
124+
"_utils",
125+
"_context",
126+
"_dlpack",
127+
"_kernel_arg_handler",
128+
"_launch_config",
129+
"_memoryview",
130+
):
114131
_warn_deprecated()
115132
# Import the submodule from the new location
116133
import importlib
134+
117135
new_name = name.lstrip("_")
118136
try:
119137
return importlib.import_module(f"cuda.core.{new_name}")

cuda_core/tests/test_experimental_backward_compat.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@
99
correctly and emit appropriate deprecation warnings.
1010
"""
1111

12-
import warnings
13-
1412
import pytest
1513

14+
1615
# Test that experimental imports still work
1716
def test_experimental_imports_work():
1817
"""Test that imports from experimental namespace still work."""
1918
# Clear cached module to ensure warning is emitted
2019
import sys
21-
if 'cuda.core.experimental' in sys.modules:
22-
del sys.modules['cuda.core.experimental']
23-
20+
21+
if "cuda.core.experimental" in sys.modules:
22+
del sys.modules["cuda.core.experimental"]
23+
2424
# Test main module import - should emit deprecation warning
2525
with pytest.deprecated_call():
2626
import cuda.core.experimental
27-
27+
2828
# Test that symbols are accessible
2929
assert hasattr(cuda.core.experimental, "Device")
3030
assert hasattr(cuda.core.experimental, "Stream")
@@ -36,7 +36,7 @@ def test_experimental_symbols_are_same_objects():
3636
"""Test that experimental namespace symbols are the same objects as core."""
3737
import cuda.core
3838
import cuda.core.experimental
39-
39+
4040
# Compare classes/types
4141
assert cuda.core.experimental.Device is cuda.core.Device
4242
assert cuda.core.experimental.Stream is cuda.core.Stream
@@ -49,7 +49,7 @@ def test_experimental_symbols_are_same_objects():
4949
assert cuda.core.experimental.GraphBuilder is cuda.core.GraphBuilder
5050
assert cuda.core.experimental.Event is cuda.core.Event
5151
assert cuda.core.experimental.Linker is cuda.core.Linker
52-
52+
5353
# Compare singletons
5454
assert cuda.core.experimental.system is cuda.core.system
5555

@@ -58,17 +58,18 @@ def test_experimental_direct_imports():
5858
"""Test that direct imports from experimental submodules work."""
5959
# Clear any cached imports to ensure warnings are emitted
6060
import sys
61-
if 'cuda.core.experimental' in sys.modules:
62-
del sys.modules['cuda.core.experimental']
63-
61+
62+
if "cuda.core.experimental" in sys.modules:
63+
del sys.modules["cuda.core.experimental"]
64+
6465
# Test various import patterns - warning is emitted once at module import time
6566
with pytest.deprecated_call():
66-
from cuda.core.experimental import Device, Stream, Buffer
67-
from cuda.core.experimental import Program, Kernel, ObjectCode
68-
from cuda.core.experimental import Graph, GraphBuilder, Event
69-
from cuda.core.experimental import Linker, launch
70-
from cuda.core.experimental import system
71-
67+
from cuda.core.experimental import (
68+
Buffer,
69+
Device,
70+
Stream,
71+
)
72+
7273
# Verify objects are usable
7374
assert Device is not None
7475
assert Stream is not None
@@ -78,7 +79,7 @@ def test_experimental_direct_imports():
7879
def test_experimental_submodule_access():
7980
"""Test that accessing experimental submodules works."""
8081
import cuda.core.experimental
81-
82+
8283
# Test that submodules can be accessed (via __getattr__)
8384
# Note: These may not exist as actual modules, but the forwarding should work
8485
try:
@@ -94,28 +95,29 @@ def test_experimental_submodule_access():
9495

9596
def test_experimental_utils_module():
9697
"""Test that experimental.utils module works.
97-
98+
9899
Note: The deprecation warning is only emitted once at import time when
99100
cuda.core.experimental is first imported. Accessing utils or importing
100101
from utils does not trigger additional warnings since utils is already
101102
set as an attribute in the module namespace.
102103
"""
103104
import cuda.core.experimental
104-
105+
105106
# Should be able to access utils (no warning on access, only on initial import)
106107
assert hasattr(cuda.core.experimental, "utils")
107108
assert cuda.core.experimental.utils is not None
108-
109+
109110
# Should have expected utilities (no warning on import from utils submodule)
110111
from cuda.core.experimental.utils import StridedMemoryView, args_viewable_as_strided_memory
112+
111113
assert StridedMemoryView is not None
112114
assert args_viewable_as_strided_memory is not None
113115

114116

115117
def test_experimental_options_classes():
116118
"""Test that options classes are accessible."""
117119
import cuda.core.experimental
118-
120+
119121
assert hasattr(cuda.core.experimental, "EventOptions")
120122
assert hasattr(cuda.core.experimental, "StreamOptions")
121123
assert hasattr(cuda.core.experimental, "LaunchConfig")
@@ -125,7 +127,7 @@ def test_experimental_options_classes():
125127
assert hasattr(cuda.core.experimental, "GraphDebugPrintOptions")
126128
assert hasattr(cuda.core.experimental, "DeviceMemoryResourceOptions")
127129
assert hasattr(cuda.core.experimental, "VirtualMemoryResourceOptions")
128-
130+
129131
# Verify they're the same objects
130132
assert cuda.core.experimental.EventOptions is cuda.core.EventOptions
131133
assert cuda.core.experimental.StreamOptions is cuda.core.StreamOptions
@@ -135,13 +137,13 @@ def test_experimental_options_classes():
135137
def test_experimental_memory_classes():
136138
"""Test that memory-related classes are accessible."""
137139
import cuda.core.experimental
138-
140+
139141
assert hasattr(cuda.core.experimental, "MemoryResource")
140142
assert hasattr(cuda.core.experimental, "DeviceMemoryResource")
141143
assert hasattr(cuda.core.experimental, "LegacyPinnedMemoryResource")
142144
assert hasattr(cuda.core.experimental, "VirtualMemoryResource")
143145
assert hasattr(cuda.core.experimental, "GraphMemoryResource")
144-
146+
145147
# Verify they're the same objects
146148
assert cuda.core.experimental.MemoryResource is cuda.core.MemoryResource
147149
assert cuda.core.experimental.DeviceMemoryResource is cuda.core.DeviceMemoryResource
@@ -151,11 +153,12 @@ def test_experimental_memory_classes():
151153
def test_experimental_instantiations():
152154
"""Test that objects can be instantiated through experimental namespace."""
153155
from cuda.core.experimental import Device
154-
156+
155157
# Should be able to create objects
156158
device = Device()
157159
assert device is not None
158-
160+
159161
# Verify it's the same type
160162
from cuda.core import Device as CoreDevice
163+
161164
assert isinstance(device, CoreDevice)

0 commit comments

Comments
 (0)