bot / setup_checks.py
teslatony's picture
Create setup_checks.py
672ebf4 verified
raw
history blame
2.97 kB
<<<ФАЙЛ: setup_checks.py>>>
# FILE: setup_checks.py
import sys
import subprocess
import pkg_resources
import importlib
import traceback
from pathlib import Path
REQUIREMENTS_FILE = Path("requirements.txt")
def check_python_version():
if sys.version_info < (3, 10):
print(f"[ERROR] Python 3.10+ требуется, текущая версия: {sys.version}")
return False
print(f"[OK] Python версия {sys.version_info.major}.{sys.version_info.minor}")
return True
def check_dependencies():
print("[INFO] Проверка зависимостей из requirements.txt...")
if not REQUIREMENTS_FILE.exists():
print("[ERROR] requirements.txt не найден!")
return False
with REQUIREMENTS_FILE.open("r", encoding="utf-8") as f:
reqs = [line.strip() for line in f if line.strip() and not line.startswith("#")]
ok = True
for r in reqs:
try:
pkg_resources.require(r)
print(f"[OK] {r}")
except pkg_resources.DistributionNotFound:
print(f"[ERROR] Пакет не установлен: {r}")
ok = False
except pkg_resources.VersionConflict as e:
print(f"[ERROR] Конфликт версии: {e}")
ok = False
return ok
def run_static_analysis():
print("[INFO] Запуск flake8 и mypy...")
ok = True
try:
subprocess.run(["flake8", "--max-line-length=120"], check=True)
subprocess.run(["mypy", "."], check=True)
except subprocess.CalledProcessError:
ok = False
return ok
def smoke_test_app():
print("[INFO] Выполняем smoke-test app.py...")
ok = True
try:
app_module = importlib.import_module("app")
if not hasattr(app_module, "mock_predict"):
print("[ERROR] В app.py отсутствует mock_predict()")
ok = False
else:
test_result = app_module.mock_predict("Тест")
if not isinstance(test_result, str):
print("[ERROR] mock_predict() вернул не строку")
ok = False
else:
print("[OK] mock_predict() успешно работает")
except Exception:
print("[ERROR] Ошибка при импорте app.py:")
traceback.print_exc()
ok = False
return ok
def main():
success = True
if not check_python_version():
success = False
if not check_dependencies():
success = False
if not run_static_analysis():
print("[WARNING] Статический анализ выявил проблемы")
if not smoke_test_app():
success = False
if success:
print("[SUCCESS] Все проверки пройдены")
sys.exit(0)
else:
print("[FAIL] Обнаружены критические ошибки")
sys.exit(1)
if __name__ == "__main__":
main()