Skip to content

feat: ban pytest imports in source code and centralize ruff config#1061

Open
skrawani wants to merge 6 commits intoqdrant:devfrom
skrawani:958-ban-pytest-import
Open

feat: ban pytest imports in source code and centralize ruff config#1061
skrawani wants to merge 6 commits intoqdrant:devfrom
skrawani:958-ban-pytest-import

Conversation

@skrawani
Copy link
Copy Markdown

@skrawani skrawani commented Aug 14, 2025

  • Add TID251 rule to prevent pytest imports outside tests/
  • Move ruff settings to pyproject.toml for consistency

All Submissions:

  • Contributions should target the dev branch. Did you create your branch from dev?
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you installed pre-commit with pip3 install pre-commit and set up hooks with pre-commit install?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

- Add TID251 rule to prevent pytest imports outside tests/
- Move ruff settings to pyproject.toml for consistency
@netlify
Copy link
Copy Markdown

netlify Bot commented Aug 14, 2025

Deploy Preview for poetic-froyo-8baba7 ready!

Name Link
🔨 Latest commit f1321e9
🔍 Latest deploy log https://app.netlify.com/projects/poetic-froyo-8baba7/deploys/689e542baff3520009366e70
😎 Deploy Preview https://deploy-preview-1061--poetic-froyo-8baba7.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 14, 2025

📝 Walkthrough

Walkthrough

This PR updates configuration only:

  • .pre-commit-config.yaml: Re-enables Ruff and Ruff-format hooks with corrected YAML formatting and types_or; minor style tweaks.
  • pyproject.toml: Adds Ruff configuration (line-length 99, enables TID251, bans pytest in app code, per-file ignore for tests/**).
  • .github/workflows/type-checkers.yml: Indentation adjustment for the mypy step.
  • .github/workflows/ruff-linting.yml: New workflow to run Ruff via Poetry on push/PR to dev/master using Python 3.9, outputs GitHub-formatted results.

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
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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 directly

Top-level exclude here only affects pre-commit. If contributors run ruff/ruff-format directly, those directories will still be linted. Recommend mirroring this in pyproject.toml via tool.ruff.extend-exclude for 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 3d29466 and 63eb5d5.

📒 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 good

The hooks are correctly configured, and using --fix on Ruff aligns with auto-fix before format. The order (Ruff then ruff-format) is sensible.

Comment thread .pre-commit-config.yaml
# See https://pre-commit.com/hooks.html for more hooks
default_language_version:
python: python3.10
python: python3.10
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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 || true

Length 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_version entry to let pre-commit auto-detect
    • If hooks truly require 3.10, document the requirement in CONTRIBUTING/README instead of hard-pinning
🤖 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.

Comment thread pyproject.toml
Comment on lines +80 to +86
[tool.ruff]
line-length = 99

[tool.ruff.lint]
# TODO: Enable all rules later
select = ["TID251"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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"])
  • 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.

Comment thread pyproject.toml Outdated
@skrawani skrawani marked this pull request as draft August 14, 2025 19:32
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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.

📥 Commits

Reviewing files that changed from the base of the PR and between 63eb5d5 and 95de540.

📒 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.

Comment thread .github/workflows/type-checkers.yml Outdated
Comment on lines +37 to +39
- name: ruff
run: |
poetry run ruff check .
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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=github

Run 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))
PY

Length 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=github

Committable 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.

Comment thread qdrant_client/hybrid/formula.py Outdated
@skrawani
Copy link
Copy Markdown
Author

Resolves #958 by enforcing banned imports.

  • Adds pre-commit with Ruff (TID251) and a CI job to check banned imports in qdrant_client/.
  • Allows pytest imports in tests/** via per-file ignore.
  • Verification: Introducing pytest in source code causes the workflow to fail as expected.
Screenshot 2025-08-15 at 2 32 04 AM

@skrawani skrawani marked this pull request as ready for review August 14, 2025 21:31
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
.github/workflows/ruff-linting.yml (1)

30-32: Nit: remove the extra space before --output-format

Minor 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 95de540 and f1321e9.

📒 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 required

pyproject.toml contains ruff = "0.4.3" under [tool.poetry.group.dev.dependencies], so the workflow's poetry install --only dev + poetry run ruff will work.

  • .github/workflows/ruff-linting.yml (lines 24–32): runs poetry install --only dev and poetry run ruff check .
  • pyproject.toml (lines ~37–44; exact entry at pyproject.toml:43): ruff = "0.4.3"

Comment on lines +20 to +22
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
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.

Comment on lines +24 to +29
- 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ 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-root

This 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.

Suggested change
- 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).

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.

2 participants