Skip to content

Add ruff to pre-commit - #581

Merged
erikwa merged 7 commits into
olofk:mainfrom
erikwa:add-pre-commit-ruff
Nov 16, 2026
Merged

erikwa merged 7 commits into
olofk:mainfrom
erikwa:add-pre-commit-ruff

Conversation

@erikwa

@erikwa erikwa commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Adds a ruff check hook to pre-commit and fixes everything it reports. The rules are ruff's classic defaults (E4, E7, E9, F) plus isort (I) and pyupgrade (UP). They are listed explicitly in pyproject.toml so that a ruff upgrade that changes its defaults doesn't change ours.

Ruff surfaced five existing bugs in vcs.py, tools/xcelium.py, design_compiler.py, openfpga.py and scripts/el_docker. Fixing them changes behavior, so they are marked with FIXME comments and left for separate PRs.

Testing: pre-commit run -a is clean and all 239 tests pass locally on Python 3.14.

Enable ruff's classic default rules (E4, E7, E9, F) plus import sorting
(I) and syntax upgrades (UP).
Ruff removed the sys.version_info branches for Python < 3.8, which
left both subprocess_run_3_9 helpers unused. They were already broken
(TimeoutExpired was never imported), so remove them along with the
msvcrt/_mswindows probe that only they used.

Also convert the remaining "# type: Dict[...]" comments to annotations
so the deprecated typing.Dict/List imports can go.
Hand fixes for what ruff cannot fix safely:

- type(x) == T -> type(x) is T, == None -> is None
- bare except -> except OSError/Exception
- drop unused locals, a duplicated "generic" dict key and two
  no-op .format() calls
- move stray module-level imports to the top
- rename ambiguous `l` loop variables

Add FIXME comments for five existing bugs that ruff surfaced, in
vcs.py, tools/xcelium.py, design_compiler.py, openfpga.py and
scripts/el_docker, to be fixed separately.
Test modules imported make_edalize_test, tool_fixture and flow_fixture
and then took them as parameters of the same name, which ruff reports
as unused (F401) and redefined (F811). Register the fixture modules
with pytest_plugins in tests/conftest.py and drop the imports.
This includes the extensionless scripts in tests/mock_commands, which
the ruff pre-commit hook also checks.

The imports in test_plugin.py are what the test checks, so they keep a
noqa. The vunit mock re-exports VUnit with a redundant alias.
@erikwa
erikwa merged commit 1de9dbe into olofk:main Nov 16, 2026
7 checks passed
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.

1 participant