Skip to content

chore: use ruff to lint and format files#3779

Draft
aignas wants to merge 1 commit into
mainfrom
aignas.refactor.pre-commit-use-ruff
Draft

chore: use ruff to lint and format files#3779
aignas wants to merge 1 commit into
mainfrom
aignas.refactor.pre-commit-use-ruff

Conversation

@aignas
Copy link
Copy Markdown
Collaborator

@aignas aignas commented May 16, 2026

There have been a few attempts at doing these, but the efforts are
stale. Since ruff is very popular these days and it is only a single
binary and is fast, let's use that.

From now on we will be able to maintain the files better, because we
have a CI step testing the compliance.

Closes #3073

There have been a few attempts at doing these, but the efforts are
stale. Since `ruff` is very popular these days and it is only a single
binary and is fast, let's use that.

From now on we will be able to maintain the files better, because we
have a CI step testing the compliance.

Closes #3073
Comment on lines +18 to +26
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install ruff
run: pip install ruff==0.15.13
- name: Run ruff check
run: ruff check --output-format=github
- name: Run ruff format check
run: ruff format --check
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request replaces isort and black with ruff for linting and formatting across the repository, leading to extensive automated changes in imports and code style. While the transition modernizes the project's tooling, the automated cleanup removed several imports required for tests to function correctly, specifically in system_python_nodeps_test.py, repl_test.py, and verify_files_test.py. The reviewer also identified a version typo in the pre-commit configuration and recommended lowering the target-version in ruff.toml to maintain support for older Python versions.

@@ -8,4 +8,3 @@
# Verify a C-implemented module can be imported.
# Socket isn't implement in C, but requires `_socket`,
# which is implemented in C
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The import of socket was removed by the automated cleanup, but it is required for this test to verify that C-implemented modules can be imported. Since this file is already included in per-file-ignores for F401 in ruff.toml, the import should be restored.

Suggested change
# which is implemented in C
# which is implemented in C
import socket

Comment thread tests/repl/repl_test.py
"""Validates that we cannot import helper/test_module.py since it's not a direct dep."""
with self.assertRaises(ModuleNotFoundError):
import test_module
pass
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The import was replaced with pass, which will cause this test to fail because assertRaises expects an exception to be raised. The import should be restored with a # noqa: F401 comment to prevent Ruff from removing it again.

Suggested change
pass
import test_module # noqa: F401

import somepkg.a
import somepkg.subpkg
import somepkg.subpkg.b
pass
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

These imports were removed by the automated cleanup, making the test useless. They should be restored to verify that the packages are indeed importable. Adding # noqa: F401 will prevent them from being removed in future linting runs.

Suggested change
pass
import somepkg # noqa: F401
import somepkg.a # noqa: F401
import somepkg.subpkg # noqa: F401
import somepkg.subpkg.b # noqa: F401

Comment thread .pre-commit-config.yaml
Comment thread ruff.toml
@@ -0,0 +1,30 @@
line-length = 100
target-version = "py313"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Setting target-version to py313 indicates that the project only supports Python 3.13 and newer. This may cause Ruff to suggest or enforce syntax that is incompatible with older Python versions. It is recommended to set this to the minimum Python version supported by the project (e.g., py38 or py39).

Suggested change
target-version = "py313"
target-version = "py38"

@aignas aignas marked this pull request as draft May 16, 2026 06:00
Copy link
Copy Markdown
Collaborator

@dougthor42 dougthor42 left a comment

Choose a reason for hiding this comment

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

Most of the AI comments are actually decent. One wasn't.

+2 when those are addressed.

Comment thread .pre-commit-config.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants