@@ -24,6 +24,7 @@ builtin cd "$ROOT" || exit 1
2424YAPF_VERSION=$( yapf --version | awk ' {print $2}' )
2525RUFF_VERSION=$( ruff --version | awk ' {print $2}' )
2626MYPY_VERSION=$( mypy --version | awk ' {print $2}' )
27+ CODESPELL_VERSION=$( codespell --version)
2728
2829# # params: tool name, tool version, required version
2930tool_version_check () {
@@ -36,6 +37,7 @@ tool_version_check() {
3637tool_version_check " yapf" $YAPF_VERSION " $( grep yapf requirements-dev.txt | cut -d' =' -f3) "
3738tool_version_check " ruff" $RUFF_VERSION " $( grep " ruff==" requirements-dev.txt | cut -d' =' -f3) "
3839tool_version_check " mypy" " $MYPY_VERSION " " $( grep mypy requirements-dev.txt | cut -d' =' -f3) "
40+ tool_version_check " codespell" " $CODESPELL_VERSION " " $( grep codespell requirements-dev.txt | cut -d' =' -f3) "
3941
4042YAPF_FLAGS=(
4143 ' --recursive'
@@ -93,6 +95,47 @@ echo 'vLLM yapf: Done'
9395# echo 'vLLM mypy:'
9496# mypy
9597
98+ # check spelling of specified files
99+ spell_check () {
100+ codespell " $@ "
101+ }
102+
103+ spell_check_all (){
104+ codespell --toml pyproject.toml
105+ }
106+
107+ # Spelling check of files that differ from main branch.
108+ spell_check_changed () {
109+ # The `if` guard ensures that the list of filenames is not empty, which
110+ # could cause ruff to receive 0 positional arguments, making it hang
111+ # waiting for STDIN.
112+ #
113+ # `diff-filter=ACM` and $MERGEBASE is to ensure we only lint files that
114+ # exist on both branches.
115+ MERGEBASE=" $( git merge-base origin/main HEAD) "
116+
117+ if ! git diff --diff-filter=ACM --quiet --exit-code " $MERGEBASE " -- ' *.py' ' *.pyi' & > /dev/null; then
118+ git diff --name-only --diff-filter=ACM " $MERGEBASE " -- ' *.py' ' *.pyi' | xargs \
119+ codespell
120+ fi
121+ }
122+
123+ # Run Codespell
124+ # # This flag runs spell check of individual files. --files *must* be the first command line
125+ # # arg to use this option.
126+ if [[ " $1 " == ' --files' ]]; then
127+ spell_check " ${@: 2} "
128+ # If `--all` is passed, then any further arguments are ignored and the
129+ # entire python directory is linted.
130+ elif [[ " $1 " == ' --all' ]]; then
131+ spell_check_all
132+ else
133+ # Check spelling only of the files that changed in last commit.
134+ spell_check_changed
135+ fi
136+ echo ' vLLM codespell: Done'
137+
138+
96139# Lint specified files
97140lint () {
98141 ruff " $@ "
@@ -117,9 +160,9 @@ lint_changed() {
117160}
118161
119162# Run Ruff
120- echo ' vLLM Ruff :'
121- # # This flag lints individual files. --files *must* be the first command line
122- # # arg to use this option.
163+ echo ' vLLM ruff :'
164+ # ## This flag lints individual files. --files *must* be the first command line
165+ # ## arg to use this option.
123166if [[ " $1 " == ' --files' ]]; then
124167 lint " ${@: 2} "
125168 # If `--all` is passed, then any further arguments are ignored and the
@@ -139,3 +182,5 @@ if ! git diff --quiet &>/dev/null; then
139182
140183 exit 1
141184fi
185+
186+
0 commit comments