From 452b2276e77a751bc54cfb622e4de843cd813332 Mon Sep 17 00:00:00 2001 From: Cade Daniel Date: Tue, 31 Oct 2023 15:12:06 -0700 Subject: [PATCH 1/2] Formatter only checks lints in changed files --- format.sh | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/format.sh b/format.sh index 9d6d5b6ea4e72..f4b63ecd66d88 100755 --- a/format.sh +++ b/format.sh @@ -93,9 +93,43 @@ echo 'vLLM yapf: Done' # echo 'vLLM mypy:' # mypy +# Lint specified files +lint() { + pylint "$@" +} + +# Lint files that differ from main branch. Ignores dirs that are not slated +# for autolint yet. +lint_changed() { + # The `if` guard ensures that the list of filenames is not empty, which + # could cause pylint to receive 0 positional arguments, making it hang + # waiting for STDIN. + # + # `diff-filter=ACM` and $MERGEBASE is to ensure we only lint files that + # exist on both branches. + MERGEBASE="$(git merge-base origin/main 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 \ + pylint + fi + +} + # Run Pylint echo 'vLLM Pylint:' -pylint vllm tests +## This flag lints individual files. --files *must* be the first command line +## arg to use this option. +if [[ "$1" == '--files' ]]; then + lint "${@:2}" + # If `--all` is passed, then any further arguments are ignored and the + # entire python directory is linted. +elif [[ "$1" == '--all' ]]; then + lint vllm tests +else + # Format only the files that changed in last commit. + lint_changed +fi if ! git diff --quiet &>/dev/null; then echo 'Reformatted files. Please review and stage the changes.' From 2cf6227e56a2d3310e60196ca7de9f51afe70b5c Mon Sep 17 00:00:00 2001 From: Cade Daniel Date: Tue, 31 Oct 2023 15:17:51 -0700 Subject: [PATCH 2/2] Adding __init__.py to tests dir --- tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000000000..e69de29bb2d1d