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
12 changes: 6 additions & 6 deletions stub_uploader/build_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ def package_source_path(self, package_name: str) -> Path:
The top-level package name can optionally include the "-stubs" suffix.
"""
top_level, *sub_packages = package_name.split(".")
if top_level.endswith(SUFFIX):
top_level = top_level[: -len(SUFFIX)]
top_level = top_level.removesuffix(SUFFIX)
return Path(top_level, *sub_packages)

def package_build_path(self, package_name: str) -> Path:
Expand Down Expand Up @@ -243,7 +242,9 @@ def find_stub_files(top: str) -> list[str]:
elif not file.endswith((".md", ".rst")):
# Allow having README docs, as some stubs have these (e.g. click).
if (
subprocess.run(["git", "check-ignore", file], cwd=top).returncode
subprocess.run(
["git", "check-ignore", file], cwd=top, check=False
).returncode
!= 0
):
raise ValueError(f"Only stub files are allowed, not {file!r}")
Expand Down Expand Up @@ -337,7 +338,7 @@ def is_ignored_distribution_file(entry: Path) -> bool:
return True
if (
subprocess.run(
["git", "check-ignore", entry.name], cwd=str(entry.parent)
["git", "check-ignore", entry.name], cwd=str(entry.parent), check=False
).returncode
== 0
):
Expand Down Expand Up @@ -500,8 +501,7 @@ def main(
print(f"{package}=={package_version(package)}")
print("\033[0m")
subprocess.run(
[sys.executable, "-m", "build", "--no-isolation"],
cwd=tmpdir,
[sys.executable, "-m", "build", "--no-isolation"], cwd=tmpdir, check=False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be check=True?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly, I just wanted to preserve current behavior in this PR. I'll explore this later and send a followup PR if it makes sense.

)
return Path(tmpdir) / "dist"

Expand Down
7 changes: 3 additions & 4 deletions stub_uploader/get_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
"""

from __future__ import annotations
import datetime

from typing import Any
import datetime

import requests
from packaging.specifiers import Specifier, SpecifierSet
Expand Down Expand Up @@ -42,8 +41,8 @@ def fetch_pypi_versions(distribution: str) -> list[Version]:
# Looks like this is first time this package is ever uploaded.
return []
raise ValueError("Error while retrieving version")
releases: dict[str, Any] = resp.json()["releases"]
return [Version(release) for release in releases.keys()]
releases: dict[str, object] = resp.json()["releases"]
return [Version(release) for release in releases]


def ensure_specificity(ver: list[int], specificity: int) -> None:
Expand Down
21 changes: 11 additions & 10 deletions stub_uploader/metadata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from dataclasses import dataclass
import functools
import graphlib
import os
Expand All @@ -10,9 +9,10 @@
import tomllib
import urllib.parse
from collections.abc import Generator, Iterable
from dataclasses import dataclass
from glob import glob
from pathlib import Path
from typing import Any, LiteralString, Optional
from typing import Any, LiteralString

import requests
from packaging.requirements import Requirement
Expand Down Expand Up @@ -70,15 +70,15 @@ def base_name(self) -> str:

class Metadata:
def __init__(
self, distribution: str, data: dict[str, Any], typeshed_pkgs: set[str]
self, distribution: str, data: dict[str, object], typeshed_pkgs: set[str]
):
assert not distribution.startswith(TYPES_PREFIX)
self._alleged_upstream_distribution = distribution
self.data = data
self.typeshed_pkgs = typeshed_pkgs

@property
def upstream_distribution(self) -> Optional[str]:
def upstream_distribution(self) -> str | None:
# TODO: add a field to METADATA.toml if the stubs are for a package
# that does not exist on PyPI
if self._alleged_upstream_distribution == "gdb":
Expand Down Expand Up @@ -241,7 +241,7 @@ def canonical_name(name: str) -> str:
class _UploadedPackages:
def __init__(self, file_path: str) -> None:
self._file_path = file_path
self._cached: Optional[list[str]] = None
self._cached: list[str] | None = None

def read(self) -> set[str]:
if self._cached is not None:
Expand Down Expand Up @@ -298,7 +298,7 @@ def temp_archive_path(sdist_data: dict[str, str], req: Requirement) -> str:

def extract_sdist_requires(
sdist_data: dict[str, str], req: Requirement
) -> Generator[Requirement, None, None]:
) -> Generator[Requirement]:
tmpdir = temp_archive_path(sdist_data, req)

# Only a single folder with "<package-version>.egg-info/requires.txt" in the archive should exist
Expand All @@ -316,7 +316,7 @@ def extract_sdist_requires(

def extract_sdist_pyproject_requires(
sdist_data: dict[str, str], req: Requirement
) -> Generator[Requirement, None, None]:
) -> Generator[Requirement]:
tmpdir = temp_archive_path(sdist_data, req)

# Find and process only the first pyproject.toml we come across:
Expand Down Expand Up @@ -416,7 +416,7 @@ def verify_external_req_stubs_require_its_runtime(

def get_upstream_release_metadata(
req: Requirement, upstream_distribution: str, upstream_version_spec: Specifier
) -> dict[str, Any]:
) -> dict[str, object]:
"""Fetch metadata for the latest supported, non-yanked upstream release."""

project_url = f"https://pypi.org/pypi/{upstream_distribution}"
Expand Down Expand Up @@ -444,7 +444,8 @@ def get_upstream_release_metadata(
release = urllib.parse.quote(max(candidates)[1], safe="")
resp = requests.get(f"{project_url}/{release}/json")
validate_pypi_response(resp, req)
data: dict[str, Any] = resp.json()
data: object = resp.json()
assert isinstance(data, dict)
return data


Expand Down Expand Up @@ -495,7 +496,7 @@ def runtime_in_upstream_group_requires(req: Requirement, data: dict[str, Any]) -

def sort_by_dependency(
typeshed_dir: str, distributions: Iterable[str]
) -> Generator[str, None, None]:
) -> Generator[str]:
# Just a simple topological sort. Unlike previous versions of the code, we do not rely
# on this to perform validation, like requiring the graph to be complete.
# We only use this to help with edge cases like multiple packages being uploaded
Expand Down
7 changes: 4 additions & 3 deletions stub_uploader/ts_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from __future__ import annotations

import argparse
from collections.abc import Iterable
from dataclasses import dataclass, fields
from pathlib import Path
import re
import subprocess
import tomllib
from collections.abc import Iterable
from dataclasses import dataclass, fields
from pathlib import Path

from packaging.requirements import Requirement
from packaging.version import Version
Expand All @@ -37,6 +37,7 @@ def read_current_commit(self) -> str:
capture_output=True,
text=True,
cwd=self.typeshed_path,
check=False,
).stdout.strip()


Expand Down
2 changes: 1 addition & 1 deletion stub_uploader/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from stub_uploader import build_wheel
from stub_uploader.get_version import determine_stub_version
from stub_uploader.update_changelog import update_changelog
from stub_uploader.metadata import read_metadata, sort_by_dependency, uploaded_packages
from stub_uploader.update_changelog import update_changelog


def upload(
Expand Down
1 change: 1 addition & 0 deletions stub_uploader/upload_changed.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import argparse
import os

from stub_uploader import get_changed
from stub_uploader.upload import upload

Expand Down
Loading