check_project_status.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. DataOps Platform 项目状态检查脚本
  5. 用于诊断Cursor项目识别问题
  6. """
  7. import os
  8. import sys
  9. import json
  10. from pathlib import Path
  11. def check_python_environment():
  12. """检查Python环境"""
  13. print("=" * 60)
  14. print("Python环境检查")
  15. print("=" * 60)
  16. print(f"Python版本: {sys.version}")
  17. print(f"Python路径: {sys.executable}")
  18. print(f"Python可执行文件: {os.path.exists(sys.executable)}")
  19. # 检查虚拟环境
  20. in_venv = hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)
  21. print(f"是否在虚拟环境中: {in_venv}")
  22. if in_venv:
  23. print(f"虚拟环境路径: {sys.prefix}")
  24. print()
  25. def check_project_structure():
  26. """检查项目结构"""
  27. print("=" * 60)
  28. print("项目结构检查")
  29. print("=" * 60)
  30. project_root = Path(__file__).parent
  31. print(f"项目根目录: {project_root}")
  32. # 关键文件检查
  33. key_files = [
  34. "pyproject.toml",
  35. "setup.py",
  36. "requirements.txt",
  37. "application.py",
  38. ".cursorrules",
  39. ".gitignore",
  40. "README.md"
  41. ]
  42. for file_name in key_files:
  43. file_path = project_root / file_name
  44. exists = file_path.exists()
  45. print(f"{file_name}: {'✓' if exists else '✗'} ({'存在' if exists else '缺失'})")
  46. print()
  47. # 目录结构检查
  48. key_dirs = [
  49. "app",
  50. "app/api",
  51. "app/config",
  52. "app/models",
  53. "app/services",
  54. "database",
  55. "docs",
  56. "tests",
  57. ".vscode"
  58. ]
  59. for dir_name in key_dirs:
  60. dir_path = project_root / dir_name
  61. exists = dir_path.exists()
  62. print(f"{dir_name}/: {'✓' if exists else '✗'} ({'存在' if exists else '缺失'})")
  63. print()
  64. def check_cursor_compatibility():
  65. """检查Cursor兼容性"""
  66. print("=" * 60)
  67. print("Cursor兼容性检查")
  68. print("=" * 60)
  69. project_root = Path(__file__).parent
  70. # 检查pyproject.toml
  71. pyproject_path = project_root / "pyproject.toml"
  72. if pyproject_path.exists():
  73. print("✓ pyproject.toml 存在 - 现代Python项目标准")
  74. try:
  75. with open(pyproject_path, 'r', encoding='utf-8') as f:
  76. content = f.read()
  77. if "build-system" in content and "project" in content:
  78. print(" ✓ 文件格式正确")
  79. else:
  80. print(" ✗ 文件格式可能有问题")
  81. except Exception as e:
  82. print(f" ✗ 读取文件失败: {e}")
  83. else:
  84. print("✗ pyproject.toml 缺失 - 可能导致项目识别问题")
  85. # 检查setup.py
  86. setup_path = project_root / "setup.py"
  87. if setup_path.exists():
  88. print("✓ setup.py 存在 - 提供向后兼容性")
  89. else:
  90. print("✗ setup.py 缺失 - 可能影响旧版本工具识别")
  91. # 检查.cursorrules
  92. cursorrules_path = project_root / ".cursorrules"
  93. if cursorrules_path.exists():
  94. print("✓ .cursorrules 存在 - Cursor编辑器配置")
  95. else:
  96. print("✗ .cursorrules 缺失 - Cursor编辑器配置不完整")
  97. # 检查.vscode配置
  98. vscode_dir = project_root / ".vscode"
  99. if vscode_dir.exists():
  100. print("✓ .vscode 目录存在 - 工作区配置")
  101. settings_path = vscode_dir / "settings.json"
  102. if settings_path.exists():
  103. print(" ✓ settings.json 存在")
  104. else:
  105. print(" ✗ settings.json 缺失")
  106. launch_path = vscode_dir / "launch.json"
  107. if launch_path.exists():
  108. print(" ✓ launch.json 存在")
  109. else:
  110. print(" ✗ launch.json 缺失")
  111. else:
  112. print("✗ .vscode 目录缺失 - 工作区配置不完整")
  113. print()
  114. def check_dependencies():
  115. """检查依赖配置"""
  116. print("=" * 60)
  117. print("依赖配置检查")
  118. print("=" * 60)
  119. project_root = Path(__file__).parent
  120. requirements_path = project_root / "requirements.txt"
  121. if requirements_path.exists():
  122. print("✓ requirements.txt 存在")
  123. try:
  124. with open(requirements_path, 'r', encoding='utf-8') as f:
  125. lines = f.readlines()
  126. flask_deps = [line for line in lines if 'flask' in line.lower()]
  127. if flask_deps:
  128. print(f" ✓ 包含Flask依赖: {len(flask_deps)} 个")
  129. else:
  130. print(" ✗ 缺少Flask依赖")
  131. except Exception as e:
  132. print(f" ✗ 读取文件失败: {e}")
  133. else:
  134. print("✗ requirements.txt 缺失")
  135. # 检查虚拟环境
  136. venv_path = project_root / "venv"
  137. if venv_path.exists():
  138. print("✓ 虚拟环境存在")
  139. python_exe = venv_path / "Scripts" / "python.exe" if os.name == 'nt' else venv_path / "bin" / "python"
  140. if python_exe.exists():
  141. print(" ✓ 虚拟环境Python可执行文件存在")
  142. else:
  143. print(" ✗ 虚拟环境Python可执行文件缺失")
  144. else:
  145. print("✗ 虚拟环境不存在 - 需要创建")
  146. print()
  147. def generate_cursor_workspace():
  148. """生成Cursor工作区文件"""
  149. print("=" * 60)
  150. print("生成Cursor工作区文件")
  151. print("=" * 60)
  152. project_root = Path(__file__).parent
  153. workspace_path = project_root / "DataOps-platform.code-workspace"
  154. workspace_config = {
  155. "folders": [
  156. {
  157. "name": "DataOps Platform",
  158. "path": "."
  159. }
  160. ],
  161. "settings": {
  162. "python.defaultInterpreterPath": "./venv/Scripts/python.exe",
  163. "python.terminal.activateEnvironment": True,
  164. "python.linting.enabled": True,
  165. "python.linting.flake8Enabled": True,
  166. "python.formatting.provider": "black",
  167. "python.testing.pytestEnabled": True,
  168. "python.testing.pytestArgs": ["tests"],
  169. "files.exclude": {
  170. "**/__pycache__": True,
  171. "**/*.pyc": True,
  172. "**/venv": True,
  173. "**/.git": True
  174. },
  175. "search.exclude": {
  176. "**/venv": True,
  177. "**/__pycache__": True,
  178. "**/*.pyc": True
  179. }
  180. },
  181. "extensions": {
  182. "recommendations": [
  183. "ms-python.python",
  184. "ms-python.flake8",
  185. "ms-python.black-formatter",
  186. "ms-python.mypy-type-checker",
  187. "ms-python.pytest-adapter"
  188. ]
  189. }
  190. }
  191. try:
  192. with open(workspace_path, 'w', encoding='utf-8') as f:
  193. json.dump(workspace_config, f, indent=2, ensure_ascii=False)
  194. print(f"✓ 工作区文件已生成: {workspace_path}")
  195. print(" 现在可以使用 'File > Open Workspace from File...' 打开此文件")
  196. except Exception as e:
  197. print(f"✗ 生成工作区文件失败: {e}")
  198. print()
  199. def main():
  200. """主函数"""
  201. print("DataOps Platform 项目状态检查工具")
  202. print("用于诊断Cursor项目识别问题")
  203. print()
  204. check_python_environment()
  205. check_project_structure()
  206. check_cursor_compatibility()
  207. check_dependencies()
  208. generate_cursor_workspace()
  209. print("=" * 60)
  210. print("检查完成!")
  211. print("=" * 60)
  212. print()
  213. print("如果发现问题,请按照以下步骤操作:")
  214. print("1. 运行 run_project.bat 创建虚拟环境并安装依赖")
  215. print("2. 使用 'File > Open Workspace from File...' 打开 .code-workspace 文件")
  216. print("3. 或者直接使用 'File > Open Folder...' 打开项目目录")
  217. print("4. 确保Cursor使用正确的Python解释器(虚拟环境中的Python)")
  218. print()
  219. print("如果问题仍然存在,请检查:")
  220. print("- Python版本是否为3.8+")
  221. print("- 是否有足够的磁盘空间")
  222. print("- 防火墙设置是否阻止了端口访问")
  223. print("- 系统环境变量是否正确设置")
  224. if __name__ == "__main__":
  225. main()