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

Use ruff as linter in pre-commit and GH autotest #6538

Closed
rdimaio opened this issue Mar 7, 2024 · 0 comments
Closed

Use ruff as linter in pre-commit and GH autotest #6538

rdimaio opened this issue Mar 7, 2024 · 0 comments
Assignees
Milestone

Comments

@rdimaio
Copy link
Contributor

rdimaio commented Mar 7, 2024

ruff is a Python linter that seems to be very widely used, fast and configurable. It replaces flake8, isort, and other tools.

I think it might be worth adding ruff in the pre-commit hook (https://github.com/astral-sh/ruff-pre-commit), instead of isort (#6532), and configuring it to our needs.

Additionally, in the GH autotest workflow (https://github.com/rucio/rucio/blob/master/.github/workflows/autotest.yml), we could replace add_header, python_annotations and python_pyright with either pre-commit/action (https://github.com/pre-commit/action?tab=readme-ov-file) or https://pre-commit.ci/.

  • Reasons for this:
    • Avoid code duplication between checks written in the precommit config and in autotest.yml - we can just point autotest.yml to run the checks in the precommit config, keeping them "in sync"
    • It should be quicker, as it should only run on files changed (and eventual imports followed by the type checker)
@rdimaio rdimaio self-assigned this Mar 18, 2024
rdimaio added a commit to rdimaio/rucio that referenced this issue Mar 18, 2024
rdimaio added a commit to rdimaio/rucio that referenced this issue Mar 18, 2024
Adding Ruff to both the pre-commit script
(with --fix passed, thus sorting imports automatically)
and to GH autotest (checking only).
Ruff is currently only configured to check for import sorting.
Other linting functions (flake8, pyupgrade) will be added progressively.
rdimaio added a commit to rdimaio/rucio that referenced this issue Mar 18, 2024
rdimaio added a commit to rdimaio/rucio that referenced this issue Mar 18, 2024
rdimaio added a commit to rdimaio/rucio that referenced this issue Mar 18, 2024
Since Python 3, all classes inherit from object by default,
so object can be omitted from the list of base classes.

See also:
- https://docs.astral.sh/ruff/rules/useless-object-inheritance/
- https://peps.python.org/pep-3115/
rdimaio added a commit to rdimaio/rucio that referenced this issue Mar 18, 2024
rdimaio added a commit to rdimaio/rucio that referenced this issue Mar 18, 2024
rdimaio added a commit to rdimaio/rucio that referenced this issue Mar 18, 2024
UTF-8 is the default encoding in Python,
so there is no need to call encode when UTF-8 is the desired encoding.
Instead, use a bytes literal.

See also:
- https://docs.astral.sh/ruff/rules/unnecessary-encode-utf8/
rdimaio added a commit to rdimaio/rucio that referenced this issue Mar 18, 2024
Pyupgrade is a linter to check for deprecated Python syntax.
This commit configures ruff to perform pyupgrade linting.
In the ignore list, I added some pyupgrade error codes (UP*) for the
moment.
These must either be fixed manually, or might be controversial in some
way, so we can consider them at a later point.
rdimaio added a commit to rdimaio/rucio that referenced this issue Mar 18, 2024
rdimaio added a commit to rdimaio/rucio that referenced this issue Mar 19, 2024
rdimaio added a commit to rdimaio/rucio that referenced this issue Mar 19, 2024
Adding Ruff to both the pre-commit script
(with --fix passed, thus sorting imports automatically)
and to GH autotest (checking only).
Ruff is currently only configured to check for import sorting.
Other linting functions (flake8, pyupgrade) will be added progressively.
rdimaio added a commit to rdimaio/rucio that referenced this issue Mar 19, 2024
rdimaio added a commit to rdimaio/rucio that referenced this issue Mar 19, 2024
Adding Ruff to both the pre-commit script
(with --fix passed, thus sorting imports automatically)
and to GH autotest (checking only).
Ruff is currently only configured to check for import sorting.
Other linting functions (flake8, pyupgrade) will be added progressively.
rdimaio added a commit to rdimaio/rucio that referenced this issue Mar 19, 2024
rdimaio added a commit to rdimaio/rucio that referenced this issue Mar 19, 2024
Adding Ruff to both the pre-commit script
(with --fix passed, thus sorting imports automatically)
and to GH autotest (checking only).
Ruff is currently only configured to check for import sorting.
Other linting functions (flake8, pyupgrade) will be added progressively.
bari12 pushed a commit that referenced this issue Mar 20, 2024
bari12 pushed a commit that referenced this issue Mar 20, 2024
Adding Ruff to both the pre-commit script
(with --fix passed, thus sorting imports automatically)
and to GH autotest (checking only).
Ruff is currently only configured to check for import sorting.
Other linting functions (flake8, pyupgrade) will be added progressively.
bari12 pushed a commit that referenced this issue Mar 20, 2024
Adding Ruff to both the pre-commit script
(with --fix passed, thus sorting imports automatically)
and to GH autotest (checking only).
Ruff is currently only configured to check for import sorting.
Other linting functions (flake8, pyupgrade) will be added progressively.
bari12 pushed a commit that referenced this issue Mar 20, 2024
@bari12 bari12 changed the title Consider using ruff as linter in pre-commit and GH autotest USe ruff as linter in pre-commit and GH autotest Mar 20, 2024
@bari12 bari12 changed the title USe ruff as linter in pre-commit and GH autotest Use ruff as linter in pre-commit and GH autotest Mar 20, 2024
@bari12 bari12 added this to the 34.1.0 milestone Mar 20, 2024
bari12 pushed a commit that referenced this issue Mar 21, 2024
…6538

rucio is detected as a third-party dependency by default
(likely has to do with the project structure or __init__ files).
This change configures isort to treat rucio as a first-party dependency,
and re-formats the files.
bari12 pushed a commit that referenced this issue Mar 21, 2024
bari12 pushed a commit that referenced this issue Mar 21, 2024
Since Python 3, all classes inherit from object by default,
so object can be omitted from the list of base classes.

See also:
- https://docs.astral.sh/ruff/rules/useless-object-inheritance/
- https://peps.python.org/pep-3115/
bari12 pushed a commit that referenced this issue Mar 21, 2024
bari12 pushed a commit that referenced this issue Mar 21, 2024
bari12 pushed a commit that referenced this issue Mar 21, 2024
UTF-8 is the default encoding in Python,
so there is no need to call encode when UTF-8 is the desired encoding.
Instead, use a bytes literal.

See also:
- https://docs.astral.sh/ruff/rules/unnecessary-encode-utf8/
bari12 pushed a commit that referenced this issue Mar 21, 2024
Pyupgrade is a linter to check for deprecated Python syntax.
This commit configures ruff to perform pyupgrade linting.
In the ignore list, I added some pyupgrade error codes (UP*) for the
moment.
These must either be fixed manually, or might be controversial in some
way, so we can consider them at a later point.
bari12 pushed a commit that referenced this issue Mar 21, 2024
…6538

rucio is detected as a third-party dependency by default
(likely has to do with the project structure or __init__ files).
This change configures isort to treat rucio as a first-party dependency,
and re-formats the files.
@bari12 bari12 closed this as completed Apr 2, 2024
rdimaio added a commit to rdimaio/rucio that referenced this issue Apr 2, 2024
voetberg pushed a commit to voetberg/rucio that referenced this issue Apr 15, 2024
voetberg pushed a commit to voetberg/rucio that referenced this issue Apr 15, 2024
Adding Ruff to both the pre-commit script
(with --fix passed, thus sorting imports automatically)
and to GH autotest (checking only).
Ruff is currently only configured to check for import sorting.
Other linting functions (flake8, pyupgrade) will be added progressively.
voetberg pushed a commit to voetberg/rucio that referenced this issue Apr 15, 2024
voetberg pushed a commit to voetberg/rucio that referenced this issue Apr 15, 2024
voetberg pushed a commit to voetberg/rucio that referenced this issue Apr 15, 2024
Since Python 3, all classes inherit from object by default,
so object can be omitted from the list of base classes.

See also:
- https://docs.astral.sh/ruff/rules/useless-object-inheritance/
- https://peps.python.org/pep-3115/
voetberg pushed a commit to voetberg/rucio that referenced this issue Apr 15, 2024
voetberg pushed a commit to voetberg/rucio that referenced this issue Apr 15, 2024
voetberg pushed a commit to voetberg/rucio that referenced this issue Apr 15, 2024
UTF-8 is the default encoding in Python,
so there is no need to call encode when UTF-8 is the desired encoding.
Instead, use a bytes literal.

See also:
- https://docs.astral.sh/ruff/rules/unnecessary-encode-utf8/
voetberg pushed a commit to voetberg/rucio that referenced this issue Apr 15, 2024
Pyupgrade is a linter to check for deprecated Python syntax.
This commit configures ruff to perform pyupgrade linting.
In the ignore list, I added some pyupgrade error codes (UP*) for the
moment.
These must either be fixed manually, or might be controversial in some
way, so we can consider them at a later point.
voetberg pushed a commit to voetberg/rucio that referenced this issue Apr 15, 2024
voetberg pushed a commit to voetberg/rucio that referenced this issue Apr 15, 2024
…ucio#6538

rucio is detected as a third-party dependency by default
(likely has to do with the project structure or __init__ files).
This change configures isort to treat rucio as a first-party dependency,
and re-formats the files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants