-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a pre commit config to help format before pushing (#4258)
* pre commit config * yapf version * fix * mypy check all files * skip smoke_test.py * add doc * better format * newline format * sync with format.sh * comment fix
- Loading branch information
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Ensure this configuration aligns with format.sh and requirements.txt | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v5.0.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: check-yaml | ||
- id: check-added-large-files | ||
|
||
- repo: https://github.com/psf/black | ||
rev: 22.10.0 # Match the version from requirements | ||
hooks: | ||
- id: black | ||
name: black (IBM specific) | ||
files: "^sky/skylet/providers/ibm/.*" # Match only files in the IBM directory | ||
|
||
- repo: https://github.com/pycqa/isort | ||
rev: 5.12.0 # Match the version from requirements | ||
hooks: | ||
# First isort command | ||
- id: isort | ||
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 | ||
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 # Match the version from requirements | ||
hooks: | ||
- id: yapf | ||
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: https://github.com/pylint-dev/pylint | ||
rev: v2.14.5 # Match the version from requirements | ||
hooks: | ||
- id: pylint | ||
additional_dependencies: | ||
- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters