Skip to content
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

Replace bandit with ruff #93200

Merged
merged 3 commits into from Jun 8, 2023
Merged

Replace bandit with ruff #93200

merged 3 commits into from Jun 8, 2023

Conversation

scop
Copy link
Member

@scop scop commented May 17, 2023

Proposed change

Move from bandit to ruff. Ruff >= 0.0.271 will be needed before this can go in.

Remaining rules:

The following discussion applies to an earlier submission where I proposed a partial move to ruff, with some rules still missing it. Keeping it for historical purposes.


Even though not all rules are yet available in ruff, I suppose consolidating towards it is a good thing. It appears to be doing a better job than bandit for at least some rules; it does not support nosec, and migrating them to supported noqas turned up no things that could be removed. It did flag some additional, valid ones that were missed by bandit.

Removal of these bandit rules brings the time it takes to run it down a bit, too. With B601 and B609 still left there but others removed, the times I see for time pre-commit run bandit --all-files go down from about

real	1m44,239s
user	6m3,650s
sys	0m1,528s

...to roughly

real	1m28,261s
user	5m24,393s
sys	0m1,432s

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @mdegat01, mind taking a look at this pull request as it has been labeled with an integration (influxdb) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of influxdb can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign influxdb Removes the current integration label and assignees on the pull request, add the integration domain after the command.

@home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (recorder) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of recorder can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign recorder Removes the current integration label and assignees on the pull request, add the integration domain after the command.

@home-assistant
Copy link

Hey there @bachya, mind taking a look at this pull request as it has been labeled with an integration (yi) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of yi can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign yi Removes the current integration label and assignees on the pull request, add the integration domain after the command.

@scop scop marked this pull request as draft May 19, 2023 10:07
@scop scop changed the title Use ruff for bandit rules available in it Move from bandit to ruff May 19, 2023
@scop scop changed the title Move from bandit to ruff Replace bandit with ruff Jun 3, 2023
@scop scop mentioned this pull request Jun 8, 2023
20 tasks
scop added 2 commits June 8, 2023 20:53
Only one trivial docstring thing to address.

`keep-runtime-typing` replaced by `UP006` and `UP007` ignores:
https://github.com/astral-sh/ruff/blob/main/BREAKING_CHANGES.md#00268
B325 is not available in ruff, but it has been removed in bandit, too.
@scop scop changed the base branch from dev to scop-upgrade-ruff June 8, 2023 17:53
@scop scop marked this pull request as ready for review June 8, 2023 17:54
@scop scop requested a review from gjohansson-ST as a code owner June 8, 2023 17:54
Base automatically changed from scop-upgrade-ruff to dev June 8, 2023 19:53
Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Super nice! Great contributions upstream for this as well ❤️

../Frenck

@frenck frenck merged commit ca936d0 into dev Jun 8, 2023
52 checks passed
@frenck frenck deleted the scop-bandit-to-ruff branch June 8, 2023 20:46
@github-actions github-actions bot locked and limited conversation to collaborators Jun 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants