Skip to content

Commit 161306b

Browse files
authored
Merge pull request #577 from kkraus14/bandit_config
Add bandit config, fix failing issues
2 parents d695bfe + 83a89d3 commit 161306b

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

.bandit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[bandit]
2+
skips = B101,B311

.pre-commit-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ repos:
2020
rev: 8ff25e07e487f143571cc305e56dd0253c60bc7b #v1.8.3
2121
hooks:
2222
- id: bandit
23+
args:
24+
- --ini
25+
- .bandit
2326

2427
default_language_version:
2528
python: python3

cuda_bindings/tests/test_cuda.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,8 @@ def test_get_error_name_and_string():
647647

648648
@pytest.mark.skipif(not callableBinary("nvidia-smi"), reason="Binary existance needed")
649649
def test_device_get_name():
650-
import subprocess
650+
# TODO: Refactor this test once we have nvml bindings to avoid the use of subprocess
651+
import subprocess # nosec B404
651652

652653
(err,) = cuda.cuInit(0)
653654
assert err == cuda.CUresult.CUDA_SUCCESS
@@ -656,12 +657,12 @@ def test_device_get_name():
656657
err, ctx = cuda.cuCtxCreate(0, device)
657658
assert err == cuda.CUresult.CUDA_SUCCESS
658659

659-
p = subprocess.run(
660-
["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
661-
)
660+
p = subprocess.check_output(
661+
["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"], shell=False, stderr=subprocess.PIPE
662+
) # nosec B603, B607
662663

663664
delimiter = b"\r\n" if platform.system() == "Windows" else b"\n"
664-
expect = p.stdout.split(delimiter)
665+
expect = p.split(delimiter)
665666
size = 64
666667
_, got = cuda.cuDeviceGetName(size, device)
667668
got = got.split(b"\x00")[0]

cuda_core/tests/example_tests/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def run_example(samples_path, filename, env=None):
3333
sys.argv = [fullpath]
3434
old_sys_path = sys.path.copy()
3535
sys.path.append(samples_path)
36-
exec(script, env if env else {})
36+
# TODO: Refactor the examples to give them a common callable `main()` to avoid needing to use exec here?
37+
exec(script, env if env else {}) # nosec B102
3738
except ImportError as e:
3839
# for samples requiring any of optional dependencies
3940
for m in ("cupy",):

cuda_python/setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
#
33
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
44

5+
import ast
56
from setuptools import setup
67

78
# We want to keep the version in sync with cuda.bindings, but setuptools would not let
89
# us to refer to any files outside of the project root, so we have to employ our own
910
# run-time lookup using setup()...
1011
with open("../cuda_bindings/cuda/bindings/_version.py") as f:
11-
exec(f.read())
12-
version = __version__ # noqa: F821
13-
del __version__ # noqa: F821
12+
for line in f:
13+
if line.startswith("__version__"):
14+
version = ast.parse(line).body[0].value.value
1415

1516
setup(
1617
version=version,

0 commit comments

Comments
 (0)