File tree Expand file tree Collapse file tree 4 files changed +76
-1
lines changed
Expand file tree Collapse file tree 4 files changed +76
-1
lines changed Original file line number Diff line number Diff line change 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 ()
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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 : |
Original file line number Diff line number Diff line change 11import os
2-
32from setuptools import find_packages , setup
43
54with open ("README.md" , "r" , encoding = 'utf-8' ) as fh :
You can’t perform that action at this time.
0 commit comments