diff --git a/msys2_autobuild/build.py b/msys2_autobuild/build.py index db38efb..a851e45 100644 --- a/msys2_autobuild/build.py +++ b/msys2_autobuild/build.py @@ -9,7 +9,7 @@ from concurrent.futures import ThreadPoolExecutor from contextlib import contextmanager from pathlib import Path, PurePath, PurePosixPath 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 @@ -155,7 +155,7 @@ def staging_dependencies( asset_path = os.path.join(repo_dir, get_asset_filename(asset)) todo.append((asset_path, asset)) - def fetch_item(item): + def fetch_item(item: Tuple[str, GitReleaseAsset]) -> Tuple[str, GitReleaseAsset]: asset_path, asset = item download_asset(asset, asset_path) return item diff --git a/msys2_autobuild/cmd_build.py b/msys2_autobuild/cmd_build.py index a2c17ab..0b06561 100644 --- a/msys2_autobuild/cmd_build.py +++ b/msys2_autobuild/cmd_build.py @@ -92,7 +92,7 @@ def run_build(args: Any) -> None: continue -def add_parser(subparsers) -> None: +def add_parser(subparsers: Any) -> None: sub = subparsers.add_parser("build", help="Build all packages") sub.add_argument("-t", "--build-types", action="store") sub.add_argument( diff --git a/msys2_autobuild/cmd_clean_assets.py b/msys2_autobuild/cmd_clean_assets.py index 8ff83ae..1baaa4f 100644 --- a/msys2_autobuild/cmd_clean_assets.py +++ b/msys2_autobuild/cmd_clean_assets.py @@ -56,7 +56,7 @@ def clean_gha_assets(args: Any) -> None: 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.add_argument( "--dry-run", action="store_true", help="Only show what is going to be deleted") diff --git a/msys2_autobuild/cmd_clear_failed.py b/msys2_autobuild/cmd_clear_failed.py index 2b726e4..406c01b 100644 --- a/msys2_autobuild/cmd_clear_failed.py +++ b/msys2_autobuild/cmd_clear_failed.py @@ -37,7 +37,7 @@ def clear_failed_state(args: Any) -> None: asset.delete_asset() -def add_parser(subparsers) -> None: +def add_parser(subparsers: Any) -> None: sub = subparsers.add_parser( "clear-failed", help="Clear the failed state for packages", allow_abbrev=False) sub.add_argument( diff --git a/msys2_autobuild/cmd_fetch_assets.py b/msys2_autobuild/cmd_fetch_assets.py index 3b7aca5..2309d9b 100644 --- a/msys2_autobuild/cmd_fetch_assets.py +++ b/msys2_autobuild/cmd_fetch_assets.py @@ -2,7 +2,7 @@ import fnmatch import os from concurrent.futures import ThreadPoolExecutor from pathlib import Path -from typing import Any, Dict, List +from typing import Any, Dict, List, Tuple from github.GitReleaseAsset import GitReleaseAsset @@ -73,7 +73,7 @@ def fetch_assets(args: Any) -> None: asset_path = asset_dir / get_asset_filename(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) if not asset_path.exists(): return False @@ -132,7 +132,7 @@ def fetch_assets(args: Any) -> None: print("Pass --fetch-all to fetch all packages.") 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 if not args.pretend: download_asset(asset, asset_path) @@ -145,7 +145,7 @@ def fetch_assets(args: Any) -> None: print("done") -def add_parser(subparsers) -> None: +def add_parser(subparsers: Any) -> None: sub = subparsers.add_parser( "fetch-assets", help="Download all staging packages", allow_abbrev=False) sub.add_argument("targetdir") diff --git a/msys2_autobuild/cmd_show_build.py b/msys2_autobuild/cmd_show_build.py index 6def078..b9de5c7 100644 --- a/msys2_autobuild/cmd_show_build.py +++ b/msys2_autobuild/cmd_show_build.py @@ -57,7 +57,7 @@ def show_build(args: Any) -> None: show_table("DONE", done) -def add_parser(subparsers) -> None: +def add_parser(subparsers: Any) -> None: sub = subparsers.add_parser( "show", help="Show all packages to be built", allow_abbrev=False) sub.add_argument( diff --git a/msys2_autobuild/cmd_update_status.py b/msys2_autobuild/cmd_update_status.py index 33983bd..8699fc6 100644 --- a/msys2_autobuild/cmd_update_status.py +++ b/msys2_autobuild/cmd_update_status.py @@ -7,7 +7,7 @@ def run_update_status(args: Any) -> None: update_status(get_buildqueue_with_status(full_details=True)) -def add_parser(subparsers) -> None: +def add_parser(subparsers: Any) -> None: sub = subparsers.add_parser( "update-status", help="Update the status file", allow_abbrev=False) sub.set_defaults(func=run_update_status) diff --git a/msys2_autobuild/cmd_upload_assets.py b/msys2_autobuild/cmd_upload_assets.py index 43ae8f1..bbe4f13 100644 --- a/msys2_autobuild/cmd_upload_assets.py +++ b/msys2_autobuild/cmd_upload_assets.py @@ -54,7 +54,7 @@ def upload_assets(args: Any) -> None: print("Done") -def add_parser(subparsers) -> None: +def add_parser(subparsers: Any) -> None: sub = subparsers.add_parser( "upload-assets", help="Upload packages", allow_abbrev=False) sub.add_argument("path", help="Directory to look for packages in") diff --git a/msys2_autobuild/cmd_write_build_plan.py b/msys2_autobuild/cmd_write_build_plan.py index 7ed9523..8a8e9d6 100644 --- a/msys2_autobuild/cmd_write_build_plan.py +++ b/msys2_autobuild/cmd_write_build_plan.py @@ -1,6 +1,6 @@ import json import shlex -from typing import Any, Dict, List +from typing import Any, Dict, List, Iterator import itertools 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 -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 packages = " ".join(["base-devel"]) 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" packages = " ".join(["base-devel", "VCS"]) 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 -def roundrobin(*iterables): +def roundrobin(*iterables): # type: ignore "roundrobin('ABC', 'D', 'EF') --> A D E B F C" # Recipe credited to George Sakkis num_active = len(iterables) @@ -124,7 +124,7 @@ def write_build_plan(args: Any) -> None: write_out(jobs) -def add_parser(subparsers) -> None: +def add_parser(subparsers: Any) -> None: sub = subparsers.add_parser( "write-build-plan", help="Write a GHA build matrix setup", allow_abbrev=False) sub.add_argument("--optional-deps", action="store") diff --git a/msys2_autobuild/gh.py b/msys2_autobuild/gh.py index 6ed9f9c..721aeeb 100644 --- a/msys2_autobuild/gh.py +++ b/msys2_autobuild/gh.py @@ -253,9 +253,9 @@ def get_release(repo: Repository, name: str, create: bool = True) -> GitRelease: class CachedAssets: - def __init__(self): - self._assets = {} - self._failed = {} + def __init__(self) -> None: + self._assets: Dict[BuildType, List[GitReleaseAsset]] = {} + self._failed: Dict[str, List[GitReleaseAsset]] = {} def get_assets(self, build_type: BuildType) -> List[GitReleaseAsset]: if build_type not in self._assets: diff --git a/msys2_autobuild/queue.py b/msys2_autobuild/queue.py index 22fbedb..5b34f51 100644 --- a/msys2_autobuild/queue.py +++ b/msys2_autobuild/queue.py @@ -65,7 +65,7 @@ class Package(dict): def set_blocked( 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_blocked = dep_details.get("blocked", {}) details = self.get_status_details(build_type) @@ -116,7 +116,7 @@ class Package(dict): build_type = Config.MSYS_SRC_ARCH 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. # This requires them to be in the main repo though, otherwise the cycle has to # be fixed manually. diff --git a/msys2_autobuild/utils.py b/msys2_autobuild/utils.py index 2279430..e4348f6 100644 --- a/msys2_autobuild/utils.py +++ b/msys2_autobuild/utils.py @@ -19,7 +19,7 @@ def requests_cache_disabled() -> Any: @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) if nocache: with requests_cache_disabled(): diff --git a/tests/main_test.py b/tests/main_test.py index 8fa929d..d0f3caa 100644 --- a/tests/main_test.py +++ b/tests/main_test.py @@ -1,3 +1,5 @@ +# type: ignore + from msys2_autobuild.utils import parse_optional_deps