Update with last fixes

This commit is contained in:
Alexey Dudin
2026-11-11 18:43:40 +03:00
parent 53980a5558
commit 58cc8090a9
24 changed files with 832 additions and 50 deletions
+54
View File
@@ -0,0 +1,54 @@
"""Регрессия: в установленный пакет (Docker-образ, wheel) должны попасть шаблоны и статика админки,
встроенные фрагменты и стили. Раньше package-data включал только builtin/."""
import fnmatch
import glob
import shutil
import subprocess
import sys
import tempfile
import tomllib
import unittest
import zipfile
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
PKG = ROOT / "src" / "site_engine"
class PackagingTest(unittest.TestCase):
def test_package_data_patterns_cover_every_runtime_file(self):
patterns = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8"))["tool"]["setuptools"]["package-data"]["site_engine"]
runtime = [p for sub in ("builtin", "web/admin/templates", "web/admin/static") for p in (PKG / sub).rglob("*")
if p.is_file() and p.suffix != ".pyc" and "__pycache__" not in p.parts]
self.assertGreater(len(runtime), 50)
uncovered = [str(p.relative_to(PKG)) for p in runtime
if not any(fnmatch.fnmatch(p.relative_to(PKG).as_posix(), pat.replace("**/*", "*")) for pat in patterns)]
self.assertEqual(uncovered, [])
def test_built_wheel_contains_templates_static_and_fragments(self):
try:
import setuptools # noqa: F401
except ImportError:
self.skipTest("нет setuptools")
before = {name: (ROOT / name).exists() for name in ("build", "src/site_engine.egg-info")}
with tempfile.TemporaryDirectory() as tmp:
project = Path(tmp) / "project"
shutil.copytree(ROOT, project, ignore=shutil.ignore_patterns(
"build", "*.egg-info", "__pycache__", ".git", "tests", "docs", "examples", "dist", ".engine"))
result = subprocess.run([sys.executable, "-m", "pip", "wheel", str(project), "--no-deps", "--no-build-isolation",
"-q", "-w", str(Path(tmp) / "out")], capture_output=True, text=True, timeout=180)
wheels = glob.glob(f"{tmp}/out/*.whl")
if result.returncode != 0 or not wheels:
self.skipTest(f"wheel не собрался в этом окружении: {result.stderr[-200:]}")
names = zipfile.ZipFile(wheels[0]).namelist()
after = {name: (ROOT / name).exists() for name in before}
self.assertEqual(after, before, "сборка wheel не должна оставлять мусор в рабочем каталоге")
for needed in ("site_engine/web/admin/templates/login.html.j2", "site_engine/web/admin/templates/page_edit.html.j2",
"site_engine/web/admin/static/admin.css", "site_engine/builtin/base.css",
"site_engine/builtin/fragments/hero/template.html.j2"):
self.assertIn(needed, names)
if __name__ == "__main__":
unittest.main()