From e3a55f064782cddefc4303664e941c196b0f7316 Mon Sep 17 00:00:00 2001 From: ZePing Guo Date: Wed, 27 Nov 2024 13:17:55 +0800 Subject: [PATCH] sync with format.sh --- .pre-commit-config.yaml | 87 ++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 32 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 667ba9bcf38..2e10afe2feb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,4 @@ -# TODO(zpoint): Ensure it is synchronized with format.sh +# Ensure this configuration aligns with format.sh and requirements.txt repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 @@ -9,49 +9,72 @@ repos: - id: check-added-large-files - repo: https://github.com/psf/black - rev: 23.12.1 + rev: 22.10.0 # Match the version from requirements hooks: - id: black - files: sky/skylet/providers/ibm/.* + name: black (IBM specific) + files: "^sky/skylet/providers/ibm/.*" # Match only files in the IBM directory - repo: https://github.com/pycqa/isort - rev: 5.13.2 + rev: 5.12.0 # Match the version from requirements hooks: + # First isort command - id: isort - exclude: sky/skylet/providers/ibm/.* - args: ["--profile", "google"] + name: isort (general) + args: + - "--sg=build/**" # Matches "${ISORT_YAPF_EXCLUDES[@]}" + - "--sg=sky/skylet/providers/ibm/**" + files: "^(sky|tests|examples|llm|docs)/.*" # Only match these directories + # Second isort command - id: isort - files: sky/skylet/providers/ibm/.* - args: ["--profile", "black", "-l", "88", "-m", "3"] - stages: [pre-commit] + name: isort (IBM specific) + args: + - "--profile=black" + - "-l=88" + - "-m=3" + files: "^sky/skylet/providers/ibm/.*" # Only match IBM-specific directory + +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.991 # Match the version from requirements + hooks: + - id: mypy + args: + # from tests/mypy_files.txt + - "sky" + - "--exclude" + - "sky/benchmark|sky/callbacks|sky/skylet/providers/azure|sky/resources.py|sky/backends/monkey_patches" + pass_filenames: false + additional_dependencies: + - types-PyYAML + - types-requests<2.31 # Match the condition in requirements.txt + - types-setuptools + - types-cachetools + - types-pyvmomi - repo: https://github.com/google/yapf - rev: v0.32.0 + rev: v0.32.0 # Match the version from requirements hooks: - id: yapf - exclude: (build/.*|sky/skylet/providers/ibm/.*) - additional_dependencies: [toml] + name: yapf + exclude: (build/.*|sky/skylet/providers/ibm/.*) # Matches exclusions from the script + args: ['--recursive', '--parallel'] # Only necessary flags + additional_dependencies: [toml==0.10.2] -- repo: local +- repo: https://github.com/pylint-dev/pylint + rev: v2.14.5 # Match the version from requirements hooks: - id: pylint - name: pylint - entry: pylint - language: python - types: [python] additional_dependencies: - - pylint==2.14.5 - - pylint-quotes==0.2.3 - args: [ - "--load-plugins=pylint_quotes", - "--rcfile=.pylintrc" - ] - exclude: ^(build/.*|sky/skylet/providers/ibm/.*|tests/test_smoke\.py)$ - - - id: mypy - name: mypy - entry: mypy - language: system - types: [python] - require_serial: true - exclude: ^tests/test_smoke\.py$ + - pylint-quotes==0.2.3 # Match the version from requirements + name: pylint-only-changed-files + entry: > + bash -c ' + MERGEBASE=$(git merge-base origin/main HEAD); + changed_files=$(git diff --name-only --diff-filter=ACM "$MERGEBASE" -- "sky/*.py" "sky/*.pyi"); + if [[ -n "$changed_files" ]]; then + echo "$changed_files" | tr "\n" "\0" | xargs -0 pylint --load-plugins=pylint_quotes --rcfile=.pylintrc; + else + echo "Pylint skipped: no files changed in sky/."; + fi' + pass_filenames: false + always_run: true