more type annotations

This commit is contained in:
Christoph Reiter 2023-03-24 14:09:24 +01:00
parent 30fbfffb96
commit e3bb36afac
13 changed files with 25 additions and 23 deletions

View File

@ -9,7 +9,7 @@ from concurrent.futures import ThreadPoolExecutor
from contextlib import contextmanager from contextlib import contextmanager
from pathlib import Path, PurePath, PurePosixPath from pathlib import Path, PurePath, PurePosixPath
from subprocess import check_call from subprocess import check_call
from typing import Any, Dict, Generator, List, Sequence, TypeVar from typing import Any, Dict, Generator, List, Sequence, TypeVar, Tuple
from github.GitReleaseAsset import GitReleaseAsset from github.GitReleaseAsset import GitReleaseAsset
@ -155,7 +155,7 @@ def staging_dependencies(
asset_path = os.path.join(repo_dir, get_asset_filename(asset)) asset_path = os.path.join(repo_dir, get_asset_filename(asset))
todo.append((asset_path, asset)) todo.append((asset_path, asset))
def fetch_item(item): def fetch_item(item: Tuple[str, GitReleaseAsset]) -> Tuple[str, GitReleaseAsset]:
asset_path, asset = item asset_path, asset = item
download_asset(asset, asset_path) download_asset(asset, asset_path)
return item return item

View File

@ -92,7 +92,7 @@ def run_build(args: Any) -> None:
continue continue
def add_parser(subparsers) -> None: def add_parser(subparsers: Any) -> None:
sub = subparsers.add_parser("build", help="Build all packages") sub = subparsers.add_parser("build", help="Build all packages")
sub.add_argument("-t", "--build-types", action="store") sub.add_argument("-t", "--build-types", action="store")
sub.add_argument( sub.add_argument(

View File

@ -56,7 +56,7 @@ def clean_gha_assets(args: Any) -> None:
pass pass
def add_parser(subparsers) -> None: def add_parser(subparsers: Any) -> None:
sub = subparsers.add_parser("clean-assets", help="Clean up GHA assets", allow_abbrev=False) sub = subparsers.add_parser("clean-assets", help="Clean up GHA assets", allow_abbrev=False)
sub.add_argument( sub.add_argument(
"--dry-run", action="store_true", help="Only show what is going to be deleted") "--dry-run", action="store_true", help="Only show what is going to be deleted")

View File

@ -37,7 +37,7 @@ def clear_failed_state(args: Any) -> None:
asset.delete_asset() asset.delete_asset()
def add_parser(subparsers) -> None: def add_parser(subparsers: Any) -> None:
sub = subparsers.add_parser( sub = subparsers.add_parser(
"clear-failed", help="Clear the failed state for packages", allow_abbrev=False) "clear-failed", help="Clear the failed state for packages", allow_abbrev=False)
sub.add_argument( sub.add_argument(

View File

@ -2,7 +2,7 @@ import fnmatch
import os import os
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from pathlib import Path from pathlib import Path
from typing import Any, Dict, List from typing import Any, Dict, List, Tuple
from github.GitReleaseAsset import GitReleaseAsset from github.GitReleaseAsset import GitReleaseAsset
@ -73,7 +73,7 @@ def fetch_assets(args: Any) -> None:
asset_path = asset_dir / get_asset_filename(asset) asset_path = asset_dir / get_asset_filename(asset)
to_fetch[str(asset_path)] = asset to_fetch[str(asset_path)] = asset
def file_is_uptodate(path, asset): def file_is_uptodate(path: str, asset: GitReleaseAsset) -> bool:
asset_path = Path(path) asset_path = Path(path)
if not asset_path.exists(): if not asset_path.exists():
return False return False
@ -132,7 +132,7 @@ def fetch_assets(args: Any) -> None:
print("Pass --fetch-all to fetch all packages.") print("Pass --fetch-all to fetch all packages.")
print("Pass --delete to clear the target directory") print("Pass --delete to clear the target directory")
def fetch_item(item): def fetch_item(item: Tuple[str, GitReleaseAsset]) -> Tuple[str, GitReleaseAsset]:
asset_path, asset = item asset_path, asset = item
if not args.pretend: if not args.pretend:
download_asset(asset, asset_path) download_asset(asset, asset_path)
@ -145,7 +145,7 @@ def fetch_assets(args: Any) -> None:
print("done") print("done")
def add_parser(subparsers) -> None: def add_parser(subparsers: Any) -> None:
sub = subparsers.add_parser( sub = subparsers.add_parser(
"fetch-assets", help="Download all staging packages", allow_abbrev=False) "fetch-assets", help="Download all staging packages", allow_abbrev=False)
sub.add_argument("targetdir") sub.add_argument("targetdir")

View File

@ -57,7 +57,7 @@ def show_build(args: Any) -> None:
show_table("DONE", done) show_table("DONE", done)
def add_parser(subparsers) -> None: def add_parser(subparsers: Any) -> None:
sub = subparsers.add_parser( sub = subparsers.add_parser(
"show", help="Show all packages to be built", allow_abbrev=False) "show", help="Show all packages to be built", allow_abbrev=False)
sub.add_argument( sub.add_argument(

View File

@ -7,7 +7,7 @@ def run_update_status(args: Any) -> None:
update_status(get_buildqueue_with_status(full_details=True)) update_status(get_buildqueue_with_status(full_details=True))
def add_parser(subparsers) -> None: def add_parser(subparsers: Any) -> None:
sub = subparsers.add_parser( sub = subparsers.add_parser(
"update-status", help="Update the status file", allow_abbrev=False) "update-status", help="Update the status file", allow_abbrev=False)
sub.set_defaults(func=run_update_status) sub.set_defaults(func=run_update_status)

View File

@ -54,7 +54,7 @@ def upload_assets(args: Any) -> None:
print("Done") print("Done")
def add_parser(subparsers) -> None: def add_parser(subparsers: Any) -> None:
sub = subparsers.add_parser( sub = subparsers.add_parser(
"upload-assets", help="Upload packages", allow_abbrev=False) "upload-assets", help="Upload packages", allow_abbrev=False)
sub.add_argument("path", help="Directory to look for packages in") sub.add_argument("path", help="Directory to look for packages in")

View File

@ -1,6 +1,6 @@
import json import json
import shlex import shlex
from typing import Any, Dict, List from typing import Any, Dict, List, Iterator
import itertools import itertools
from .config import BuildType, Config, build_type_is_src from .config import BuildType, Config, build_type_is_src
@ -10,7 +10,7 @@ from .queue import (Package, PackageStatus, get_buildqueue_with_status,
from .utils import apply_optional_deps from .utils import apply_optional_deps
def generate_jobs_for(build_type: BuildType, optional_deps: str, count: int): def generate_jobs_for(build_type: BuildType, optional_deps: str, count: int) -> Iterator[Dict[str, Any]]:
name = build_type name = build_type
packages = " ".join(["base-devel"]) packages = " ".join(["base-devel"])
runner = ["windows-2022"] if build_type != "clangarm64" else ["Windows", "ARM64", "autobuild"] runner = ["windows-2022"] if build_type != "clangarm64" else ["Windows", "ARM64", "autobuild"]
@ -28,7 +28,7 @@ def generate_jobs_for(build_type: BuildType, optional_deps: str, count: int):
} }
def generate_src_jobs(optional_deps: str, count: int): def generate_src_jobs(optional_deps: str, count: int) -> Iterator[Dict[str, Any]]:
name = "src" name = "src"
packages = " ".join(["base-devel", "VCS"]) packages = " ".join(["base-devel", "VCS"])
runner = ["windows-2022"] runner = ["windows-2022"]
@ -48,7 +48,7 @@ def generate_src_jobs(optional_deps: str, count: int):
# from https://docs.python.org/3/library/itertools.html # from https://docs.python.org/3/library/itertools.html
def roundrobin(*iterables): def roundrobin(*iterables): # type: ignore
"roundrobin('ABC', 'D', 'EF') --> A D E B F C" "roundrobin('ABC', 'D', 'EF') --> A D E B F C"
# Recipe credited to George Sakkis # Recipe credited to George Sakkis
num_active = len(iterables) num_active = len(iterables)
@ -124,7 +124,7 @@ def write_build_plan(args: Any) -> None:
write_out(jobs) write_out(jobs)
def add_parser(subparsers) -> None: def add_parser(subparsers: Any) -> None:
sub = subparsers.add_parser( sub = subparsers.add_parser(
"write-build-plan", help="Write a GHA build matrix setup", allow_abbrev=False) "write-build-plan", help="Write a GHA build matrix setup", allow_abbrev=False)
sub.add_argument("--optional-deps", action="store") sub.add_argument("--optional-deps", action="store")

View File

@ -253,9 +253,9 @@ def get_release(repo: Repository, name: str, create: bool = True) -> GitRelease:
class CachedAssets: class CachedAssets:
def __init__(self): def __init__(self) -> None:
self._assets = {} self._assets: Dict[BuildType, List[GitReleaseAsset]] = {}
self._failed = {} self._failed: Dict[str, List[GitReleaseAsset]] = {}
def get_assets(self, build_type: BuildType) -> List[GitReleaseAsset]: def get_assets(self, build_type: BuildType) -> List[GitReleaseAsset]:
if build_type not in self._assets: if build_type not in self._assets:

View File

@ -65,7 +65,7 @@ class Package(dict):
def set_blocked( def set_blocked(
self, build_type: BuildType, status: PackageStatus, self, build_type: BuildType, status: PackageStatus,
dep: "Package", dep_type: BuildType): dep: "Package", dep_type: BuildType) -> None:
dep_details = dep.get_status_details(dep_type) dep_details = dep.get_status_details(dep_type)
dep_blocked = dep_details.get("blocked", {}) dep_blocked = dep_details.get("blocked", {})
details = self.get_status_details(build_type) details = self.get_status_details(build_type)
@ -116,7 +116,7 @@ class Package(dict):
build_type = Config.MSYS_SRC_ARCH build_type = Config.MSYS_SRC_ARCH
return self._get_build(build_type) return self._get_build(build_type)
def is_optional_dep(self, dep: "Package", dep_type: BuildType): def is_optional_dep(self, dep: "Package", dep_type: BuildType) -> bool:
# Some deps are manually marked as optional to break cycles. # Some deps are manually marked as optional to break cycles.
# This requires them to be in the main repo though, otherwise the cycle has to # This requires them to be in the main repo though, otherwise the cycle has to
# be fixed manually. # be fixed manually.

View File

@ -19,7 +19,7 @@ def requests_cache_disabled() -> Any:
@lru_cache(maxsize=None) @lru_cache(maxsize=None)
def get_requests_session(nocache=False) -> requests.Session: def get_requests_session(nocache: bool = False) -> requests.Session:
adapter = HTTPAdapter(max_retries=REQUESTS_RETRY) adapter = HTTPAdapter(max_retries=REQUESTS_RETRY)
if nocache: if nocache:
with requests_cache_disabled(): with requests_cache_disabled():

View File

@ -1,3 +1,5 @@
# type: ignore
from msys2_autobuild.utils import parse_optional_deps from msys2_autobuild.utils import parse_optional_deps