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

Enable many ruff checks #476

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from

Commits on Dec 2, 2024

  1. Add pre-commit-workflow

    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    efa8b48 View commit details
    Browse the repository at this point in the history
  2. Fix files to comply with pre-commit

    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    4151c63 View commit details
    Browse the repository at this point in the history
  3. Update lint, format checks in tox and cirrus files

    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    eef0489 View commit details
    Browse the repository at this point in the history
  4. Fix Pycodestyle E722: bare-except

    Catching BaseException can make it hard to interrupt the program
    (e.g., with Ctrl-C) and can disguise other problems.
    
    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    24b61cd View commit details
    Browse the repository at this point in the history
  5. Fix Pycodestyle E741: ambiguous-variable-name

    Checks for the use of the characters 'l', 'O', or 'I' as variable names.
    
    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    b68959f View commit details
    Browse the repository at this point in the history
  6. Fix Pycodestyle E402, Pyflakes F401 and Bandit S101

    F401: unused-import
    
    E402: module-import-not-at-top-of-file
    
    S101: assert
    
    Assertions are removed when Python is run with optimization requested
    (i.e., when the -O flag is present), which is a common practice in
     production environments. As such, assertions should not be used for
    runtime validation of user input or to enforce interface constraints.
    
    Signed-off-by: Nicola Sella <[email protected]>
    
    Unused import
    
    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    78b7719 View commit details
    Browse the repository at this point in the history
  7. Fix Pyflakes F841: unused-variable

    Check for unused variables. Unused variables should be prefixed with '_'
    
    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    0c44357 View commit details
    Browse the repository at this point in the history
  8. Fix Pylint PLW2901: redefined-loop-name

    More on why it is bad here:
    https://docs.astral.sh/ruff/rules/redefined-loop-name/
    
    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    ae96ee4 View commit details
    Browse the repository at this point in the history
  9. Add comments in ruff.toml

    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    cd9917d View commit details
    Browse the repository at this point in the history
  10. Fix Pycodestyle E501: line-too-long

    This is a quality of life improvement and it should be backward
    compatible with our previous set line-length
    
    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    af4a128 View commit details
    Browse the repository at this point in the history
  11. Fix Pyupgrades

    Fix sys.version_info comparisons and drop unsupported python code
    
    Furthermore, addresses UP008: super-call-with-parameters
    
    Super is not called with parameters anymore when the first argument is
    __class__ and the second argument is equivalent to the first argument of
    the enclosing method
    
    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    f08b4af View commit details
    Browse the repository at this point in the history
  12. Fix Bugbear B028: no-explicit-stacklevel

    It is recommended to use 2 or more to give the caller more context about
    warning
    
    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    9adc703 View commit details
    Browse the repository at this point in the history
  13. Fix Bugbear B024

    B024: abstract-base-class-without-abstract-method
    PodmanResource is not an abstract class and the ABC inheritance should be removed
    
    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    df3ea3e View commit details
    Browse the repository at this point in the history
  14. Enable Bugbear Checks

    Bugbear checks usually check for design problems within the code.
    
    https://pypi.org/project/flake8-bugbear/
    
    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    6ef117c View commit details
    Browse the repository at this point in the history
  15. Suppress Bandit S108: hardcoded-temp-file

    This could be an exception and should be checked in the future but it is
    suppressed at the moment.
    
    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    ed52f0c View commit details
    Browse the repository at this point in the history
  16. Suppress Bandit S603

    S603: subprocess-without-shell-equals-true
    
    This could be an exception or a false positive and since it's used on
    one single piece of code it is ok to ignore from now.
    
    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    5f162e1 View commit details
    Browse the repository at this point in the history
  17. Enable Flake Bandit checks

    Bandit provides security checks and good practices suggestions for the
    codebase.
    
    https://pypi.org/project/flake8-bandit/
    
    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    52a135a View commit details
    Browse the repository at this point in the history
  18. Update Ruff version

    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    1655b1a View commit details
    Browse the repository at this point in the history
  19. Fix Code based on ruff 0.3->0.8.1

    Fix errors for tyope annotation for list, dict, type and tuple
    
    Example:
    UP006: Use `list` instead of `List` for type annotation
    
    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    1dcce71 View commit details
    Browse the repository at this point in the history
  20. Remove code that is never executed

    Python Version is already set to be < 3.9 so this code will never run
    
    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    dd6de6a View commit details
    Browse the repository at this point in the history
  21. Remove pylint bare-except comment

    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    a49e497 View commit details
    Browse the repository at this point in the history
  22. Disambiguate shadowed builtins without API break

    This suppresses A003 for `list` builtin.
    
    `typing.List`, `typing.Dict`, `typing.Tuple` and `typing.Type` are
    deprecated. Removing these annotations breaks the calls to `list` when
    they are done within the same class scope, which makes them ambiguous.
    
    Typed returns `list` resolve to the function `list` defined in the class,
    shadowing the builtin function. This change is not great but a proper
    one would require changing the name of the class function `list` and
    breaking the API to be fixed.
    
    Example of where it breaks:
    
    podman/domains/images_manager.py
    
    class ImagesManager(...):
    
        def list(...):
            ...
    
        def pull(
            self,
            ...
            ) -> Image | list[Image], [[str]]:
            ...
    
    Here, the typed annotation of `pull` would resolve to the `list` method,
    rather than the builtin.
    
    Signed-off-by: Nicola Sella <[email protected]>
    inknos committed Dec 2, 2024
    Configuration menu
    Copy the full SHA
    a151b12 View commit details
    Browse the repository at this point in the history