Skip to content

chore(dev-tools): port bandit config to ruff#1033

Merged
cpcloud merged 17 commits intoNVIDIA:mainfrom
cpcloud:ruff-bandit
Sep 29, 2025
Merged

chore(dev-tools): port bandit config to ruff#1033
cpcloud merged 17 commits intoNVIDIA:mainfrom
cpcloud:ruff-bandit

Conversation

@cpcloud
Copy link
Copy Markdown
Contributor

@cpcloud cpcloud commented Sep 26, 2025

Port our bandit config over to using ruff.

@copy-pr-bot
Copy link
Copy Markdown
Contributor

copy-pr-bot bot commented Sep 26, 2025

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

Copy link
Copy Markdown
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to replace these in this PR?

rwgk-win11.localdomain:~/forked/cuda-python $ git grep nosec
cuda_bindings/tests/test_cuda.py:    import subprocess  # nosec B404
cuda_bindings/tests/test_cuda.py:    )  # nosec B603, B607
cuda_bindings/tests/test_utils.py:import subprocess  # nosec B404
cuda_bindings/tests/test_utils.py:    subprocess.check_call(  # nosec B603
cuda_core/tests/example_tests/utils.py:        exec(script, env if env else {})  # nosec B102
cuda_core/tests/test_module.py:import pickle  # nosec B403, B301
cuda_core/tests/test_module.py:    result = pickle.loads(pickle.dumps(objcode))  # nosec B403, B301
cuda_pathfinder/cuda/pathfinder/_utils/platform_aware.py:        from subprocess import list2cmdline  # nosec B404
cuda_pathfinder/tests/spawned_process_runner.py:            except Exception:  # nosec B110
cuda_pathfinder/tests/spawned_process_runner.py:        except Exception:  # nosec B110

Comment thread .github/workflows/bandit.yml Outdated
- name: Perform Bandit Analysis using Ruff
uses: astral-sh/ruff-action@57714a7c8a2e59f32539362ba31877a1957dded1 # v3.5.1
with:
args: "--select S --ignore S101,S311,S404 --config ruff.toml --output-format sarif --output-file results.sarif"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reasonable way we could consolidate the --ignore list here and the list in ruff.toml?

If not, could you please add 1-line comments in both places, to keep the lists in sync?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really need to avoid having so many "make sure to sync" comments littered everywhere. IME these basically never have the intended effect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a programmatic plucking of the desired ignore codes.

Comment thread .pre-commit-config.yaml
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/PyCQA/bandit
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hooray!

@rwgk
Copy link
Copy Markdown
Collaborator

rwgk commented Sep 26, 2025

Oh, sorry, you're replacing already! I overlooked change vs additions. Please disregard my other comment.

@rwgk
Copy link
Copy Markdown
Collaborator

rwgk commented Sep 26, 2025

There are still some nosec left:

rwgk-win11.localdomain:~/forked/cuda-python $ git sw ruff-bandit
branch 'ruff-bandit' set up to track 'cpcloud/ruff-bandit'.
Switched to a new branch 'ruff-bandit'
rwgk-win11.localdomain:~/forked/cuda-python $ git grep nosec
cuda_bindings/tests/test_cuda.py:    import subprocess  # nosec B404
cuda_bindings/tests/test_utils.py:import subprocess  # nosec B404
cuda_core/tests/test_module.py:import pickle  # nosec B403, B301
cuda_pathfinder/cuda/pathfinder/_utils/platform_aware.py:        from subprocess import list2cmdline  # nosec B404

@cpcloud
Copy link
Copy Markdown
Contributor Author

cpcloud commented Sep 26, 2025

Interesting, I'm not sure how those are not being picked up by ruff. Let me poke a bit.

@leofang leofang requested a review from kkraus14 September 26, 2025 21:32
@cpcloud
Copy link
Copy Markdown
Contributor Author

cpcloud commented Sep 29, 2025

/ok to test

rwgk
rwgk previously approved these changes Sep 29, 2025
Comment thread cuda_pathfinder/cuda/pathfinder/_utils/platform_aware.py Outdated
Comment thread .github/workflows/bandit.yml Outdated
# (ruff.toml, pyproject.toml, etc), so to avoid having keep everything
# in sync we grab them from the TOML programmatically
run: |
echo "codes=$(yj -tj < ./ruff.toml | jq '[.lint.ignore[] | select(test("^S\\d+"))] | join(",")' -r)" >> "$GITHUB_OUTPUT"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, cool!

@cpcloud
Copy link
Copy Markdown
Contributor Author

cpcloud commented Sep 29, 2025

/ok to test

@github-actions

This comment has been minimized.

@cpcloud
Copy link
Copy Markdown
Contributor Author

cpcloud commented Sep 29, 2025

/ok to test

@cpcloud
Copy link
Copy Markdown
Contributor Author

cpcloud commented Sep 29, 2025

/ok to test

@cpcloud
Copy link
Copy Markdown
Contributor Author

cpcloud commented Sep 29, 2025

/ok to test

@cpcloud cpcloud requested a review from rwgk September 29, 2025 19:56
@cpcloud cpcloud enabled auto-merge (squash) September 29, 2025 20:03
Copy link
Copy Markdown
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

@cpcloud cpcloud merged commit a090753 into NVIDIA:main Sep 29, 2025
70 checks passed
@github-actions
Copy link
Copy Markdown

Doc Preview CI
Preview removed because the pull request was closed or merged.

@leofang
Copy link
Copy Markdown
Member

leofang commented Sep 30, 2025

While I complained about this change being a bit disruptive to open PRs, I do find the new linter runs a lot faster than the raw Bandit, so thanks a lot @cpcloud 🙂

@leofang leofang added enhancement Any code-related improvements support All things related to the project that can't be categorized labels Oct 9, 2025
@leofang leofang added this to the cuda.core beta 7 milestone Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Any code-related improvements support All things related to the project that can't be categorized

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants