feat: ban pytest imports in source code and centralize ruff config#1061
feat: ban pytest imports in source code and centralize ruff config#1061skrawani wants to merge 6 commits intoqdrant:devfrom
Conversation
- Add TID251 rule to prevent pytest imports outside tests/ - Move ruff settings to pyproject.toml for consistency
✅ Deploy Preview for poetic-froyo-8baba7 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
📝 WalkthroughWalkthroughThis PR updates configuration only:
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
.pre-commit-config.yaml (1)
6-6: Mirror pre-commit exclude in Ruff config for parity when running ruff directlyTop-level
excludehere only affects pre-commit. If contributors runruff/ruff-formatdirectly, those directories will still be linted. Recommend mirroring this inpyproject.tomlviatool.ruff.extend-excludefor consistent behavior.Apply in pyproject.toml:
[tool.ruff] line-length = 99 +extend-exclude = ["qdrant_client/grpc", "qdrant_client/http", "qdrant_client/models"]
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these settings in your CodeRabbit configuration.
📒 Files selected for processing (2)
.pre-commit-config.yaml(2 hunks)pyproject.toml(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Redirect rules - poetic-froyo-8baba7
- GitHub Check: Header rules - poetic-froyo-8baba7
- GitHub Check: Pages changed - poetic-froyo-8baba7
🔇 Additional comments (1)
.pre-commit-config.yaml (1)
19-24: Re-enabling Ruff and Ruff-Format via pre-commit looks goodThe hooks are correctly configured, and using
--fixon Ruff aligns with auto-fix before format. The order (Ruff then ruff-format) is sensible.
| # See https://pre-commit.com/hooks.html for more hooks | ||
| default_language_version: | ||
| python: python3.10 | ||
| python: python3.10 |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
Pinning default_language_version to python3.10 can cause dev friction
If a contributor doesn’t have Python 3.10 installed locally, pre-commit will fail to create hook environments. Consider either omitting this (let pre-commit auto-detect), using a more generic python3, or documenting the requirement.
Run to check local impact (no changes performed):
🏁 Script executed:
#!/bin/bash
# Shows which Python binary pre-commit will try to use for hooks on this machine.
python3 --version 2>/dev/null || true
command -v python3.10 2>/dev/null || trueLength of output: 64
Action required: don't pin pre-commit default_language_version to python3.10
I ran the check: python3 → Python 3.11.2; python3.10 not present. With the current setting pre-commit will fail to create hook envs on machines without python3.10.
- File to update:
- .pre-commit-config.yaml (around line 4)
- Current snippet:
python: python3.10
- Suggested fixes (pick one):
- Replace with a generic runtime:
python: python3- Diff:
- python: python3.10 + python: python3
- OR remove the explicit
default_language_versionentry to let pre-commit auto-detect - If hooks truly require 3.10, document the requirement in CONTRIBUTING/README instead of hard-pinning
- Replace with a generic runtime:
🤖 Prompt for AI Agents
In .pre-commit-config.yaml around line 4, the default_language_version is pinned
to python3.10 which causes pre-commit to fail on systems without that
interpreter; update the entry to a generic runtime (replace python3.10 with
python3) or remove the default_language_version line entirely so pre-commit
auto-detects the interpreter; if your hooks actually require Python 3.10, remove
the hard pin and instead document the requirement in CONTRIBUTING/README so
contributors can install the correct interpreter.
| [tool.ruff] | ||
| line-length = 99 | ||
|
|
||
| [tool.ruff.lint] | ||
| # TODO: Enable all rules later | ||
| select = ["TID251"] | ||
|
|
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
Don’t override all Ruff rules with select = ["TID251"]; use extend-select
Setting select = ["TID251"] disables all other lint rules. If the goal is to add TID251 on top of the existing/implicit rule set, switch to extend-select. This avoids unintentionally dropping other checks (e.g., pyflakes/pycodestyle/import rules) the project may rely on.
Proposed change:
[tool.ruff.lint]
-# TODO: Enable all rules later
-select = ["TID251"]
+# Keep existing rules and add TID251 on top.
+extend-select = ["TID251"]Optionally, also mirror pre-commit excludes so CLI runs behave the same:
[tool.ruff]
line-length = 99
+extend-exclude = ["qdrant_client/grpc", "qdrant_client/http", "qdrant_client/models"]To confirm we’re not dropping previously enabled rules, search for any other Ruff config in the repo and for prior select/extend-select usage:
🏁 Script executed:
#!/bin/bash
# Find any other Ruff configuration files.
fd -a 'ruff.toml' -a '.ruff.toml' -a 'pyproject.toml' | sed 's/^/CONFIG: /'
# Show any existing ruff config blocks (outside this file, if any).
rg -n '^\[tool\.ruff(\.|])' -A 5 | sed 's/^/RUFF: /'
# Show any select/extend-select occurrences.
rg -n '^\s*(select|extend-select)\s*=' -A 1 | sed 's/^/SEL: /'Length of output: 1013
Use extend-select instead of select so you don't disable other Ruff rules
select = ["TID251"] replaces the enabled rule set; switch to extend-select to add TID251 on top of the existing/implicit rules.
- Location to change:
- pyproject.toml — lines ~80–86 (current:
select = ["TID251"])
- pyproject.toml — lines ~80–86 (current:
- Verification: repo search found only this Ruff config/select occurrence in pyproject.toml.
Proposed change:
[tool.ruff.lint]
-# TODO: Enable all rules later
-select = ["TID251"]
+# Keep existing rules and add TID251 on top.
+extend-select = ["TID251"]Optional (mirror pre-commit excludes so CLI runs match):
[tool.ruff]
line-length = 99
+extend-exclude = ["qdrant_client/grpc", "qdrant_client/http", "qdrant_client/models"]🤖 Prompt for AI Agents
In pyproject.toml around lines 80 to 86, the Ruff configuration uses select =
["TID251"] which replaces the default/other enabled rules; change this to
extend-select = ["TID251"] so Ruff adds TID251 on top of existing rules instead
of disabling them, i.e. replace the select key with extend-select (keeping the
same list value) so other rules remain active.
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these settings in your CodeRabbit configuration.
📒 Files selected for processing (2)
.github/workflows/type-checkers.yml(1 hunks)qdrant_client/hybrid/formula.py(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Redirect rules - poetic-froyo-8baba7
- GitHub Check: Header rules - poetic-froyo-8baba7
- GitHub Check: Pages changed - poetic-froyo-8baba7
🔇 Additional comments (1)
.github/workflows/type-checkers.yml (1)
31-31: LGTM: mypy step formatting.Indentation-only tweak; no functional change.
| - name: ruff | ||
| run: | | ||
| poetry run ruff check . |
There was a problem hiding this comment.
💡 Verification agent
🧩 Analysis chain
Add Ruff CI step: good addition; improve output formatting and ensure availability.
- Suggest emitting GitHub-annotated output for inline review comments.
- Verify that Ruff is included in Poetry dev dependencies; otherwise this step will fail in CI.
Apply this diff to improve annotations:
- poetry run ruff check .
+ poetry run ruff check . --output-format=githubRun this script to verify Ruff is declared in pyproject.toml (dev deps or any dependency group):
🏁 Script executed:
#!/bin/bash
set -euo pipefail
if [ ! -f pyproject.toml ]; then
echo "pyproject.toml not found at repo root"
exit 1
fi
# Ensure tomli available for Python <3.11
python - <<'PY'
import json
from pathlib import Path
try:
import tomllib # Python 3.11+
except ModuleNotFoundError:
try:
import tomli as tomllib # fallback
except ModuleNotFoundError:
print(json.dumps({"error": "tomllib/tomli not available"}))
raise SystemExit(1)
data = tomllib.loads(Path("pyproject.toml").read_text())
tool = data.get("tool", {})
poetry = tool.get("poetry", {})
locations = []
deps = poetry.get("dependencies", {}) or {}
if "ruff" in deps:
locations.append("tool.poetry.dependencies")
dev_legacy = poetry.get("dev-dependencies", {}) or {}
if "ruff" in dev_legacy:
locations.append("tool.poetry.dev-dependencies")
group = poetry.get("group", {}) or {}
for gname, gdata in group.items():
gdeps = (gdata or {}).get("dependencies", {}) or {}
if "ruff" in gdeps:
locations.append(f"tool.poetry.group.{gname}.dependencies")
print(json.dumps({"ruff_found": bool(locations), "locations": locations}, indent=2))
PYLength of output: 150
Enable Ruff GitHub annotations — ruff present in pyproject.toml
Ruff is declared in tool.poetry.group.dev.dependencies (verified). Apply the workflow change to emit GitHub-annotated output.
- Files to change:
- .github/workflows/type-checkers.yml (around lines 37–39) — update the ruff run command.
- pyproject.toml — ruff already present at tool.poetry.group.dev.dependencies (no change needed).
Apply this diff:
- poetry run ruff check .
+ poetry run ruff check . --output-format=githubCommittable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In .github/workflows/type-checkers.yml around lines 37 to 39, the ruff step runs
"poetry run ruff check ." which doesn’t emit GitHub annotations; update the run
command to use Ruff’s GitHub output format by changing it to run "poetry run
ruff check --format=github ." so lint findings are reported as GitHub
annotations by the workflow.
|
Resolves #958 by enforcing banned imports.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
.github/workflows/ruff-linting.yml (1)
30-32: Nit: remove the extra space before --output-formatMinor formatting nit; no behavioral change.
Apply this diff:
- poetry run ruff check . --output-format=github + poetry run ruff check . --output-format=github
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these settings in your CodeRabbit configuration.
📒 Files selected for processing (3)
.github/workflows/ruff-linting.yml(1 hunks).github/workflows/type-checkers.yml(1 hunks)pyproject.toml(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- .github/workflows/type-checkers.yml
- pyproject.toml
🧰 Additional context used
🪛 actionlint (1.7.7)
.github/workflows/ruff-linting.yml
20-20: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🔇 Additional comments (1)
.github/workflows/ruff-linting.yml (1)
24-32: Ruff is declared in dev dependencies — no change requiredpyproject.toml contains
ruff = "0.4.3"under[tool.poetry.group.dev.dependencies], so the workflow'spoetry install --only dev+poetry run ruffwill work.
- .github/workflows/ruff-linting.yml (lines 24–32): runs
poetry install --only devandpoetry run ruff check .- pyproject.toml (lines ~37–44; exact entry at pyproject.toml:43):
ruff = "0.4.3"
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} |
There was a problem hiding this comment.
Upgrade setup-python action to v5 to satisfy actionlint and current runner requirements
actionlint flags actions/setup-python@v4 as too old. Use v5 to avoid CI failures and keep current with GitHub Actions runners.
Apply this diff:
- - name: Set up Python ${{ matrix.python-version }}
- uses: actions/setup-python@v4
+ - name: Set up Python ${{ matrix.python-version }}
+ uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} |
🧰 Tools
🪛 actionlint (1.7.7)
20-20: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🤖 Prompt for AI Agents
.github/workflows/ruff-linting.yml around lines 20 to 22: the workflow uses
actions/setup-python@v4 which actionlint flags as outdated; update the action
reference to actions/setup-python@v5 (keep the existing with: python-version:
${{ matrix.python-version }} block intact) so the workflow uses the current
major version and satisfies actionlint/runner requirements.
| - name: Install Poetry and lint deps | ||
| run: | | ||
| python -m pip install poetry | ||
| poetry config virtualenvs.create false | ||
| poetry install --no-interaction --no-ansi --only dev | ||
|
|
There was a problem hiding this comment.
🛠️ Refactor suggestion
Install only tooling in an isolated venv; avoid installing the project/root package
Installing only the dev group while still installing the project (default behavior) can slow down the job and potentially fail if project default deps are heavy or require system libs. Keep Poetry’s venv enabled and skip installing the root package for a faster, more robust lint job.
Apply this diff:
- - name: Install Poetry and lint deps
+ - name: Install Poetry and lint deps
run: |
- python -m pip install poetry
- poetry config virtualenvs.create false
- poetry install --no-interaction --no-ansi --only dev
+ python -m pip install --upgrade pip
+ python -m pip install poetry
+ poetry install --no-interaction --no-ansi --only dev --no-rootThis keeps ruff in a Poetry-managed virtualenv and avoids unnecessary dependency resolution of the application itself.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| - name: Install Poetry and lint deps | |
| run: | | |
| python -m pip install poetry | |
| poetry config virtualenvs.create false | |
| poetry install --no-interaction --no-ansi --only dev | |
| - name: Install Poetry and lint deps | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install poetry | |
| poetry install --no-interaction --no-ansi --only dev --no-root |
🤖 Prompt for AI Agents
In .github/workflows/ruff-linting.yml around lines 24 to 29, the workflow
currently disables Poetry virtualenv creation and installs the root package when
installing dev deps; change it to create an isolated venv and skip installing
the project by removing the "poetry config virtualenvs.create false" line and
using "poetry install --no-interaction --no-ansi --only dev --no-root" (so
Poetry manages a venv and only tooling/dev dependencies are installed).

All Submissions:
devbranch. Did you create your branch fromdev?New Feature Submissions:
pre-commitwithpip3 install pre-commitand set up hooks withpre-commit install?Changes to Core Features: