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 2 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
22 changes: 20 additions & 2 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,7 +81,7 @@ 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 \
git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.py' '*.pyi' | xargs -P 5 -d '\n' \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like -d is not available on mac:

xargs: invalid option -- d
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements] [-S replsize]]
             [-J replstr] [-L number] [-n number [-x]] [-P maxprocs]
             [-s size] [utility [argument ...]]

Any other fix than having all macos users install gnu xargs? https://superuser.com/questions/467176/replacement-for-xargs-d-in-osx

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the catch! This only matters if there are filenames with spaces, which we probably don't expect but should still handle.
I think we can use tr '\n' '\0' | xargs -0 instead. Will update.

yapf --in-place "${YAPF_EXCLUDES[@]}" "${YAPF_FLAGS[@]}"
fi

Expand Down Expand Up @@ -119,7 +123,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" | xargs -d '\n' 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