-
Notifications
You must be signed in to change notification settings - Fork 64
feat: ci check import #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,62 @@ | ||||||
| #!/usr/bin/env python3 | ||||||
| """检查所有Python文件是否可以成功编译和导入""" | ||||||
|
|
||||||
| import os | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| import py_compile | ||||||
| import sys | ||||||
| from pathlib import Path | ||||||
|
|
||||||
|
|
||||||
| def check_syntax(file_path): | ||||||
| """检查Python文件语法""" | ||||||
| try: | ||||||
| py_compile.compile(file_path, doraise=True) | ||||||
| return True, None | ||||||
| except py_compile.PyCompileError as e: | ||||||
| return False, str(e) | ||||||
|
|
||||||
|
|
||||||
| def main(): | ||||||
| """主函数""" | ||||||
| project_root = Path(__file__).parent.parent.parent | ||||||
| dingo_path = project_root / "dingo" | ||||||
|
|
||||||
| if not dingo_path.exists(): | ||||||
| print(f"❌ 找不到dingo目录: {dingo_path}") | ||||||
| sys.exit(1) | ||||||
|
|
||||||
| errors = [] | ||||||
| checked = 0 | ||||||
|
|
||||||
| print("🔍 检查所有Python文件的语法和导入...") | ||||||
| print("-" * 60) | ||||||
|
|
||||||
| for py_file in dingo_path.rglob("*.py"): | ||||||
| if "__pycache__" in str(py_file): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current method of checking for
Suggested change
|
||||||
| continue | ||||||
|
|
||||||
| checked += 1 | ||||||
| success, error = check_syntax(str(py_file)) | ||||||
|
|
||||||
| if success: | ||||||
| print(f"✓ {py_file.relative_to(project_root)}") | ||||||
| else: | ||||||
| error_msg = f"✗ {py_file.relative_to(project_root)}: {error}" | ||||||
| print(error_msg) | ||||||
| errors.append(error_msg) | ||||||
|
|
||||||
| print("-" * 60) | ||||||
| print(f"📊 检查了 {checked} 个文件") | ||||||
|
|
||||||
| if errors: | ||||||
| print(f"\n❌ 发现 {len(errors)} 个错误:") | ||||||
| for error in errors: | ||||||
| print(f" {error}") | ||||||
| sys.exit(1) | ||||||
| else: | ||||||
| print(f"✅ 所有文件检查通过!") | ||||||
| sys.exit(0) | ||||||
|
|
||||||
|
|
||||||
| if __name__ == "__main__": | ||||||
| main() | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| import os | ||
|
|
||
| from setuptools import find_packages, setup | ||
|
|
||
| with open("README.md", "r", encoding='utf-8') as fh: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring and filename
check_imports.pyare slightly misleading. The script usespy_compile, which primarily checks for syntax errors and can catch malformedimportstatements, but it doesn't perform a full import resolution that would detect runtime issues like circular dependencies or modules missing fromsys.path. To be more accurate, the docstring should clarify that the script performs a syntax/compilation check.