Skip to content

chore(ci): pin ruff and add pre-commit hooks (PROF-15511) - #174

Merged
r1viollet merged 6 commits into
mainfrom
vlad/chore-ruff-pre-commit
Jul 28, 2026
Merged

chore(ci): pin ruff and add pre-commit hooks (PROF-15511)#174
r1viollet merged 6 commits into
mainfrom
vlad/chore-ruff-pre-commit

Conversation

@vlad-scherbich

@vlad-scherbich vlad-scherbich commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Next: #165

Summary

Started implementing pre-commit hooks for automated lints and formatting fixes before the issues hit CI in PR. Cheap prevention of stuck PRs needing CI reruns.

Changes

  • requirements-dev.txt — single pin for ruff==0.15.5 (CI, scripts, install docs)
  • CIpip install -r requirements-dev.txt; ruff format --check + ruff check (unchanged behavior, pinned version)
  • scripts/lint / scripts/format — local wrappers matching CI vs auto-fix; shared setup in scripts/ruff-common.sh
    • Fix before format (ruff check --fixruff format) so one ./scripts/format run converges
  • .pre-commit-config.yaml — optional local hook calling scripts/lint (language: system; no second ruff version pin via astral-sh/ruff-pre-commit)
  • README.md — Python lint setup (pip install -r requirements-dev.txt, scripts, optional pre-commit)
  • Formattingruff format fix in scenarios/python_safe_point_bias_3.11/README.md

Local workflow

pip install -r requirements-dev.txt
./scripts/lint      # check (matches CI)
./scripts/format    # auto-fix

Fixes ruff format --check CI failure (extra blank line in code block).
Pin CI ruff to match pyproject.toml expectations and add a minimal
pre-commit config (ruff-format + ruff --fix) so local runs match CI.
Mirror dd-trace-py's scripts/lint workflow without git hooks — works with Datadog global core.hooksPath. Matches the pinned CI ruff job.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves repo-wide Python linting/formatting consistency by pinning Ruff in CI and adding lightweight contributor tooling (pre-commit + convenience scripts) to reduce local/CI drift.

Changes:

  • Pin ruff==0.15.5 in the GitHub Actions CI workflow.
  • Add .pre-commit-config.yaml with Ruff formatting and autofix hooks.
  • Add scripts/lint and scripts/format helper scripts; apply a small Ruff-format change in a scenario README.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
scripts/lint Adds a local wrapper that runs ruff format --check and ruff check on provided targets.
scripts/format Adds a local wrapper intended to auto-fix via Ruff formatting and lint fixes.
scenarios/python_safe_point_bias_3.11/README.md Applies formatting-only adjustment in an embedded Python snippet.
.pre-commit-config.yaml Introduces optional pre-commit hooks for Ruff formatting and autofix.
.github/workflows/ci.yml Pins the Ruff version installed in CI to avoid drift.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/format Outdated
Comment thread .pre-commit-config.yaml Outdated
ruff check --fix can rewrite imports; formatting last avoids leaving
files unformatted after a single scripts/format or pre-commit run.
- Add requirements-dev.txt as the only ruff version pin
- CI and scripts reference it; local pre-commit hook runs scripts/lint
- Document Python lint setup in README
@vlad-scherbich
vlad-scherbich marked this pull request as ready for review July 27, 2026 22:06
@vlad-scherbich
vlad-scherbich requested a review from a team as a code owner July 27, 2026 22:06
@vlad-scherbich vlad-scherbich changed the title chore(ci): pin ruff and add pre-commit hooks chore(ci): pin ruff and add pre-commit hooks (PROF-15511) Jul 27, 2026

@r1viollet r1viollet left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@r1viollet
r1viollet merged commit 3c98d3b into main Jul 28, 2026
25 checks passed
@r1viollet
r1viollet deleted the vlad/chore-ruff-pre-commit branch July 28, 2026 07:11
r1viollet added a commit that referenced this pull request Jul 28, 2026
Follow-up to #174 based on review feedback:

- Keep the existing ruff ruleset (per review, the strict set is fine).
- Remove only dead config: the D-rule ignores/per-file-ignores and the
  pydocstyle section referenced rules that were never in select, so they
  had no effect. No change to what is actually enforced.
- Collapse scripts/lint + scripts/format + scripts/ruff-common.sh into a
  single 'scripts/ruff {check|fix}'.
- Fix scripts/ruff fix: 'ruff check --fix' exits non-zero on remaining
  unfixable lints, which under 'set -e' aborted before formatting ran,
  leaving files unformatted. Now formatting always runs.
- Point CI, README, and pre-commit at the single script.
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