From 79342e7341abf42ef6aeb1ab2f3e1c0c11f1d042 Mon Sep 17 00:00:00 2001 From: Pavel Kuznetsov Date: Sat, 7 Nov 2026 12:17:52 +0200 Subject: [PATCH 1/2] fix(release): omit generated Python bytecode and tool caches from source ZIP --- scripts/build_release.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts/build_release.py b/scripts/build_release.py index c0b77ac..c91ffb6 100644 --- a/scripts/build_release.py +++ b/scripts/build_release.py @@ -14,10 +14,24 @@ def main(version): if not re.fullmatch(r"\d+\.\d+\.\d+", version): raise SystemExit("Expected GitVersion MajorMinorPatch.") source = ROOT / "filamentra" - paths = sorted((p for p in source.rglob("*") if p.is_file()), - key=lambda p: p.relative_to(ROOT).as_posix()) - if not paths or any(p.is_symlink() for p in paths): - raise SystemExit("Missing or unsafe Filamentra source.") + # The unit tests import Filamentra before packaging, creating local __pycache__. + # Do not ship machine-specific bytecode or test/tool caches with the source ZIP. + ignored_dirs = {"__pycache__", ".pytest_cache", ".mypy_cache", ".ruff_cache"} + ignored_suffixes = {".pyc", ".pyo"} + paths = [] + for path in source.rglob("*"): + if path.is_symlink(): + raise SystemExit("Unsafe Filamentra source symlink: " + str(path)) + if not path.is_file(): + continue + relative = path.relative_to(source) + if (any(part in ignored_dirs for part in relative.parts) + or path.suffix in ignored_suffixes or path.name == ".DS_Store"): + continue + paths.append(path) + paths.sort(key=lambda path: path.relative_to(ROOT).as_posix()) + if not paths: + raise SystemExit("Missing Filamentra source.") out = ROOT / "dist" out.mkdir(exist_ok=True) target = out / f"Filamentra-{version}.zip" From 71730a40ca7c8236965b821d956feff986f3b833 Mon Sep 17 00:00:00 2001 From: Pavel Kuznetsov Date: Sat, 7 Nov 2026 12:18:04 +0200 Subject: [PATCH 2/2] test(release): verify source ZIP ignores generated Python and CI caches --- tests/test_release_package.py | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/test_release_package.py diff --git a/tests/test_release_package.py b/tests/test_release_package.py new file mode 100644 index 0000000..74edfdf --- /dev/null +++ b/tests/test_release_package.py @@ -0,0 +1,63 @@ +"""Regression tests for reproducible Filamentra runtime-source distributions.""" +import hashlib +import importlib.util +from pathlib import Path +import tempfile +import unittest +import zipfile + + +ROOT = Path(__file__).resolve().parents[1] +SPEC = importlib.util.spec_from_file_location("filamentra_release_builder", + ROOT / "scripts" / "build_release.py") +builder = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(builder) + + +class ReleasePackageTests(unittest.TestCase): + def test_generated_bytecode_and_tool_cache_do_not_change_archive(self): + with tempfile.TemporaryDirectory() as temp: + root = Path(temp) + source = root / "filamentra" + source.mkdir() + (source / "__init__.py").write_text('"""Package."""\n', encoding="utf-8") + assets = source / "assets" + assets.mkdir() + (assets / "profile.json").write_text('{"color": "blue"}\n', encoding="utf-8") + + previous_root = builder.ROOT + try: + builder.ROOT = root + builder.main("1.2.3") + archive = root / "dist" / "Filamentra-1.2.3.zip" + original = archive.read_bytes() + + # Python tests and tooling can generate these after checkout. + cache = source / "__pycache__" + cache.mkdir() + (cache / "__init__.cpython-312.pyc").write_bytes(b"binary cache") + (source / "stray.pyc").write_bytes(b"bytecode") + (source / ".DS_Store").write_bytes(b"Finder metadata") + ruff = source / ".ruff_cache" + ruff.mkdir() + (ruff / "state").write_text("tool output", encoding="utf-8") + pytest = source / ".pytest_cache" + pytest.mkdir() + (pytest / "README.md").write_text("test output", encoding="utf-8") + builder.main("1.2.3") + + self.assertEqual(archive.read_bytes(), original) + with zipfile.ZipFile(archive) as zipped: + self.assertEqual(sorted(zipped.namelist()), [ + "filamentra/__init__.py", "filamentra/assets/profile.json", + "release.json", + ]) + checksum = archive.with_suffix(".zip.sha256").read_text(encoding="ascii") + self.assertEqual(checksum, + hashlib.sha256(original).hexdigest() + " " + archive.name + "\n") + finally: + builder.ROOT = previous_root + + +if __name__ == "__main__": + unittest.main()