Skip to content

Commit

Permalink
[dev] restrict pylint to changed files (#4184)
Browse files Browse the repository at this point in the history
* [dev] restrict pylint to changed files

* fix glob

* avoid use of xargs -d
  • Loading branch information
cg505 authored Oct 29, 2024
1 parent 47ebae7 commit ce8d2df
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ BLACK_INCLUDES=(
'sky/skylet/providers/ibm'
)

PYLINT_FLAGS=(
'--load-plugins' 'pylint_quotes'
)

# Format specified files
format() {
yapf --in-place "${YAPF_FLAGS[@]}" "$@"
Expand All @@ -77,8 +81,9 @@ format_changed() {
MERGEBASE="$(git merge-base origin/master HEAD)"

if ! git diff --diff-filter=ACM --quiet --exit-code "$MERGEBASE" -- '*.py' '*.pyi' &>/dev/null; then
git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.py' '*.pyi' | xargs -P 5 \
yapf --in-place "${YAPF_EXCLUDES[@]}" "${YAPF_FLAGS[@]}"
git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.py' '*.pyi' | \
tr '\n' '\0' | xargs -P 5 -0 \
yapf --in-place "${YAPF_EXCLUDES[@]}" "${YAPF_FLAGS[@]}"
fi

}
Expand Down Expand Up @@ -119,7 +124,21 @@ mypy $(cat tests/mypy_files.txt)

# Run Pylint
echo 'Sky Pylint:'
pylint --load-plugins pylint_quotes sky
if [[ "$1" == '--files' ]]; then
# If --files is passed, filter to files within sky/ and pass to pylint.
pylint "${PYLINT_FLAGS[@]}" "${@:2}"
elif [[ "$1" == '--all' ]]; then
# Pylint entire sky directory.
pylint "${PYLINT_FLAGS[@]}" sky
else
# Pylint only files in sky/ that have changed in last commit.
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 "${PYLINT_FLAGS[@]}"
else
echo 'Pylint skipped: no files changed in sky/.'
fi
fi

if ! git diff --quiet &>/dev/null; then
echo 'Reformatted files. Please review and stage the changes.'
Expand Down

0 comments on commit ce8d2df

Please sign in to comment.