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/.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/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3c44618914..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 -s -d '{extends: relaxed, rules: {line-length: disable}}' .github/workflows - - - 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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..aa751b2651 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,54 @@ +# 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: 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 + language_version: "3.11" + pass_filenames: false + args: ["--check", "."] + additional_dependencies: ["flake8-black"] + - repo: 'https://github.com/adrienverge/yamllint' + rev: v1.37.1 + hooks: + - id: yamllint + - repo: 'https://github.com/mgedmin/check-manifest' + rev: "0.51" + hooks: + - 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"] + - id: check-gettext + name: check-gettext + language: unsupported_script + types: [python] + entry: .ci/scripts/check_gettext.sh + - 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 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 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/**", ]