Skip to content

Add bandit config, fix failing issues #577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2025
Merged
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
2 changes: 2 additions & 0 deletions .bandit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bandit]
skips = B101,B311
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ repos:
rev: 8ff25e07e487f143571cc305e56dd0253c60bc7b #v1.8.3
hooks:
- id: bandit
args:
- --ini
- .bandit

default_language_version:
python: python3
11 changes: 6 additions & 5 deletions cuda_bindings/tests/test_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,8 @@ def test_get_error_name_and_string():

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

(err,) = cuda.cuInit(0)
assert err == cuda.CUresult.CUDA_SUCCESS
Expand All @@ -656,12 +657,12 @@ def test_device_get_name():
err, ctx = cuda.cuCtxCreate(0, device)
assert err == cuda.CUresult.CUDA_SUCCESS

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

delimiter = b"\r\n" if platform.system() == "Windows" else b"\n"
expect = p.stdout.split(delimiter)
expect = p.split(delimiter)
size = 64
_, got = cuda.cuDeviceGetName(size, device)
got = got.split(b"\x00")[0]
Expand Down
3 changes: 2 additions & 1 deletion cuda_core/tests/example_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def run_example(samples_path, filename, env=None):
sys.argv = [fullpath]
old_sys_path = sys.path.copy()
sys.path.append(samples_path)
exec(script, env if env else {})
# TODO: Refactor the examples to give them a common callable `main()` to avoid needing to use exec here?
exec(script, env if env else {}) # nosec B102
except ImportError as e:
# for samples requiring any of optional dependencies
for m in ("cupy",):
Expand Down
7 changes: 4 additions & 3 deletions cuda_python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
#
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE

import ast
from setuptools import setup

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

setup(
version=version,
Expand Down
Loading