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
15 changes: 12 additions & 3 deletions stub_uploader/build_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from collections.abc import Iterable
from importlib.metadata import version as package_version
from pathlib import Path
from subprocess import CalledProcessError
from textwrap import dedent

from stub_uploader.const import (
Expand Down Expand Up @@ -134,6 +135,10 @@
""".strip()


class BuildError(Exception):
pass


class BuildData:
def __init__(self, typeshed_dir: str, distribution: str) -> None:
self.distribution = distribution
Expand Down Expand Up @@ -500,9 +505,13 @@ def main(
for package in ("build", "twine"):
print(f"{package}=={package_version(package)}")
print("\033[0m")
subprocess.run(
[sys.executable, "-m", "build", "--no-isolation"], cwd=tmpdir, check=False
)
try:
subprocess.run(
[sys.executable, "-m", "build", "--no-isolation"], cwd=tmpdir, check=True
)
except CalledProcessError as exc:
raise BuildError(f"Failed to build {distribution!r}: {exc}") from exc

return Path(tmpdir) / "dist"


Expand Down
2 changes: 1 addition & 1 deletion stub_uploader/ts_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def read_current_commit(self) -> str:
capture_output=True,
text=True,
cwd=self.typeshed_path,
check=False,
check=True,
).stdout.strip()


Expand Down
32 changes: 24 additions & 8 deletions stub_uploader/upload.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import annotations

import subprocess
from subprocess import CalledProcessError

from stub_uploader import build_wheel
from stub_uploader.build_wheel import BuildError
from stub_uploader.get_version import determine_stub_version
from stub_uploader.metadata import read_metadata, sort_by_dependency, uploaded_packages
from stub_uploader.update_changelog import update_changelog
Expand All @@ -14,17 +16,19 @@ def upload(
commit: str | None = None,
*,
dry_run: bool = False,
) -> None:
) -> bool:
to_upload = sort_by_dependency(typeshed_dir, distributions)
print("Building and uploading stubs for:", ", ".join(distributions))
print()
for distribution in to_upload:
return all(
upload_distribution(typeshed_dir, distribution, commit, dry_run=dry_run)
for distribution in to_upload
)


def upload_distribution(
typeshed_dir: str, distribution: str, commit: str | None, *, dry_run: bool
) -> None:
) -> bool:
print(f"Building stubs for {distribution}... ", end="")
metadata = read_metadata(typeshed_dir, distribution)
metadata.validate_dependencies_recursively(typeshed_dir)
Expand All @@ -34,14 +38,26 @@ def upload_distribution(
if commit:
update_changelog(typeshed_dir, commit, distribution, version, dry_run=dry_run)

temp_dir = build_wheel.main(typeshed_dir, distribution, version)
print(f"ok, version {version}")
try:
temp_dir = build_wheel.main(typeshed_dir, distribution, version)
except BuildError as exc:
print(f"error: {exc}")
print()
return False

print(f"Uploading stubs for {distribution}... ", end="")
if dry_run or not metadata.upload:
print("skipped")
else:
subprocess.run(["twine", "upload", str(temp_dir / "*")], check=True)
uploaded_packages.add(distribution)
print("ok")
try:
subprocess.run(["twine", "upload", str(temp_dir / "*")], check=True)
except CalledProcessError as exc:
print(f"error: {exc}")
print()
return False
else:
uploaded_packages.add(distribution)
print("ok")
print()

return True
8 changes: 5 additions & 3 deletions stub_uploader/upload_changed.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@

import argparse
import os
import sys

from stub_uploader import get_changed
from stub_uploader.upload import upload


def main(typeshed_dir: str, commit: str, dry_run: bool = False) -> None:
def main(typeshed_dir: str, commit: str, dry_run: bool = False) -> bool:
"""Upload stub typeshed packages modified since commit."""
changed = get_changed.main(typeshed_dir, commit)
# Ignore those distributions that were completely deleted.
current = set(os.listdir(os.path.join(typeshed_dir, "stubs")))
changed = [d for d in changed if d in current]
upload(typeshed_dir, changed, commit, dry_run=dry_run)
return upload(typeshed_dir, changed, commit, dry_run=dry_run)


if __name__ == "__main__":
Expand All @@ -37,4 +38,5 @@ def main(typeshed_dir: str, commit: str, dry_run: bool = False) -> None:
help="Should we perform a dry run (don't actually upload)",
)
args = parser.parse_args()
main(args.typeshed_dir, args.previous_commit, args.dry_run)
success = main(args.typeshed_dir, args.previous_commit, args.dry_run)
sys.exit(0 if success else 1)
8 changes: 5 additions & 3 deletions stub_uploader/upload_some.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import argparse
import os
import re
import sys

from stub_uploader.upload import upload


def main(typeshed_dir: str, pattern: str) -> None:
def main(typeshed_dir: str, pattern: str) -> bool:
"""Force upload typeshed stub packages to PyPI."""
compiled = re.compile(f"^{pattern}$") # force exact matches
matching = [
Expand All @@ -24,7 +25,7 @@ def main(typeshed_dir: str, pattern: str) -> None:
if re.match(compiled, d)
]
# TODO: Update changelog by providing the "commit" argument
upload(typeshed_dir, matching)
return upload(typeshed_dir, matching)


if __name__ == "__main__":
Expand All @@ -34,4 +35,5 @@ def main(typeshed_dir: str, pattern: str) -> None:
"pattern", help="Regular expression to select distributions for upload"
)
args = parser.parse_args()
main(args.typeshed_dir, args.pattern)
success = main(args.typeshed_dir, args.pattern)
sys.exit(0 if success else 1)
Loading