Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dev] restrict pylint to changed files #4184

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading