From 5f5d90eee23b809185145f6da7b18a3ca41b4879 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Wed, 6 Jan 2021 23:16:40 -0800 Subject: [PATCH] upload-pypi: allow dry running the script with a dev version (#9886) Co-authored-by: hauntsaninja <> --- misc/upload-pypi.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/misc/upload-pypi.py b/misc/upload-pypi.py index 7aa9553cf4f8..ad244a547ddb 100644 --- a/misc/upload-pypi.py +++ b/misc/upload-pypi.py @@ -59,7 +59,15 @@ def check_sdist(dist: Path, version: str) -> None: with tarfile.open(sdist) as f: version_py = f.extractfile(f"{sdist.name[:-len('.tar.gz')]}/mypy/version.py") assert version_py is not None - assert f"'{version}'" in version_py.read().decode("utf-8") + version_py_contents = version_py.read().decode("utf-8") + + # strip a git hash from our version, if necessary, since that's not present in version.py + match = re.match(r"(.*\+dev).*$", version) + hashless_version = match.group(1) if match else version + + assert ( + f"'{hashless_version}'" in version_py_contents + ), "Version does not match version.py in sdist" def spot_check_dist(dist: Path, version: str) -> None: @@ -92,7 +100,11 @@ def upload_dist(dist: Path, dry_run: bool = True) -> None: def upload_to_pypi(version: str, dry_run: bool = True) -> None: - assert re.match(r"0\.[0-9]{3}$", version) + assert re.match(r"v?0\.[0-9]{3}(\+\S+)?$", version) + if "dev" in version: + assert dry_run, "Must use --dry-run with dev versions of mypy" + if version.startswith("v"): + version = version[1:] target_dir = tempfile.mkdtemp() dist = Path(target_dir) / "dist"