Skip to content

Commit 5f5d90e

Browse files
authored
upload-pypi: allow dry running the script with a dev version (#9886)
Co-authored-by: hauntsaninja <>
1 parent cfdb1f1 commit 5f5d90e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

misc/upload-pypi.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,15 @@ def check_sdist(dist: Path, version: str) -> None:
5959
with tarfile.open(sdist) as f:
6060
version_py = f.extractfile(f"{sdist.name[:-len('.tar.gz')]}/mypy/version.py")
6161
assert version_py is not None
62-
assert f"'{version}'" in version_py.read().decode("utf-8")
62+
version_py_contents = version_py.read().decode("utf-8")
63+
64+
# strip a git hash from our version, if necessary, since that's not present in version.py
65+
match = re.match(r"(.*\+dev).*$", version)
66+
hashless_version = match.group(1) if match else version
67+
68+
assert (
69+
f"'{hashless_version}'" in version_py_contents
70+
), "Version does not match version.py in sdist"
6371

6472

6573
def spot_check_dist(dist: Path, version: str) -> None:
@@ -92,7 +100,11 @@ def upload_dist(dist: Path, dry_run: bool = True) -> None:
92100

93101

94102
def upload_to_pypi(version: str, dry_run: bool = True) -> None:
95-
assert re.match(r"0\.[0-9]{3}$", version)
103+
assert re.match(r"v?0\.[0-9]{3}(\+\S+)?$", version)
104+
if "dev" in version:
105+
assert dry_run, "Must use --dry-run with dev versions of mypy"
106+
if version.startswith("v"):
107+
version = version[1:]
96108

97109
target_dir = tempfile.mkdtemp()
98110
dist = Path(target_dir) / "dist"

0 commit comments

Comments
 (0)