Skip to content

Use newer ruff style #2031

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 1 commit into from
May 30, 2025
Merged

Conversation

EliahKagan
Copy link
Member

@EliahKagan EliahKagan commented May 30, 2025

This updates ruff in .pre-commit-config.yaml from 0.6.0 to 0.11.12, changes its id from the legacy ruff alias to ruff-check (which is better distinguished from ruff-format, which we also have a hook for), and applies the few style changes it newly recommends throughout the code. The style changes seem to make things slightly clearer overall.

This also updates some other pre-commit hooks, but those don't require any changes to the code.

Currently the ruff dependency in requirements-dev.txt doesn't specify a version, so no change is needed there. This update may be seen as bringing the pre-commit version in line with what users will usually have locally with pip install -e ".[test]".

The pre-commit hooks are how linting is currently done on CI, so this is updating ruff for CI. That's the most significant effect of this change. (pre-commit is run for linting on CI probably much more often than it is used locally, to manage pre-commit hooks or otherwise, in GitPython development.)


This works locally and on CI, but I'll still wait for all checks to pass before merging.

@EliahKagan EliahKagan marked this pull request as ready for review May 30, 2025 17:06
This updates `ruff` in `.pre-commit-config.yaml` from 0.6.0 to
0.11.12, changes its `id` from the legacy `ruff` alias to
`ruff-check` (which is better distinguished from `ruff-format`,
which we also have a hook for), and applies the few style changes
it newly recommends throughout the code. The style changes seem to
make things slightly clearer overall.

This also updates some other pre-commit hooks, but those don't
require any changes to the code.

Currently the `ruff` dependency in `requirements-dev.txt` doesn't
specify a version, so no change is needed there. This update may
be seen as bringing the `pre-commit` version in line with what
users will usually have locally with `pip install -e ".[test]"`.

The `pre-commit` hooks are how linting is currently done on CI, so
this is updating `ruff` for CI. That's the most significant effect
of this change. (`pre-commit` is run for linting on CI probably
much more often than it is used locally, to manage pre-commit
hooks or otherwise, in GitPython development.)
@EliahKagan EliahKagan merged commit 2d662cc into gitpython-developers:main May 30, 2025
25 checks passed
@EliahKagan EliahKagan deleted the newer-ruff branch May 30, 2025 18:20
EliahKagan added a commit to EliahKagan/GitPython that referenced this pull request Jun 8, 2025
This resolves two warnings about Ruff configuration, by:

- No longer setting `ignore-init-module-imports = true` explicitly,
  which was deprecated since `ruff` 0.4.4. We primarily use `ruff`
  via `pre-commit`, for which this deprecation has applied since we
  upgraded the version in `.pre-commit-config.yaml` from 0.4.3 to
  0.6.0 in d1582d1 (gitpython-developers#1953).

  We continue to list `F401` ("Module imported but unused") as not
  automatically fixable, to avoid inadvertently removing imports
  that may be needed.

  See also:
  https://docs.astral.sh/ruff/settings/#lint_ignore-init-module-imports

- Rename the rule `TCH004` to `TC004`, since `TCH004` is the old
  name that may eventually be removed and that is deprecated since
  0.8.0. We upgraded `ruff` in `.pre-commit-config.yml` again in
  b7ce712 (gitpython-developers#2031), from 0.6.0 to 0.11.12, at which point this
  deprecation applied.

  See also https://astral.sh/blog/ruff-v0.8.0.

These changes make those configuration-related warnings go away,
and no new diagnostics (errors/warnings) are produced when running
`ruff check` or `pre-commit --all-files`. No F401-related
diagnostics are triggered when testing with explicit
`ignore-init-module-imports = false`, in preview mode or otherwise.

This commit also adds the version lower bound `>=0.8` for `ruff` in
`requirements-dev.txt`. (That file is rarely used, as noted in
a8a73ff (gitpython-developers#1871), but as long as we have it, there may be a benefit
to excluding dependency versions for which our configuration is no
longer compatible.)
EliahKagan added a commit to EliahKagan/GitPython that referenced this pull request Jun 8, 2025
This resolves two warnings about Ruff configuration, by:

- No longer setting `ignore-init-module-imports = true` explicitly,
  which was deprecated since `ruff` 0.4.4. We primarily use `ruff`
  via `pre-commit`, for which this deprecation has applied since we
  upgraded the version in `.pre-commit-config.yaml` from 0.4.3 to
  0.6.0 in d1582d1 (gitpython-developers#1953).

  We continue to list `F401` ("Module imported but unused") as not
  automatically fixable, to avoid inadvertently removing imports
  that may be needed.

  See also:
  https://docs.astral.sh/ruff/settings/#lint_ignore-init-module-imports

- Rename the rule `TCH004` to `TC004`, since `TCH004` is the old
  name that may eventually be removed and that is deprecated since
  0.8.0. We upgraded `ruff` in `.pre-commit-config.yml` again in
  b7ce712 (gitpython-developers#2031), from 0.6.0 to 0.11.12, at which point this
  deprecation applied.

  See also https://astral.sh/blog/ruff-v0.8.0.

These changes make those configuration-related warnings go away,
and no new diagnostics (errors/warnings) are produced when running
`ruff check` or `pre-commit run --all-files`. No F401-related
diagnostics are triggered when testing with explicit
`ignore-init-module-imports = false`, in preview mode or otherwise.

In addition, this commit makes two changes that are not needed to
resolve warnings:

- Stop excluding `E203` ("Whitespace before ':'"). That diagnostic
  is no longer failing with the current code here in the current
  version of `ruff`, and code changes that would cause it to fail
  would likely be accidentally mis-st

- Add the version lower bound `>=0.8` for `ruff` in
  `requirements-dev.txt`. That file is rarely used, as noted in
  a8a73ff (gitpython-developers#1871), but as long as we have it, there may be a
  benefit to excluding dependency versions for which our
  configuration is no longer compatible. This is the only change in
  this commit outside of `pyproject.toml`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant