Skip to content

Commit caaa5cc

Browse files
committed
cleaning up some of the guards, removing some of the standalone_numba_cuda reasons (not needed), cleaning up some imports
1 parent 5179b84 commit caaa5cc

File tree

13 files changed

+27
-50
lines changed

13 files changed

+27
-50
lines changed

numba_cuda/numba/cuda/__init__.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
import warnings
88
import sys
99

10-
# Import version from the parent package
1110
from numba_cuda._version import __version__
1211

13-
# Generate version_info early to avoid circular import issues
1412
from numba_cuda._version import generate_version_info
1513

1614
version_info = generate_version_info(__version__)
@@ -22,14 +20,7 @@
2220
# Re-export all type names
2321
from numba.cuda.types import *
2422

25-
# Check if upstream numba is available - needs to be defined early to avoid circular imports
26-
try:
27-
import numba
28-
29-
_HAS_NUMBA = True
30-
except ImportError:
31-
_HAS_NUMBA = False
32-
23+
_HAS_NUMBA = importlib.util.find_spec("numba") is not None
3324

3425
# Require NVIDIA CUDA bindings at import time
3526
if not (

numba_cuda/numba/cuda/core/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from functools import wraps
1616
from abc import abstractmethod
1717

18-
from numba_cuda._version import __version__
18+
import numba_cuda
1919

2020
# Filled at the end
2121
__all__ = []
@@ -456,7 +456,7 @@ def termcolor():
456456
This should not have happened, a problem has occurred in Numba's internals.
457457
You are currently using Numba version %s.
458458
%s
459-
""" % (__version__, feedback_details)
459+
""" % (numba_cuda.__version__, feedback_details)
460460

461461
error_extras = dict()
462462
error_extras["unsupported_error"] = unsupported_error_info

numba_cuda/numba/cuda/lowering.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,14 +1880,14 @@ def _lit_or_omitted(value):
18801880
"""Returns a Literal instance if the type of value is supported;
18811881
otherwise, return `Omitted(value)`.
18821882
"""
1883-
excepts = LiteralTypingError
1883+
typing_errors = LiteralTypingError
18841884
if _HAS_NUMBA:
18851885
from numba.core.errors import (
18861886
LiteralTypingError as CoreLiteralTypingError,
18871887
)
18881888

1889-
excepts = (LiteralTypingError, CoreLiteralTypingError)
1889+
typing_errors = (LiteralTypingError, CoreLiteralTypingError)
18901890
try:
18911891
return types.literal(value)
1892-
except excepts:
1892+
except typing_errors:
18931893
return types.Omitted(value)

numba_cuda/numba/cuda/tests/core/serialize_usecases.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
import numpy as np
1212
import numpy.random as nprand
1313

14-
from numba.cuda import _HAS_NUMBA
15-
16-
if _HAS_NUMBA:
17-
from numba import jit
14+
# This does not need a guard, it's already guarded at the import site
15+
from numba import jit
1816

1917

2018
@jit("int32(int32, int32)")

numba_cuda/numba/cuda/tests/cudapy/test_datetime.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
import numpy as np
55

6-
from numba.cuda import vectorize, guvectorize
7-
from numba import cuda
6+
from numba import cuda, vectorize, guvectorize
87
from numba.cuda.np.numpy_support import from_dtype
98
from numba.cuda.testing import CUDATestCase, skip_on_cudasim
109
import unittest

numba_cuda/numba/cuda/tests/cudapy/test_enums.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import numpy as np
99

1010
from numba.cuda import int16, int32
11-
from numba.cuda import vectorize
12-
from numba.cuda import _HAS_NUMBA
11+
from numba.cuda import vectorize, _HAS_NUMBA
1312

1413
if _HAS_NUMBA:
1514
from numba import njit
@@ -67,9 +66,7 @@ def f(out):
6766
f(expected)
6867
self.assertPreciseEqual(expected, got)
6968

70-
@skip_on_standalone_numba_cuda(
71-
"Test not supported in standalone numba_cuda"
72-
)
69+
@skip_on_standalone_numba_cuda
7370
def test_return_from_device_func(self):
7471
@njit
7572
def inner(pred):

numba_cuda/numba/cuda/tests/cudapy/test_gufunc_scalar.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"""
99

1010
import numpy as np
11-
from numba.cuda import guvectorize
12-
from numba import cuda
11+
from numba import cuda, guvectorize
1312
from numba.cuda.testing import skip_on_cudasim, CUDATestCase
1413
import unittest
1514

numba_cuda/numba/cuda/tests/cudapy/test_math.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
skip_on_cudasim,
1111
)
1212
from numba.cuda.np import numpy_support
13-
from numba import vectorize
14-
import numba.cuda as cuda
13+
from numba import cuda, vectorize
1514
from numba.cuda import float32, float64, int32, void, int64
1615
import math
1716

numba_cuda/numba/cuda/tests/cudapy/test_overload.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ def check_overload(self, kernel, expected):
237237
cuda.jit(kernel)[1, 1](x)
238238
self.assertEqual(x[0], expected)
239239

240-
@skip_on_standalone_numba_cuda(
241-
"Test not supported in standalone numba_cuda"
242-
)
240+
@skip_on_standalone_numba_cuda
243241
def check_overload_cpu(self, kernel, expected):
244242
x = np.ones(1, dtype=np.int32)
245243
njit(kernel)(x)
@@ -344,9 +342,7 @@ def kernel(x):
344342
expected = GENERIC_TARGET_OL_CALLS_TARGET_OL * GENERIC_TARGET_OL
345343
self.check_overload_cpu(kernel, expected)
346344

347-
@skip_on_standalone_numba_cuda(
348-
"Test not supported in standalone numba_cuda"
349-
)
345+
@skip_on_standalone_numba_cuda
350346
def test_overload_attribute_target(self):
351347
MyDummy, MyDummyType = self.make_dummy_type()
352348
mydummy_type_cpu = cpu_typeof(MyDummy()) # For @njit (cpu)

numba_cuda/numba/cuda/tests/cudapy/test_serialize.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
import pickle
55
import numpy as np
6-
from numba.cuda import vectorize
7-
from numba import cuda
6+
from numba import cuda, vectorize
87
from numba.cuda import types
98
from numba.cuda.testing import skip_on_cudasim, CUDATestCase
109
import unittest

0 commit comments

Comments
 (0)