Skip to content

Commit 1c7d324

Browse files
feat: ci check import (#285)
* feat: ci check import * 🎨 Auto-format code with pre-commit --------- Co-authored-by: GitHub Action <[email protected]>
1 parent 153a19d commit 1c7d324

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

.github/scripts/check_imports.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python3
2+
"""检查所有Python文件是否可以成功编译和导入"""
3+
4+
import os
5+
import py_compile
6+
import sys
7+
from pathlib import Path
8+
9+
10+
def check_syntax(file_path):
11+
"""检查Python文件语法"""
12+
try:
13+
py_compile.compile(file_path, doraise=True)
14+
return True, None
15+
except py_compile.PyCompileError as e:
16+
return False, str(e)
17+
18+
19+
def main():
20+
"""主函数"""
21+
project_root = Path(__file__).parent.parent.parent
22+
dingo_path = project_root / "dingo"
23+
24+
if not dingo_path.exists():
25+
print(f"❌ 找不到dingo目录: {dingo_path}")
26+
sys.exit(1)
27+
28+
errors = []
29+
checked = 0
30+
31+
print("🔍 检查所有Python文件的语法和导入...")
32+
print("-" * 60)
33+
34+
for py_file in dingo_path.rglob("*.py"):
35+
if "__pycache__" in str(py_file):
36+
continue
37+
38+
checked += 1
39+
success, error = check_syntax(str(py_file))
40+
41+
if success:
42+
print(f"✓ {py_file.relative_to(project_root)}")
43+
else:
44+
error_msg = f"✗ {py_file.relative_to(project_root)}: {error}"
45+
print(error_msg)
46+
errors.append(error_msg)
47+
48+
print("-" * 60)
49+
print(f"📊 检查了 {checked} 个文件")
50+
51+
if errors:
52+
print(f"\n❌ 发现 {len(errors)} 个错误:")
53+
for error in errors:
54+
print(f" {error}")
55+
sys.exit(1)
56+
else:
57+
print(f"✅ 所有文件检查通过!")
58+
sys.exit(0)
59+
60+
61+
if __name__ == "__main__":
62+
main()

.github/workflows/IntegrationTest.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ jobs:
2727
if [ -f requirements/runtime.txt ]; then pip install -r requirements/runtime.txt; fi
2828
pip install -e .
2929
30+
- name: Check Python syntax and imports
31+
run: |
32+
python .github/scripts/check_imports.py
33+
3034
- name: Integration Test(local plaintext)
3135
run: |
3236
python -m dingo.run.cli --input .github/env/local_plaintext.json

.github/workflows/lint.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ jobs:
1919
- name: Install pre-commit
2020
run: pip install pre-commit==3.8.0
2121

22+
- name: Install package
23+
run: |
24+
python -m pip install --upgrade pip
25+
if [ -f requirements/runtime.txt ]; then pip install -r requirements/runtime.txt; fi
26+
pip install -e .
27+
28+
- name: Check Python syntax and imports
29+
run: |
30+
python .github/scripts/check_imports.py
31+
2232
- name: Run pre-commit (auto-fix)
2333
id: pre_commit_auto_fix
2434
run: |

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
32
from setuptools import find_packages, setup
43

54
with open("README.md", "r", encoding='utf-8') as fh:

0 commit comments

Comments
 (0)