Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions scripts/verify_python_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
*,
Expand All @@ -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
)
Expand Down
17 changes: 14 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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",
Expand Down
27 changes: 27 additions & 0 deletions tests/test_python_distribution_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading