From b6cfdadd44c9744057873c71902091b282d3af51 Mon Sep 17 00:00:00 2001 From: Pedro Brochado Date: Mon, 22 Dec 2025 16:50:15 -0300 Subject: [PATCH 1/7] Configure flake8 pre-commit --- .pre-commit-config.yaml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..00ad0c2855 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,29 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + # - id: trailing-whitespace + # - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files +- repo: https://github.com/pycqa/flake8 + rev: 7.3.0 + hooks: + - id: flake8 + args: ["--config", ".flake8"] + language_version: "3.11" +- repo: https://github.com/psf/black + rev: 24.3.0 + hooks: + - id: black + - id: black + args: ["--check", "--diff", "."] + additional_dependencies: ["flake8-black"] +- repo: https://github.com/adrienverge/yamllint + rev: v1.37.1 + hooks: + - id: yamllint + + From ec4d339e2f2703f280773aeb5e7682c968e14245 Mon Sep 17 00:00:00 2001 From: Pedro Brochado Date: Mon, 22 Dec 2025 17:07:26 -0300 Subject: [PATCH 2/7] Configure pre-commit yamllint --- .github/workflows/lint.yml | 2 +- .pre-commit-config.yaml | 38 ++++++++++++++++++++------------------ .yamllint.yaml | 4 ++++ 3 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 .yamllint.yaml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3c44618914..5cf15baf7d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -36,7 +36,7 @@ jobs: - name: "Lint workflow files" run: | - yamllint -s -d '{extends: relaxed, rules: {line-length: disable}}' .github/workflows + yamllint - name: "Verify bump version config" run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 00ad0c2855..429ccac10d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,29 +1,31 @@ # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks repos: -- repo: https://github.com/pre-commit/pre-commit-hooks + - repo: 'https://github.com/pre-commit/pre-commit-hooks' rev: v3.2.0 hooks: - # - id: trailing-whitespace - # - id: end-of-file-fixer - - id: check-yaml - - id: check-added-large-files -- repo: https://github.com/pycqa/flake8 + - id: check-yaml + - id: check-added-large-files + - repo: 'https://github.com/pycqa/flake8' rev: 7.3.0 hooks: - - id: flake8 - args: ["--config", ".flake8"] - language_version: "3.11" -- repo: https://github.com/psf/black + - id: flake8 + args: + - '--config' + - .flake8 + language_version: '3.11' + - repo: 'https://github.com/psf/black' rev: 24.3.0 hooks: - - id: black - - id: black - args: ["--check", "--diff", "."] - additional_dependencies: ["flake8-black"] -- repo: https://github.com/adrienverge/yamllint + - id: black + - id: black + args: + - '--check' + - '--diff' + - . + additional_dependencies: + - flake8-black + - repo: 'https://github.com/adrienverge/yamllint' rev: v1.37.1 hooks: - - id: yamllint - - + - id: yamllint diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 0000000000..7b7fa1b99d --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,4 @@ +extends: relaxed + +rules: + line-length: disable From 3f347526f65a9270e65c3be495f380aa728b8069 Mon Sep 17 00:00:00 2001 From: Pedro Brochado Date: Mon, 22 Dec 2025 17:26:57 -0300 Subject: [PATCH 3/7] Configure pre-commit black --- .pre-commit-config.yaml | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 429ccac10d..09847b6ed1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,21 +10,16 @@ repos: rev: 7.3.0 hooks: - id: flake8 - args: - - '--config' - - .flake8 + args: ["--config", ".flake8"] language_version: '3.11' - repo: 'https://github.com/psf/black' rev: 24.3.0 hooks: - id: black - - id: black - args: - - '--check' - - '--diff' - - . - additional_dependencies: - - flake8-black + language_version: "3.11" + pass_filenames: false + args: ["--check", "."] + additional_dependencies: ["flake8-black"] - repo: 'https://github.com/adrienverge/yamllint' rev: v1.37.1 hooks: From 7ccbda5d2a3ce7fabb31c7d3eec4fc64c770413c Mon Sep 17 00:00:00 2001 From: Pedro Brochado Date: Mon, 22 Dec 2025 17:39:17 -0300 Subject: [PATCH 4/7] Update pre-commit check-manifest --- .pre-commit-config.yaml | 4 ++++ pyproject.toml | 2 ++ 2 files changed, 6 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 09847b6ed1..2dc3452a34 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,3 +24,7 @@ repos: rev: v1.37.1 hooks: - id: yamllint + - repo: 'https://github.com/mgedmin/check-manifest' + rev: "0.51" + hooks: + - id: check-manifest diff --git a/pyproject.toml b/pyproject.toml index fdb6d11f71..ba3a295247 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -198,6 +198,8 @@ ignore = [ ".github/**", "lint_requirements.txt", ".flake8", + ".yamllint.yaml", + ".pre-commit-config.yaml", "pulpcore/tests/functional/assets/**", ] From 52a768b04554f979253af71616ba69ef6db45e16 Mon Sep 17 00:00:00 2001 From: Pedro Brochado Date: Tue, 23 Dec 2025 09:13:54 -0300 Subject: [PATCH 5/7] Add custom scripts as pre-commit hooks --- .ci/scripts/check_gettext.sh | 12 +++++++++--- .pre-commit-config.yaml | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/.ci/scripts/check_gettext.sh b/.ci/scripts/check_gettext.sh index d11ff4f504..724236ab35 100755 --- a/.ci/scripts/check_gettext.sh +++ b/.ci/scripts/check_gettext.sh @@ -10,11 +10,17 @@ # make sure this script runs at the repo root cd "$(dirname "$(realpath -e "$0")")"/../.. -set -uv +set -u -MATCHES=$(grep -n -r --include \*.py "_(f") +if [ $# -gt 0 ]; then + MATCHES=$(grep -n "_(f" "$@" 2>/dev/null || true) +else + # fallback to original behavior if no files are provided + set -v + MATCHES=$(grep -n -r --include \*.py "_(f") +fi -if [ $? -ne 1 ]; then +if [ -n "$MATCHES" ]; then printf "\nERROR: Detected mix of f-strings and gettext:\n" echo "$MATCHES" exit 1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2dc3452a34..0cef894b4c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,3 +28,25 @@ repos: rev: "0.51" hooks: - id: check-manifest + - repo: local + hooks: + - id: check-requirements + name: check-requirements + language: python + entry: python .ci/scripts/check_requirements.py + pass_filenames: false + additional_dependencies: ["packaging"] + - repo: local + hooks: + - id: check-gettext + name: check-gettext + language: unsupported_script + types: [python] + entry: .ci/scripts/check_gettext.sh + - repo: local + hooks: + - id: extra-lint + name: extra-lint + language: unsupported + entry: sh -c "[ ! -x .ci/scripts/extra_linting.sh ] || .ci/scripts/extra_linting.sh" + pass_filenames: false From 609a8255c605f142d9fa168fdf9caa1387f7f733 Mon Sep 17 00:00:00 2001 From: Pedro Brochado Date: Tue, 23 Dec 2025 10:20:29 -0300 Subject: [PATCH 6/7] Add check-bump to pre-commit --- .ci/scripts/check_bump.sh | 5 +++++ .pre-commit-config.yaml | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100755 .ci/scripts/check_bump.sh diff --git a/.ci/scripts/check_bump.sh b/.ci/scripts/check_bump.sh new file mode 100755 index 0000000000..004843538c --- /dev/null +++ b/.ci/scripts/check_bump.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -eux +bump-my-version bump release --dry-run --allow-dirty +bump-my-version show-bump diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0cef894b4c..aa751b2651 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,21 +30,23 @@ repos: - id: check-manifest - repo: local hooks: + - id: check-bump + name: check-bump + language: python + entry: .ci/scripts/check_bump.sh + pass_filenames: false + additional_dependencies: ["bump-my-version"] - id: check-requirements name: check-requirements language: python entry: python .ci/scripts/check_requirements.py pass_filenames: false additional_dependencies: ["packaging"] - - repo: local - hooks: - id: check-gettext name: check-gettext language: unsupported_script types: [python] entry: .ci/scripts/check_gettext.sh - - repo: local - hooks: - id: extra-lint name: extra-lint language: unsupported From bffcfe90583ad0e4ad6bdace2a31c3ce2a457e82 Mon Sep 17 00:00:00 2001 From: Pedro Brochado Date: Tue, 23 Dec 2025 10:23:34 -0300 Subject: [PATCH 7/7] Update lint workflow to use pre-commit --- .github/workflows/lint.yml | 63 ++++++++++++-------------------------- 1 file changed, 20 insertions(+), 43 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5cf15baf7d..c53194be1c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -23,49 +23,26 @@ jobs: with: fetch-depth: 1 path: "pulpcore" - - uses: "actions/setup-python@v5" with: python-version: "3.11" - - - name: "Install python dependencies" - run: | - echo ::group::PYDEPS - pip install -r lint_requirements.txt - echo ::endgroup:: - - - name: "Lint workflow files" - run: | - yamllint - - - name: "Verify bump version config" - run: | - bump-my-version bump --dry-run release - bump-my-version show-bump - - # run black separately from flake8 to get a diff - - name: "Run black" - run: | - black --version - black --check --diff . - - # Lint code. - - name: "Run flake8" - run: | - flake8 - - - name: "Run extra lint checks" - run: | - [ ! -x .ci/scripts/extra_linting.sh ] || .ci/scripts/extra_linting.sh - - - name: "Check for any files unintentionally left out of MANIFEST.in" - run: | - check-manifest - - - name: "Verify requirements files" - run: | - python .ci/scripts/check_requirements.py - - - name: "Check for common gettext problems" - run: | - sh .ci/scripts/check_gettext.sh + # cache example from: + # https://pre-commit.com/#github-actions-example + - name: set PY + run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV + - uses: actions/cache@v5 + with: + path: ~/.cache/pre-commit + key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} + - name: Install pre-commit + run: | + pip install pre-commit + - name: Run pre-commit + shell: "bash" + env: + PY_COLORS: "1" + FORCE_COLOR: "1" + PRE_COMMIT_COLOR: "always" + TERM: "xterm-256color" + run: | + pre-commit run --all-files -v