feat: daedalus publish - guarded PyPI release (v0.12.0)
- new script python/src/publish/publish.py: guards (clean tree, HEAD exactly tagged v<version>, version not yet on PyPI, build+twine present), then the chained python -m build (the sdist must rebuild the wheel, SPEC 9.2.1) and twine check; --upload sends exactly this version's sdist+wheel, credentials stay with twine (~/.pypirc or prompt, __token__) - spec python/src/publish/spec.md (sections 1-7) first, then tests (13) in python/tests/test_publish.py, then code (SPEC 6.12) - fix release-blocking sdist defect (SPEC 9.2.1): empty powershell/ and batch/ folders now carry README placeholders and MANIFEST.in ships them, so an sdist installs again - release tooling in requirements.txt; registry entry, README row + section, CHANGELOG 0.12.0, version pins Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -34,7 +34,7 @@ def test_app_version_falls_back_to_pyproject(monkeypatch):
|
||||
raise hello.importlib.metadata.PackageNotFoundError(_name)
|
||||
|
||||
monkeypatch.setattr(hello.importlib.metadata, "version", not_found)
|
||||
assert hello.app_version() == "0.11.0"
|
||||
assert hello.app_version() == "0.12.0"
|
||||
|
||||
|
||||
def test_help_exits_zero(capsys):
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
"""Tests for the publish script: guarded PyPI release (publish spec).
|
||||
|
||||
No network, no git state, no real build: every guard and step runs
|
||||
through an injected runner and an injectable PyPI status fetch
|
||||
(daedalus agent rule 5.6, publish spec item 6.1).
|
||||
"""
|
||||
import re
|
||||
|
||||
from daedalus.publish import publish
|
||||
|
||||
|
||||
def make_runner(script, calls=None):
|
||||
"""Build an injectable run_cmd(cmd, cwd) from {prefix: (code, out)}."""
|
||||
|
||||
def run_cmd(cmd, cwd=None):
|
||||
if calls is not None:
|
||||
calls.append((list(cmd), cwd))
|
||||
for prefix, reply in script.items():
|
||||
if list(cmd)[:len(prefix)] == list(prefix):
|
||||
return reply
|
||||
raise AssertionError(f"unexpected command: {cmd}")
|
||||
|
||||
return run_cmd
|
||||
|
||||
|
||||
def clean_runner(version, calls=None):
|
||||
"""A runner with all guards green for `version`."""
|
||||
py = publish.PY
|
||||
return make_runner({
|
||||
("git", "status"): (0, ""),
|
||||
("git", "describe"): (0, f"v{version}\n"),
|
||||
(py, "-m", "build", "--version"): (0, "build 1.6.1\n"),
|
||||
(py, "-m", "twine", "--version"): (0, "twine 7.0.0\n"),
|
||||
(py, "-m", "build"): (0, "Successfully built\n"),
|
||||
(py, "-m", "twine", "check"): (0, "PASSED\n"),
|
||||
(py, "-m", "twine", "upload"): (0, "Uploaded\n"),
|
||||
}, calls)
|
||||
|
||||
|
||||
# --- pyproject discovery (publish spec items 3.1-3.2)
|
||||
|
||||
|
||||
def test_read_project_from_this_repo():
|
||||
"""The script's own repo resolves: name daedalus, semver version."""
|
||||
root = publish.find_repo_root()
|
||||
assert root is not None
|
||||
name, version = publish.read_project(root / "pyproject.toml")
|
||||
assert name == "daedalus"
|
||||
assert re.fullmatch(r"\d+\.\d+\.\d+", version)
|
||||
|
||||
|
||||
# --- guards (publish spec item 3.3)
|
||||
|
||||
|
||||
def test_dirty_tree_stops_before_building():
|
||||
"""A dirty tree is exit 3; no build runs."""
|
||||
name, version = publish.read_project(
|
||||
publish.find_repo_root() / "pyproject.toml")
|
||||
calls = []
|
||||
runner = make_runner({("git", "status"): (0, " M file\n")}, calls)
|
||||
args = publish.parse_args([])
|
||||
assert publish.cmd_publish(args, runner,
|
||||
lambda _u: 404) == 3
|
||||
assert not any(cmd[0] == "git" and cmd[1] == "describe"
|
||||
or cmd[1:3] == ["-m", "build"]
|
||||
for cmd, _cwd in calls)
|
||||
|
||||
|
||||
def test_tag_mismatch_stops():
|
||||
"""HEAD tagged with another version is exit 4."""
|
||||
calls = []
|
||||
runner = make_runner({
|
||||
("git", "status"): (0, ""),
|
||||
("git", "describe"): (0, "v0.0.1\n"),
|
||||
}, calls)
|
||||
args = publish.parse_args([])
|
||||
assert publish.cmd_publish(args, runner,
|
||||
lambda _u: 404) == 4
|
||||
|
||||
|
||||
def test_tag_probe_failure_stops():
|
||||
"""An untagged HEAD (describe fails) is exit 4."""
|
||||
runner = make_runner({
|
||||
("git", "status"): (0, ""),
|
||||
("git", "describe"): (128, "no tag\n"),
|
||||
})
|
||||
assert publish.cmd_publish(publish.parse_args([]), runner,
|
||||
lambda _u: 404) == 4
|
||||
|
||||
|
||||
def repo_version():
|
||||
"""The version the checkout's pyproject carries."""
|
||||
_name, version = publish.read_project(
|
||||
publish.find_repo_root() / "pyproject.toml")
|
||||
return version
|
||||
|
||||
|
||||
def test_tooling_missing_stops():
|
||||
"""No build/twine in the interpreter is exit 5."""
|
||||
runner = make_runner({
|
||||
("git", "status"): (0, ""),
|
||||
("git", "describe"): (0, f"v{repo_version()}\n"),
|
||||
(publish.PY, "-m", "build", "--version"): (127, "no module"),
|
||||
(publish.PY, "-m", "twine", "--version"): (0, "twine\n"),
|
||||
})
|
||||
assert publish.cmd_publish(publish.parse_args([]), runner,
|
||||
lambda _u: 404) == 5
|
||||
|
||||
|
||||
def test_already_on_pypi_stops():
|
||||
"""A published version is exit 6 before any artifact is built."""
|
||||
calls = []
|
||||
runner = make_runner({
|
||||
("git", "status"): (0, ""),
|
||||
("git", "describe"): (0, f"v{repo_version()}\n"),
|
||||
(publish.PY, "-m", "build", "--version"): (0, "build\n"),
|
||||
(publish.PY, "-m", "twine", "--version"): (0, "twine\n"),
|
||||
}, calls)
|
||||
assert publish.cmd_publish(publish.parse_args([]), runner,
|
||||
lambda _u: 200) == 6
|
||||
assert not any(cmd[1:3] == ["-m", "build"] and len(cmd) == 3
|
||||
for cmd, _ in calls)
|
||||
|
||||
|
||||
def test_pypi_unreachable_stops():
|
||||
"""A blind publish is refused: unreachable PyPI is exit 6."""
|
||||
runner = make_runner({
|
||||
("git", "status"): (0, ""),
|
||||
("git", "describe"): (0, f"v{repo_version()}\n"),
|
||||
(publish.PY, "-m", "build", "--version"): (0, "build\n"),
|
||||
(publish.PY, "-m", "twine", "--version"): (0, "twine\n"),
|
||||
})
|
||||
assert publish.cmd_publish(publish.parse_args([]), runner,
|
||||
lambda _u: None) == 6
|
||||
|
||||
|
||||
# --- build, check, upload (publish spec items 3.4-3.7)
|
||||
|
||||
|
||||
def test_check_only_flow_builds_and_stops(tmp_path, capsys):
|
||||
"""Without --upload: chained build, twine check, exit 0."""
|
||||
name, version = publish.read_project(
|
||||
publish.find_repo_root() / "pyproject.toml")
|
||||
calls = []
|
||||
assert publish.cmd_publish(publish.parse_args([]),
|
||||
clean_runner(version, calls),
|
||||
lambda _u: 404) == 0
|
||||
build = [cmd for cmd, _ in calls
|
||||
if cmd[1:3] == ["-m", "build"] and len(cmd) == 3]
|
||||
assert len(build) == 1 # chained, not two runs
|
||||
assert not any(cmd[3:4] == ["upload"] for cmd, _ in calls)
|
||||
out = capsys.readouterr().out
|
||||
assert f"{name}-{version}.tar.gz" in out
|
||||
assert "--upload" in out # the next-step hint
|
||||
|
||||
|
||||
def test_upload_sends_exactly_this_version():
|
||||
"""--upload passes only this version's sdist and wheel."""
|
||||
name, version = publish.read_project(
|
||||
publish.find_repo_root() / "pyproject.toml")
|
||||
calls = []
|
||||
assert publish.cmd_publish(publish.parse_args(["--upload"]),
|
||||
clean_runner(version, calls),
|
||||
lambda _u: 404) == 0
|
||||
upload = [cmd for cmd, _ in calls if cmd[3:4] == ["upload"]][0]
|
||||
assert upload[-2] == f"dist/{name}-{version}.tar.gz"
|
||||
assert upload[-1].startswith(f"dist/{name}-{version}-")
|
||||
assert upload[-1].endswith(".whl")
|
||||
|
||||
|
||||
def test_build_failure_is_7():
|
||||
"""A failed chained build is exit 7."""
|
||||
name, version = publish.read_project(
|
||||
publish.find_repo_root() / "pyproject.toml")
|
||||
py = publish.PY
|
||||
runner = make_runner({
|
||||
("git", "status"): (0, ""),
|
||||
("git", "describe"): (0, f"v{version}\n"),
|
||||
(py, "-m", "build", "--version"): (0, "build\n"),
|
||||
(py, "-m", "twine", "--version"): (0, "twine\n"),
|
||||
(py, "-m", "build"): (1, "error\n"),
|
||||
})
|
||||
assert publish.cmd_publish(publish.parse_args([]), runner,
|
||||
lambda _u: 404) == 7
|
||||
|
||||
|
||||
def test_check_failure_is_8():
|
||||
"""twine check rejecting the artifacts is exit 8."""
|
||||
name, version = publish.read_project(
|
||||
publish.find_repo_root() / "pyproject.toml")
|
||||
py = publish.PY
|
||||
runner = make_runner({
|
||||
("git", "status"): (0, ""),
|
||||
("git", "describe"): (0, f"v{version}\n"),
|
||||
(py, "-m", "build", "--version"): (0, "build\n"),
|
||||
(py, "-m", "twine", "--version"): (0, "twine\n"),
|
||||
(py, "-m", "build"): (0, "ok\n"),
|
||||
(py, "-m", "twine", "check"): (1, "Failed\n"),
|
||||
})
|
||||
assert publish.cmd_publish(publish.parse_args([]), runner,
|
||||
lambda _u: 404) == 8
|
||||
|
||||
|
||||
def test_upload_failure_is_9():
|
||||
"""twine upload failing is exit 9."""
|
||||
name, version = publish.read_project(
|
||||
publish.find_repo_root() / "pyproject.toml")
|
||||
py = publish.PY
|
||||
runner = make_runner({
|
||||
("git", "status"): (0, ""),
|
||||
("git", "describe"): (0, f"v{version}\n"),
|
||||
(py, "-m", "build", "--version"): (0, "build\n"),
|
||||
(py, "-m", "twine", "--version"): (0, "twine\n"),
|
||||
(py, "-m", "build"): (0, "ok\n"),
|
||||
(py, "-m", "twine", "check"): (0, "PASSED\n"),
|
||||
(py, "-m", "twine", "upload"): (1, "403\n"),
|
||||
})
|
||||
assert publish.cmd_publish(publish.parse_args(["--upload"]), runner,
|
||||
lambda _u: 404) == 9
|
||||
|
||||
|
||||
def test_cli_wires_flow(monkeypatch):
|
||||
"""The CLI hands cmd_publish the real runner and fetch."""
|
||||
seen = {}
|
||||
|
||||
def fake_publish(args, run_cmd, fetch_status):
|
||||
seen["args"] = args
|
||||
seen["run_cmd"] = run_cmd
|
||||
seen["fetch"] = fetch_status
|
||||
return 0
|
||||
|
||||
monkeypatch.setattr(publish, "cmd_publish", fake_publish)
|
||||
assert publish.main(["--upload"]) == 0
|
||||
assert seen["args"].upload is True
|
||||
assert seen["run_cmd"] is publish.run_in_cwd
|
||||
assert seen["fetch"] is publish.pypi_status
|
||||
Reference in New Issue
Block a user