Skip to content

Commit c744643

Browse files
authored
[1/N][CI] Move linting system to pre-commits hooks (#1256)
### What this PR does / why we need it? Follow vllm-project/vllm lint way: https://github.com/vllm-project/vllm/blob/main/.pre-commit-config.yaml Enable pre-commit to avoid some low level error AMAP. This pr is one step of #1241, The purpose is make linting system more clear and convenient, on this step, Mainly did the following things: yapf, actionlint, ruff, typos, isort, mypy, png-lint, signoff-commit, enforce-import-regex-instead-of-re. TODO: - clang-format(check for csrc with google style) need clean code, disable for now - pymarkdown need clean code, disable for now - shellcheck need clean code, disable for now ### Does this PR introduce _any_ user-facing change? Only developer UX change: https://vllm-ascend--1256.org.readthedocs.build/en/1256/developer_guide/contributing.html#run-lint-locally ``` pip install -r requirements-lint.txt && pre-commit install bash format.sh ``` ### How was this patch tested? CI passed with new added/existing test. Co-authored-by: Yikun [yikunkero@gmail.com](mailto:yikunkero@gmail.com) Co-authored-by: wangli [wangli858794774@gmail.com](mailto:wangli858794774@gmail.com) - vLLM version: v0.9.1 - vLLM main: vllm-project/vllm@5358cce --------- Signed-off-by: wangli <wangli858794774@gmail.com>
1 parent 643e6f5 commit c744643

28 files changed

+753
-667
lines changed

.github/ISSUE_TEMPLATE/900-release-checklist.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,6 @@ body:
9595
9696
- [ ] Upload 310p wheel to Github release page
9797
98-
- [ ] Brodcast the release news (By message, blog , etc)
98+
- [ ] Broadcast the release news (By message, blog , etc)
9999
100100
- [ ] Close this issue

.github/workflows/doc_codespell.yaml

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/workflows/pre-commit.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: pre-commit
2+
3+
on:
4+
workflow_call:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
pre-commit:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout vllm-project/vllm-ascend repo
14+
uses: actions/checkout@v4
15+
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
16+
with:
17+
python-version: "3.10"
18+
- run: echo "::add-matcher::.github/workflows/matchers/actionlint.json"
19+
- run: echo "::add-matcher::.github/workflows/matchers/mypy.json"
20+
- name: Checkout vllm-project/vllm repo
21+
uses: actions/checkout@v4
22+
with:
23+
repository: vllm-project/vllm
24+
path: ./vllm-empty
25+
- name: Install vllm
26+
working-directory: vllm-empty
27+
run: |
28+
pip install -r requirements/build.txt --extra-index-url https://download.pytorch.org/whl/cpu
29+
VLLM_TARGET_DEVICE=empty pip install .
30+
- name: Install vllm-ascend dev
31+
run: |
32+
pip install -r requirements-dev.txt --extra-index-url https://download.pytorch.org/whl/cpu
33+
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
34+
env:
35+
SHELLCHECK_OPTS: "--exclude=SC2046,SC2006,SC2086" # Exclude SC2046, SC2006, SC2086 for actionlint
36+
with:
37+
extra_args: --all-files --hook-stage manual

.github/workflows/shellcheck.yml

Lines changed: 0 additions & 49 deletions
This file was deleted.

.github/workflows/vllm_ascend_test.yaml

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -69,67 +69,7 @@ jobs:
6969
lint:
7070
# Only trigger lint on pull request
7171
if: ${{ github.event_name == 'pull_request' }}
72-
runs-on: ubuntu-latest
73-
strategy:
74-
matrix:
75-
python-version: ["3.10"]
76-
steps:
77-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
78-
- name: Set up Python ${{ matrix.python-version }}
79-
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
80-
with:
81-
python-version: ${{ matrix.python-version }}
82-
- name: Install dependencies
83-
run: |
84-
python -m pip install --upgrade pip
85-
pip install -r requirements-lint.txt
86-
- name: Run codespell check
87-
run: |
88-
CODESPELL_EXCLUDES=('--skip' 'tests/prompts/**,./benchmarks/sonnet.txt,*tests/lora/data/**,build/**,./vllm_ascend.egg-info/**')
89-
CODESPELL_IGNORE_WORDS=('-L' 'CANN,cann,NNAL,nnal,ASCEND,ascend,EnQue,CopyIn,assertIn,rever')
90-
91-
codespell --toml pyproject.toml "${CODESPELL_EXCLUDES[@]}" "${CODESPELL_IGNORE_WORDS[@]}"
92-
- name: Analysing the code with ruff
93-
run: |
94-
echo "::add-matcher::.github/workflows/matchers/ruff.json"
95-
ruff check --output-format github .
96-
- name: Run isort
97-
run: |
98-
isort . --check-only
99-
- name: Running yapf
100-
run: |
101-
python -m pip install --upgrade pip
102-
pip install toml
103-
pip install yapf==0.32.0
104-
yapf --diff --recursive .
105-
106-
- name: Checkout vllm-project/vllm repo
107-
uses: actions/checkout@v4
108-
with:
109-
repository: vllm-project/vllm
110-
path: vllm-empty
111-
112-
- name: Actionlint Check
113-
env:
114-
SHELLCHECK_OPTS: --exclude=SC2046,SC2006,SC2086
115-
run: |
116-
echo "::add-matcher::.github/workflows/matchers/actionlint.json"
117-
tools/actionlint.sh -color
118-
119-
- name: Install vllm-project/vllm from source
120-
working-directory: vllm-empty
121-
run: |
122-
pip install -r requirements/build.txt --extra-index-url https://download.pytorch.org/whl/cpu
123-
VLLM_TARGET_DEVICE=empty pip install .
124-
125-
- name: Install dependencies
126-
run: |
127-
pip install -r requirements-dev.txt --extra-index-url https://download.pytorch.org/whl/cpu
128-
129-
- name: Mypy Check
130-
run: |
131-
echo "::add-matcher::.github/workflows/matchers/mypy.json"
132-
tools/mypy.sh 1 ${{ matrix.python-version }}
72+
uses: ./.github/workflows/pre-commit.yml
13373

13474
ut:
13575
needs: [lint]

.pre-commit-config.yaml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
default_install_hook_types:
2+
- pre-commit
3+
- commit-msg
4+
default_stages:
5+
- pre-commit # Run locally
6+
- manual # Run in CI
7+
exclude: 'examples/.*' # Exclude examples from all hooks by default
8+
repos:
9+
- repo: https://github.com/codespell-project/codespell
10+
rev: v2.4.1
11+
hooks:
12+
- id: codespell
13+
args: [
14+
--toml, pyproject.toml,
15+
'--skip', 'tests/e2e/multicard/test_torchair_graph_mode.py,tests/prompts/**,./benchmarks/sonnet.txt,*tests/lora/data/**,build/**,./vllm_ascend.egg-info/**,.github/**,typos.toml',
16+
'-L', 'CANN,cann,NNAL,nnal,ASCEND,ascend,EnQue,CopyIn'
17+
]
18+
additional_dependencies:
19+
- tomli
20+
- repo: https://github.com/google/yapf
21+
rev: v0.43.0
22+
hooks:
23+
- id: yapf
24+
args: [--in-place, --verbose]
25+
# Keep the same list from yapfignore here to avoid yapf failing without any inputs
26+
exclude: '(.github|benchmarks|examples|docs)/.*'
27+
- repo: https://github.com/astral-sh/ruff-pre-commit
28+
rev: v0.11.7
29+
hooks:
30+
- id: ruff
31+
args: [--output-format, github, --fix]
32+
- id: ruff-format
33+
files: ^(benchmarks|examples)/.*
34+
- repo: https://github.com/crate-ci/typos
35+
rev: v1.32.0
36+
hooks:
37+
- id: typos
38+
- repo: https://github.com/PyCQA/isort
39+
rev: 6.0.1
40+
hooks:
41+
- id: isort
42+
# - repo: https://github.com/pre-commit/mirrors-clang-format
43+
# rev: v20.1.3
44+
# hooks:
45+
# - id: clang-format
46+
# files: ^csrc/.*\.(cpp|hpp|cc|hh|cxx|hxx)$
47+
# types_or: [c++]
48+
# args: [--style=google, --verbose]
49+
# - repo: https://github.com/jackdewinter/pymarkdown
50+
# rev: v0.9.29
51+
# hooks:
52+
# - id: pymarkdown
53+
# args: [fix]
54+
- repo: https://github.com/rhysd/actionlint
55+
rev: v1.7.7
56+
hooks:
57+
- id: actionlint
58+
- repo: local
59+
hooks:
60+
# For local development, you can run mypy using tools/mypy.sh script if needed.
61+
# - id: mypy-local
62+
# name: Run mypy for local Python installation
63+
# entry: tools/mypy.sh 0 "local"
64+
# language: system
65+
# types: [python]
66+
# stages: [pre-commit] # Don't run in CI
67+
- id: mypy-3.9 # TODO: Use https://github.com/pre-commit/mirrors-mypy when mypy setup is less awkward
68+
name: Run mypy for Python 3.9
69+
entry: tools/mypy.sh 1 "3.9"
70+
# Use system python because vllm installation is required
71+
language: system
72+
types: [python]
73+
stages: [manual] # Only run in CI
74+
- id: mypy-3.10 # TODO: Use https://github.com/pre-commit/mirrors-mypy when mypy setup is less awkward
75+
name: Run mypy for Python 3.10
76+
entry: tools/mypy.sh 1 "3.10"
77+
# Use system python because vllm installation is required
78+
language: system
79+
types: [python]
80+
stages: [manual] # Only run in CI
81+
- id: mypy-3.11 # TODO: Use https://github.com/pre-commit/mirrors-mypy when mypy setup is less awkward
82+
name: Run mypy for Python 3.11
83+
entry: tools/mypy.sh 1 "3.11"
84+
# Use system python because vllm installation is required
85+
language: system
86+
types: [python]
87+
stages: [manual] # Only run in CI
88+
- id: mypy-3.12 # TODO: Use https://github.com/pre-commit/mirrors-mypy when mypy setup is less awkward
89+
name: Run mypy for Python 3.12
90+
entry: tools/mypy.sh 1 "3.12"
91+
# Use system python because vllm installation is required
92+
language: system
93+
types: [python]
94+
stages: [manual] # Only run in CI
95+
# FIXME: enable shellcheck
96+
# - id: shellcheck
97+
# name: Lint shell scripts
98+
# entry: tools/shellcheck.sh
99+
# language: script
100+
# types: [shell]
101+
- id: png-lint
102+
name: Lint PNG exports from excalidraw
103+
entry: tools/png-lint.sh
104+
language: script
105+
types: [png]
106+
- id: signoff-commit
107+
name: Sign-off Commit
108+
entry: bash
109+
args:
110+
- -c
111+
- |
112+
if ! grep -q "^Signed-off-by: $(git config user.name) <$(git config user.email)>" "$(git rev-parse --git-path COMMIT_EDITMSG)"; then
113+
printf "\nSigned-off-by: $(git config user.name) <$(git config user.email)>\n" >> "$(git rev-parse --git-path COMMIT_EDITMSG)"
114+
fi
115+
language: system
116+
verbose: true
117+
stages: [commit-msg]
118+
- id: check-filenames
119+
name: Check for spaces in all filenames
120+
entry: bash
121+
args:
122+
- -c
123+
- 'git ls-files | grep " " && echo "Filenames should not contain spaces!" && exit 1 || exit 0'
124+
language: system
125+
always_run: true
126+
pass_filenames: false
127+
- id: enforce-import-regex-instead-of-re
128+
name: Enforce import regex as re
129+
entry: python tools/enforce_regex_import.py
130+
language: python
131+
types: [python]
132+
pass_filenames: false
133+
additional_dependencies: [regex]
134+
# Keep `suggestion` last
135+
- id: suggestion
136+
name: Suggestion
137+
entry: bash -c 'echo "To bypass pre-commit hooks, add --no-verify to git commit."'
138+
language: system
139+
verbose: true
140+
pass_filenames: false
141+
# Insert new entries above the `suggestion` entry

0 commit comments

Comments
 (0)