chore: adopt ruff as the linter, replace flake8#2511
Conversation
- Replace flake8 with ruff (pinned 0.15.20) in the dev group and enable the ruff pre-commit hook; drop the now-redundant isort hook (ruff sorts imports). The existing pre-commit CI workflow now actually enforces linting, which the configured-but-unused ruff never did. - Apply ruff's safe autofixes: remove unused imports (F401), collapse f-strings without placeholders (F541), sort imports (I001) — 302 fixes across 72 files, tests still green. - Defer pre-existing violations (E501, bare-except, bugbear rules, etc.) via an explicit ignore list with a TODO to burn it down, so ruff runs green on adoption without a mass-churn reformat. Scope F821 to the similar-issue tool's lazy optional imports. - Update AGENTS.md to run `ruff check` instead of flake8. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ADg72cCmirPo9W3E74Htyk
PR Summary by QodoAdopt Ruff as enforced linter (replace flake8) and apply safe autofixes
AI Description
Diagram
High-Level Assessment
Files changed (74)
|
Code Review by Qodo
1. #tomllib violates ruff E265
|
| @@ -1,5 +1,5 @@ | |||
| import tomllib #tomllib should be used instead of Py toml for Python 3.11+ | |||
There was a problem hiding this comment.
1. #tomllib violates ruff e265 📘 Rule violation ⚙ Maintainability
The inline comment #tomllib ... lacks a space after #, which violates Ruff/pycodestyle comment formatting and will fail linting when Ruff is enforced. This breaks the requirement that Python changes conform to the repository’s Ruff configuration.
Agent Prompt
## Issue description
`pr_agent/custom_merge_loader.py` has an inline comment that starts with `#tomllib` (no space after `#`), which violates Ruff's pycodestyle comment formatting (e.g., E265).
## Issue Context
This PR enables/enforces Ruff in CI via pre-commit, so new Ruff violations will cause PR checks to fail.
## Fix Focus Areas
- pr_agent/custom_merge_loader.py[1-1]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| import pandas as pd | ||
| import pinecone | ||
| from pinecone_datasets import Dataset, DatasetMetadata | ||
| except: | ||
| raise Exception("Please install 'pinecone' and 'pinecone_datasets' to use pinecone as vectordb") |
There was a problem hiding this comment.
2. Missing vectordb imports 🐞 Bug ≡ Correctness
PRSimilarIssue removed the Pinecone/LanceDB dependency imports (pandas, pinecone_datasets) but still uses pd, Dataset, and DatasetMetadata later, which will raise NameError at runtime when those vectordb modes are selected. Ruff won't catch this because the file is now exempted from F821 undefined-name checks.
Agent Prompt
## Issue description
`pr_agent/tools/pr_similar_issue.py` now imports only `pinecone` in the Pinecone init path, but later code paths still reference `pd` (pandas) and `Dataset`/`DatasetMetadata` (from `pinecone_datasets`). This causes runtime `NameError` when `pr_similar_issue.vectordb` is set to `pinecone` or `lancedb`.
## Issue Context
- The Pinecone path calls `_update_index_with_issues()`, which uses `pd.DataFrame`, `DatasetMetadata.empty()`, and `Dataset.from_pandas(...)`.
- The LanceDB path calls `_update_table_with_issues()`, which also uses `pd.DataFrame`.
- `pyproject.toml` adds a per-file ignore for `F821` on this file, so ruff will not flag the undefined names.
## Fix Focus Areas
- pr_agent/tools/pr_similar_issue.py[36-40]
- pr_agent/tools/pr_similar_issue.py[397-489]
- pr_agent/tools/pr_similar_issue.py[492-580]
- pyproject.toml[168-173]
## Suggested fix
1. Add **local (lazy) imports** in the functions that actually use these optional deps:
- At the top of `_update_index_with_issues`: `import pandas as pd` and `from pinecone_datasets import Dataset, DatasetMetadata` (wrap in try/except and raise a clear "install X" error if missing).
- At the top of `_update_table_with_issues`: `import pandas as pd` (similarly guarded).
2. Optionally tighten/adjust the `F821` per-file ignore after the imports are fixed, so future undefined-name regressions aren’t hidden.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Stacked on the uv migration (#2509). Base is
feature/uv-migrationso this diff shows only the ruff changes; retarget tomainonce #2509 merges.What
Consolidates linting on ruff and, crucially, makes it enforced — ruff was already configured in
pyproject.tomlbut never run in CI.flake8withruff(pinned0.15.20) in the dev group; enable the ruff pre-commit hook and drop the now-redundant isort hook (ruff sorts imports). The existingpre-commit.ymlworkflow now enforces linting on every PR.GiteaProviderimport.lint.ignorelist with a TODO to burn it down, so ruff runs green on adoption without a mass-churn reformat. F821 is scoped topr_similar_issue.py(its optional deps are imported lazily).AGENTS.mdto runruff checkinstead of flake8.Deliberately NOT included
ruff format(repo-wide formatting) — that's a large diff best done as its own PR plus a.git-blame-ignore-revsentry.Verification
ruff check→ All checks passed; ruff pre-commit hook passes.PYTHONPATH=. uv run pytest tests/unittest→ 1245 passed (autofixes broke nothing).Follow-up debt (flagged, not fixed here)
F811— two real redefinitions worth a look: a shadowedhandle_github_webhooksinbitbucket_app.py:311and a re-importedRequestinazuredevops_server_webhook.py:18.lint.ignorelist is the debt ledger — each entry is a rule to clean up and re-enable.🤖 Generated with Claude Code