teslatony commited on
Commit
672ebf4
·
verified ·
1 Parent(s): 2616b1a

Create setup_checks.py

Browse files
Files changed (1) hide show
  1. setup_checks.py +91 -0
setup_checks.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <<<ФАЙЛ: setup_checks.py>>>
2
+ # FILE: setup_checks.py
3
+ import sys
4
+ import subprocess
5
+ import pkg_resources
6
+ import importlib
7
+ import traceback
8
+ from pathlib import Path
9
+
10
+ REQUIREMENTS_FILE = Path("requirements.txt")
11
+
12
+ def check_python_version():
13
+ if sys.version_info < (3, 10):
14
+ print(f"[ERROR] Python 3.10+ требуется, текущая версия: {sys.version}")
15
+ return False
16
+ print(f"[OK] Python версия {sys.version_info.major}.{sys.version_info.minor}")
17
+ return True
18
+
19
+ def check_dependencies():
20
+ print("[INFO] Проверка зависимостей из requirements.txt...")
21
+ if not REQUIREMENTS_FILE.exists():
22
+ print("[ERROR] requirements.txt не найден!")
23
+ return False
24
+
25
+ with REQUIREMENTS_FILE.open("r", encoding="utf-8") as f:
26
+ reqs = [line.strip() for line in f if line.strip() and not line.startswith("#")]
27
+
28
+ ok = True
29
+ for r in reqs:
30
+ try:
31
+ pkg_resources.require(r)
32
+ print(f"[OK] {r}")
33
+ except pkg_resources.DistributionNotFound:
34
+ print(f"[ERROR] Пакет не установлен: {r}")
35
+ ok = False
36
+ except pkg_resources.VersionConflict as e:
37
+ print(f"[ERROR] Конфликт версии: {e}")
38
+ ok = False
39
+ return ok
40
+
41
+ def run_static_analysis():
42
+ print("[INFO] Запуск flake8 и mypy...")
43
+ ok = True
44
+ try:
45
+ subprocess.run(["flake8", "--max-line-length=120"], check=True)
46
+ subprocess.run(["mypy", "."], check=True)
47
+ except subprocess.CalledProcessError:
48
+ ok = False
49
+ return ok
50
+
51
+ def smoke_test_app():
52
+ print("[INFO] Выполняем smoke-test app.py...")
53
+ ok = True
54
+ try:
55
+ app_module = importlib.import_module("app")
56
+ if not hasattr(app_module, "mock_predict"):
57
+ print("[ERROR] В app.py отсутствует mock_predict()")
58
+ ok = False
59
+ else:
60
+ test_result = app_module.mock_predict("Тест")
61
+ if not isinstance(test_result, str):
62
+ print("[ERROR] mock_predict() вернул не строку")
63
+ ok = False
64
+ else:
65
+ print("[OK] mock_predict() успешно работает")
66
+ except Exception:
67
+ print("[ERROR] Ошибка при импорте app.py:")
68
+ traceback.print_exc()
69
+ ok = False
70
+ return ok
71
+
72
+ def main():
73
+ success = True
74
+ if not check_python_version():
75
+ success = False
76
+ if not check_dependencies():
77
+ success = False
78
+ if not run_static_analysis():
79
+ print("[WARNING] Статический анализ выявил проблемы")
80
+ if not smoke_test_app():
81
+ success = False
82
+
83
+ if success:
84
+ print("[SUCCESS] Все проверки пройдены")
85
+ sys.exit(0)
86
+ else:
87
+ print("[FAIL] Обнаружены критические ошибки")
88
+ sys.exit(1)
89
+
90
+ if __name__ == "__main__":
91
+ main()