import pathlib
import re
import sys
def version_in(path: str) -> str:
text = pathlib.Path(path).read_text(encoding="utf-8")
match = re.search(r'^version\s*=\s*"([^"]+)"', text, re.M)
if not match:
sys.exit(f"{path}: no version field found")
return match.group(1)
def main() -> None:
cargo = version_in("Cargo.toml")
pyproject = version_in("pyproject.toml")
print(f"Cargo.toml {cargo}")
print(f"pyproject.toml {pyproject}")
if cargo != pyproject:
sys.exit(
f"\nversion mismatch: Cargo.toml={cargo}, pyproject.toml={pyproject}\n"
"Bump both together, or the crate and the wheel ship as different "
"versions of the same release."
)
tag = sys.argv[1] if len(sys.argv) > 1 else None
if tag:
want = tag[1:] if tag.startswith("v") else tag
print(f"git tag {tag}")
if want != cargo:
sys.exit(
f"\ntag {tag} does not match the manifests ({cargo}).\n"
"The tag names the release; the manifests decide what is "
"actually published. Publishing them apart puts the wrong "
"number on the artifacts, permanently."
)
print("consistent.")
if __name__ == "__main__":
main()