From 5bc10a06a571f4b4e110577d830b67656a46638a Mon Sep 17 00:00:00 2001 From: "erwan.viollet" Date: Tue, 28 Jul 2026 10:03:47 +0000 Subject: [PATCH] chore(lint): consolidate lint scripts and tidy ruff config 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. --- .github/workflows/ci.yml | 7 ++----- .pre-commit-config.yaml | 8 ++++---- README.md | 6 +++--- pyproject.toml | 10 ++-------- scripts/format | 9 --------- scripts/lint | 10 ---------- scripts/ruff | 37 +++++++++++++++++++++++++++++++++++++ scripts/ruff-common.sh | 17 ----------------- 8 files changed, 48 insertions(+), 56 deletions(-) delete mode 100755 scripts/format delete mode 100755 scripts/lint create mode 100755 scripts/ruff delete mode 100755 scripts/ruff-common.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe68c7c4..ccefcb21 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,11 +30,8 @@ jobs: python-version: "3.11" - name: Install ruff run: pip install --no-cache-dir -r requirements-dev.txt - - name: Run ruff format check - run: ruff format --check . - - name: Run ruff lint check - if: success() || failure() - run: ruff check . + - name: Run ruff (format + lint check) + run: ./scripts/ruff check ddprof: uses: ./.github/workflows/test.yml with: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2aaf487b..a45bd5e3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,11 @@ -# Optional git hooks for Python scenario files (same checks as CI — see scripts/lint). +# Optional git hooks for Python scenario files (same checks as CI — see scripts/ruff). # Setup: pip install -r requirements-dev.txt pre-commit && pre-commit install -# On Datadog laptops with global core.hooksPath, use ./scripts/lint instead of pre-commit install. +# On Datadog laptops with global core.hooksPath, run ./scripts/ruff check manually instead. repos: - repo: local hooks: - id: ruff - name: ruff (scripts/lint) - entry: scripts/lint + name: ruff (scripts/ruff check) + entry: scripts/ruff check language: system types: [python] diff --git a/README.md b/README.md index 5c84ab0c..6de5a444 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,11 @@ pip install -r requirements-dev.txt ``` ```sh -./scripts/lint # check (matches the ci.yml ruff job) -./scripts/format # auto-fix formatting and lint +./scripts/ruff check # what CI runs (format --check + lint) +./scripts/ruff fix # auto-fix formatting and lint in place ``` -Optional git hooks (skip on Datadog laptops that use global `core.hooksPath` — run `./scripts/lint` manually instead): +Optional git hooks (skip on Datadog laptops that use global `core.hooksPath` — run `./scripts/ruff check` manually instead): ```sh pip install pre-commit diff --git a/pyproject.toml b/pyproject.toml index 1e7b0728..eba1c79e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,19 +40,13 @@ select = [ "RUF", # Ruff-specific rules ] ignore = [ - "D203", # one-blank-line-before-class (conflicts with D211) - "D213", # multi-line-summary-second-line (conflicts with D212) "T201", # print statement used "PLR2004", # constant variable ] [tool.ruff.lint.per-file-ignores] -"**/__init__.py" = ["D104"] # missing docstring in public package -"**/test_*.py" = ["S101", "D"] # allow assert in tests, skip docstrings -"**/tests/**/*.py" = ["S101", "D"] # allow assert in tests, skip docstrings - -[tool.ruff.lint.pydocstyle] -convention = "google" +"**/test_*.py" = ["S101"] # allow assert in tests +"**/tests/**/*.py" = ["S101"] # allow assert in tests [tool.ruff.lint.mccabe] max-complexity = 10 diff --git a/scripts/format b/scripts/format deleted file mode 100755 index 13024992..00000000 --- a/scripts/format +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -source "$(dirname "${BASH_SOURCE[0]}")/ruff-common.sh" -ruff_common_setup -ruff_resolve_targets "$@" - -ruff check --fix "${RUFF_TARGETS[@]}" -ruff format "${RUFF_TARGETS[@]}" diff --git a/scripts/lint b/scripts/lint deleted file mode 100755 index 22bd1960..00000000 --- a/scripts/lint +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Matches the ruff job in .github/workflows/ci.yml (see also scripts/format). -source "$(dirname "${BASH_SOURCE[0]}")/ruff-common.sh" -ruff_common_setup -ruff_resolve_targets "$@" - -ruff format --check "${RUFF_TARGETS[@]}" -ruff check "${RUFF_TARGETS[@]}" diff --git a/scripts/ruff b/scripts/ruff new file mode 100755 index 00000000..22cea6ee --- /dev/null +++ b/scripts/ruff @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# Python lint/format for scenario workloads. Uses the ruff pinned in requirements-dev.txt. +# +# scripts/ruff check [paths...] # what CI runs (see .github/workflows/ci.yml) +# scripts/ruff fix [paths...] # auto-fix lint + format in place +# +# With no paths, runs on the whole repo ("."). +set -euo pipefail + +cd "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +if ! command -v ruff >/dev/null 2>&1; then + echo "ruff not found; install with: pip install -r requirements-dev.txt" >&2 + exit 1 +fi + +mode="${1:-check}" +[ $# -gt 0 ] && shift +targets=("$@") +[ ${#targets[@]} -eq 0 ] && targets=(".") + +case "$mode" in + check) + ruff format --check "${targets[@]}" + ruff check "${targets[@]}" + ;; + fix) + # `ruff check --fix` exits non-zero when unfixable lints remain; `|| true` keeps + # `set -e` from aborting before we format. Fix first, format last, so output converges. + ruff check --fix "${targets[@]}" || true + ruff format "${targets[@]}" + ;; + *) + echo "usage: scripts/ruff {check|fix} [paths...]" >&2 + exit 2 + ;; +esac diff --git a/scripts/ruff-common.sh b/scripts/ruff-common.sh deleted file mode 100755 index 5a0be4b5..00000000 --- a/scripts/ruff-common.sh +++ /dev/null @@ -1,17 +0,0 @@ -# Shared setup for scripts/lint and scripts/format. -ruff_common_setup() { - RUFF_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" - cd "$RUFF_ROOT" - - if ! command -v ruff >/dev/null 2>&1; then - echo "ruff not found; install with: pip install -r $RUFF_ROOT/requirements-dev.txt" >&2 - exit 1 - fi -} - -ruff_resolve_targets() { - RUFF_TARGETS=("$@") - if [ "${#RUFF_TARGETS[@]}" -eq 0 ]; then - RUFF_TARGETS=(".") - fi -}