-
Notifications
You must be signed in to change notification settings - Fork 14
95 lines (82 loc) · 3.18 KB
/
python-code-quality.yml
File metadata and controls
95 lines (82 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: python-code-quality
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
code-quality:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.12.11"
- name: Cache pip dependencies
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install black isort flake pytest
run: |
python -m pip install --upgrade pip
# install black isort flake
pip install black==24.4.2 isort==5.13.2 flake8==7.0.0
# install pytest and other dependencies
pip install pytest==9.0.2 -r inference_server/launcher/requirements-sans-vllm.txt
- name: Check for trailing whitespace
run: |
# Check for trailing whitespace in all files
if grep -r --include="*.py" --include="*.yml" --include="*.yaml" --include="*.json" --include="*.md" --include="*.txt" '[[:space:]]$' .; then
echo "Found trailing whitespace in the above files"
exit 1
fi
- name: Check end of file newlines
run: |
# Check that files end with a newline
find . -name "*.py" -o -name "*.yml" -o -name "*.yaml" -o -name "*.json" -o -name "*.md" | while read file; do
if [ -n "$(tail -c1 "$file")" ]; then
echo "File $file does not end with a newline"
exit 1
fi
done
- name: Check for large files
run: |
# Check for files larger than 600KB
find . -type f -size +600k | grep -v '.git/' | while read file; do
echo "Large file found: $file"
done
if find . -type f -size +600k | grep -v '.git/' | grep -q .; then
echo "Large files found. Consider using Git LFS or removing them."
exit 1
fi
- name: Run Black (code formatting check)
run: |
black --check --diff .
- name: Run isort (import sorting check)
run: |
isort --profile black --check-only --diff .
- name: Run flake8 (linting)
run: |
flake8 --max-line-length=88 --extend-ignore=E203,W503 .
- name: Run pytest launcher
run: |
cd inference_server/launcher
python -m pytest tests/test_launcher.py -v
python -m pytest tests/test_gputranslator.py -v
- name: Summary
if: always()
run: |
echo "Code quality checks completed!"
echo "If any checks failed, please run the following locally to fix issues:"
echo " black ."
echo " isort --profile black ."
echo " flake8 --max-line-length=88 --extend-ignore=E203,W503 ."
echo " python -m pytest tests/test_launcher.py -v"
echo " python -m pytest tests/test_gputranslator.py -v"