/
Chaizee
/
ZenithCode_Incident-LLM-analytics
Обзор
Документация
Войти
/
Chaizee
/
ZenithCode_Incident-LLM-analytics
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
scripts/verify_project.py
147 строк
4 KB
Chaizee
fix: fix speed
12 июн 2026, 16:28
12 июн 2026, 16:28
b2745cc
Код
Авторство
О чём код?
#!/usr/bin/env python3 from __future__ import annotations import ast import compileall import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent SKIP_DIRS = {".venv", "venv", "__pycache__", ".git"} if str(ROOT) not in sys.path: sys.path.insert(0, str(ROOT)) def _py_files() -> list[Path]: out: list[Path] = [] for path in ROOT.rglob("*.py"): if any(part in SKIP_DIRS for part in path.parts): continue out.append(path) return sorted(out) def _check_future_imports(path: Path, source: str) -> list[str]: errors: list[str] = [] lines = source.splitlines() seen_non_future = False for i, line in enumerate(lines, 1): stripped = line.strip() if not stripped or stripped.startswith("#"): continue if stripped.startswith("from __future__ import"): if seen_non_future: errors.append(f"{path}:{i}: from __future__ must be at file start") continue if stripped.startswith(('"""', "'''")) and not seen_non_future: continue seen_non_future = True return errors def _check_legacy_files() -> list[str]: errors: list[str] = [] legacy = [ ROOT / "config.py", ROOT / "src" / "data.py", ROOT / "llm.py", ROOT / "src" / "pipeline.py", ROOT / "src" / "geo_map.py", ROOT / "src" / "geo_coords.py", ROOT / "src" / "chatbot.py", ROOT / "src" / "settings.py", ROOT / "scripts" / "strip_comments.py", ROOT / "requirements_hybrid.txt", ] for path in legacy: if path.is_file(): errors.append(f"legacy file must be removed: {path.relative_to(ROOT)}") init_py = ROOT / "config" / "__init__.py" if init_py.is_file(): text = init_py.read_text(encoding="utf-8") if text.count("from __future__ import") > 0: errors.append("config/__init__.py must not contain from __future__ (use config/settings.py)") if len(text.splitlines()) > 5: errors.append("config/__init__.py must only re-export config.settings") return errors def _check_config_exports() -> list[str]: errors: list[str] = [] try: from config import ( # noqa: PLC0415 APP_ICON, APP_TITLE, EXCEL_COLUMN_MAP, EXCEL_HEADERS, ROOT as PROJECT_ROOT, USE_GPU, ) except Exception as exc: return [f"config import failed: {exc}"] if PROJECT_ROOT != ROOT: errors.append(f"config.ROOT mismatch: {PROJECT_ROOT} != {ROOT}") for name in ("EXCEL_COLUMN_MAP", "EXCEL_HEADERS", "APP_TITLE", "APP_ICON", "USE_GPU"): if name not in dir(): errors.append(f"config missing export: {name}") return errors def _check_app_imports() -> list[str]: errors: list[str] = [] modules = ( "app", "src.data_polars", "src.pipeline_hybrid", "src.ui_results", "src.ml_classifier", "src.local_llm", ) for mod in modules: try: __import__(mod) except ModuleNotFoundError as exc: optional = { "polars", "pandas", "streamlit", "torch", "torchvision", "loguru", "joblib", "numpy", "sklearn", "sentence_transformers", "xgboost", "llama_cpp", "geopandas", "folium", "plotly", "openpyxl", } if exc.name in optional: continue errors.append(f"import {mod}: {exc}") except ImportError as exc: errors.append(f"import {mod}: {exc}") return errors def main() -> int: errors: list[str] = [] errors.extend(_check_legacy_files()) for path in _py_files(): source = path.read_text(encoding="utf-8") errors.extend(_check_future_imports(path, source)) try: ast.parse(source, filename=str(path)) except SyntaxError as exc: errors.append(f"syntax error {path}: {exc}") if not compileall.compile_dir(str(ROOT), quiet=1): errors.append("compileall failed") errors.extend(_check_config_exports()) errors.extend(_check_app_imports()) if errors: print("PROJECT CHECK FAILED:") for err in errors: print(f" - {err}") return 1 print("PROJECT CHECK OK") return 0 if __name__ == "__main__": raise SystemExit(main())