diff --git a/scripts/verify_python_distribution.py b/scripts/verify_python_distribution.py index caa89d33..a7497fe2 100644 --- a/scripts/verify_python_distribution.py +++ b/scripts/verify_python_distribution.py @@ -41,6 +41,18 @@ MINIMUM_MCP_VERSION = Version("1.29") UNSUPPORTED_MCP_VERSION = Version("2") SUPPORTED_PYTHON_VERSIONS = (Version("3.12"), Version("3.13"), Version("3.14")) +PRODUCT_TOP_LEVEL_PACKAGES = frozenset( + { + "app_server", + "cli", + "core", + "eval", + "prompts", + "tools", + "utils", + "workflows", + } +) class DistributionVerificationError(RuntimeError): @@ -234,6 +246,22 @@ def _single_artifact(dist_dir: Path, pattern: str, label: str) -> Path: return candidates[0].resolve() +def verify_wheel_packages(names: list[str], *, source: Path) -> None: + """Reject working-tree packages that are not part of the release surface.""" + + packages = { + name.split("/", 1)[0] + for name in names + if name.endswith("/__init__.py") and "/" in name + } + unexpected = sorted(packages - PRODUCT_TOP_LEVEL_PACKAGES) + if unexpected: + raise DistributionVerificationError( + f"{source} contains packages outside the product allowlist: " + + ", ".join(unexpected) + ) + + def verify_artifacts( dist_dir: Path, *, @@ -260,6 +288,7 @@ def verify_artifacts( source=sdist, ) with zipfile.ZipFile(wheel) as archive: + verify_wheel_packages(archive.namelist(), source=wheel) verify_web_assets( archive.read, archive.namelist(), "app_server/web_assets/", expected_version ) diff --git a/setup.py b/setup.py index 6d5b85c3..fcfa77e2 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,19 @@ REPOSITORY = "https://github.com/HKUDS/DeepCode" +# Packaging runs against a developer's working tree, not just the tracked files, so keep +# the release surface explicit: ignored experiments or local helper directories at the +# repository root must never enter a wheel. +PRODUCT_PACKAGES = ( + "app_server*", + "cli*", + "core*", + "eval*", + "prompts*", + "tools*", + "utils*", + "workflows*", +) # Markdown links whose target is relative: ](docs/x.md), ](#anchor), ](LICENSE). _RELATIVE_LINK = re.compile(r"\]\((?![a-z][a-z0-9+.-]*:|//)([^)\s]+)\)", re.IGNORECASE) @@ -72,9 +85,7 @@ def read_requirements(): ), long_description=long_description, long_description_content_type="text/markdown", - packages=setuptools.find_packages( - exclude=("tests*", "docs*", ".history*", ".git*", ".ruff_cache*") - ), + packages=setuptools.find_packages(include=PRODUCT_PACKAGES), py_modules=["deepcode"], classifiers=[ "Development Status :: 4 - Beta", diff --git a/tests/test_python_distribution_release.py b/tests/test_python_distribution_release.py index 9dc452de..6e3e080f 100644 --- a/tests/test_python_distribution_release.py +++ b/tests/test_python_distribution_release.py @@ -114,6 +114,33 @@ def test_packaged_web_manifest_requires_its_entry_assets(): release.verify_web_assets(files.__getitem__, list(files), "web/", "2.2.0") +def test_wheel_package_allowlist_accepts_product_packages(tmp_path): + release.verify_wheel_packages( + [ + "app_server/__init__.py", + "cli/__init__.py", + "core/application/__init__.py", + "deepcode.py", + ], + source=tmp_path / "artifact.whl", + ) + + +def test_wheel_package_allowlist_rejects_working_tree_experiments(tmp_path): + with pytest.raises( + release.DistributionVerificationError, + match="quant_trading", + ): + release.verify_wheel_packages( + [ + "core/__init__.py", + "quant_trading/__init__.py", + "game_theory_arsenal/__init__.py", + ], + source=tmp_path / "artifact.whl", + ) + + def test_smoke_failure_reports_output_that_the_reader_cannot_decode(tmp_path): """A rejected byte used to wipe out the whole diagnostic.