Skip to content

Commit 9b07f5e

Browse files
PotabkYikun
authored andcommitted
add pre-commit
Signed-off-by: wangli <[email protected]> Signed-off-by: Yikun Jiang <[email protected]>
1 parent ca884ef commit 9b07f5e

29 files changed

+755
-592
lines changed

.github/workflows/accuracy_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ jobs:
373373
git push -f origin "${{ env.BRANCH_NAME }}"
374374
375375
- name: Create PR in upstream via API
376-
uses: actions/github-script@v6
376+
uses: actions/github-script@v7
377377
with:
378378
github-token: ${{ secrets.PAT_TOKEN }}
379379
script: |

.github/workflows/doc_codespell.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ jobs:
2525
run: |
2626
python -m pip install --upgrade pip
2727
pip install -r requirements-lint.txt
28-
- name: Run codespell check
29-
run: |
30-
CODESPELL_EXCLUDES=('--skip' 'tests/prompts/**,./benchmarks/sonnet.txt,*tests/lora/data/**,build/**,./vllm_ascend.egg-info/**')
31-
CODESPELL_IGNORE_WORDS=('-L' 'CANN,cann,NNAL,nnal,ASCEND,ascend,EnQue,CopyIn')
32-
33-
codespell --toml pyproject.toml "${CODESPELL_EXCLUDES[@]}" "${CODESPELL_IGNORE_WORDS[@]}"
28+
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
29+
env:
30+
SHELLCHECK_OPTS: "--exclude=SC2046,SC2006,SC2086" # Exclude SC2046, SC2006, SC2086 for actionlint
31+
with:
32+
extra_args: --all-files --hook-stage manual

.github/workflows/image_ubuntu.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
username: ${{ vars.QUAY_USERNAME }}
9191
password: ${{ secrets.QUAY_PASSWORD }}
9292

93-
- name: Build and push 910b
93+
- name: Build and push
9494
uses: docker/build-push-action@v6
9595
with:
9696
platforms: >-
@@ -101,7 +101,6 @@ jobs:
101101
}}
102102
# use the current repo path as the build context, ensure .git is contained
103103
context: .
104-
file: Dockerfile
105104
# only trigger when tag, branch/main push
106105
push: ${{ github.event_name == 'push' && github.repository_owner == 'vllm-project' }}
107106
labels: ${{ steps.meta.outputs.labels }}

.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-ascend dev
26+
run: |
27+
pip install -r requirements-dev.txt --extra-index-url https://download.pytorch.org/whl/cpu
28+
- name: Install vllm
29+
working-directory: vllm-empty
30+
run: |
31+
pip install -r requirements/build.txt --extra-index-url https://download.pytorch.org/whl/cpu
32+
VLLM_TARGET_DEVICE=empty pip install .
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/vllm_ascend_test.yaml

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -67,69 +67,7 @@ concurrency:
6767

6868
jobs:
6969
lint:
70-
# Only trigger lint on pull request
71-
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')
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: Install dependencies
107-
run: |
108-
pip install -r requirements-dev.txt --extra-index-url https://download.pytorch.org/whl/cpu
109-
110-
- name: Checkout vllm-project/vllm repo
111-
uses: actions/checkout@v4
112-
with:
113-
repository: vllm-project/vllm
114-
path: vllm-empty
115-
116-
- name: Actionlint Check
117-
env:
118-
SHELLCHECK_OPTS: --exclude=SC2046,SC2006,SC2086
119-
run: |
120-
echo "::add-matcher::.github/workflows/matchers/actionlint.json"
121-
tools/actionlint.sh -color
122-
123-
- name: Install vllm-project/vllm from source
124-
working-directory: vllm-empty
125-
run: |
126-
pip install -r requirements/build.txt --extra-index-url https://download.pytorch.org/whl/cpu
127-
VLLM_TARGET_DEVICE=empty pip install .
128-
129-
- name: Mypy Check
130-
run: |
131-
echo "::add-matcher::.github/workflows/matchers/mypy.json"
132-
tools/mypy.sh 1 ${{ matrix.python-version }}
70+
uses: ./.github/workflows/pre-commit.yml
13371

13472
ut:
13573
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/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)