diff --git a/README.md b/README.md index ce1df58c..0de79bde 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ Version of system builds: - GCC 13.2.1 - Cython 3.0.10 - numpy 1.26.3 -- scikit-build 0.18.0 -- cffi 1.16.0 +- scikit-build 0.18.1 +- cffi 1.17.1 ## Misc diff --git a/builder/__main__.py b/builder/__main__.py index 9b5fe44c..9103d6c1 100644 --- a/builder/__main__.py +++ b/builder/__main__.py @@ -1,11 +1,12 @@ """Hass.io Builder main application.""" +from __future__ import annotations + from pathlib import Path import shutil from subprocess import CalledProcessError, TimeoutExpired import sys from tempfile import TemporaryDirectory -from typing import Optional import click import click_pathlib @@ -62,7 +63,7 @@ @click.option( "--prebuild-dir", type=click_pathlib.Path(exists=True), - help="Folder with include allready builded wheels for upload.", + help="Folder which includes already built wheels for upload.", ) @click.option( "--single", @@ -84,14 +85,14 @@ "--timeout", default=345, type=int, help="Max runtime for pip before abort." ) def builder( - apk: Optional[str], - pip: Optional[str], + apk: str | None, + pip: str | None, index: str, skip_binary: str, - requirement: Optional[Path], - requirement_diff: Optional[Path], - constraint: Optional[Path], - prebuild_dir: Optional[Path], + requirement: Path | None, + requirement_diff: Path | None, + constraint: Path | None, + prebuild_dir: Path | None, single: bool, local: bool, test: bool, diff --git a/builder/apk.py b/builder/apk.py index 2ff9a1bf..d0d4a50f 100644 --- a/builder/apk.py +++ b/builder/apk.py @@ -1,11 +1,13 @@ """Install APKs for build on host system.""" +from __future__ import annotations + import subprocess import sys def install_apks(apks: str) -> None: - """Install all apk string formated as 'package1;package2'.""" + """Install all apk string formatted as 'package1;package2'.""" packages = " ".join(apks.split(";")) subprocess.run( diff --git a/builder/infra.py b/builder/infra.py index 7af32934..8125422f 100644 --- a/builder/infra.py +++ b/builder/infra.py @@ -5,7 +5,7 @@ from dataclasses import dataclass from pathlib import Path import re -from typing import List, Set, Dict, Final +from typing import Final from awesomeversion import AwesomeVersion import requests @@ -49,9 +49,9 @@ def create_wheels_list(base_index: str) -> str: return f"{base_index}/{_MUSLLINUX}/" -def create_package_map(packages: List[str]) -> Dict[str, AwesomeVersion]: +def create_package_map(packages: list[str]) -> dict[str, AwesomeVersion]: """Create a dictionary from package base name to package and version string.""" - results = {} + results: dict[str, AwesomeVersion] = {} for package in packages.copy(): find = _RE_REQUIREMENT.match(package) if not find: @@ -62,11 +62,11 @@ def create_package_map(packages: List[str]) -> Dict[str, AwesomeVersion]: return results -def extract_packages_from_index(index: str) -> Dict[str, List[WhlPackage]]: +def extract_packages_from_index(index: str) -> dict[str, list[WhlPackage]]: """Extract packages from index which match the supported.""" available_data = requests.get(index, allow_redirects=True, timeout=60).text - result = {} + result: dict[str, list[WhlPackage]] = {} for match in _RE_PACKAGE_INDEX.finditer(available_data): package = WhlPackage( match["name"], AwesomeVersion(match["ver"]), match["abi"], match["plat"] @@ -80,10 +80,10 @@ def extract_packages_from_index(index: str) -> Dict[str, List[WhlPackage]]: def check_existing_packages( - package_index: Dict[str, List[WhlPackage]], package_map: Dict[str, AwesomeVersion] -) -> Set[str]: + package_index: dict[str, list[WhlPackage]], package_map: dict[str, AwesomeVersion] +) -> set[str]: """Return the set of package names that already exist in the index.""" - found: Set[str] = set({}) + found: set[str] = set({}) for package, version in package_map.items(): if package in package_index and any( sub_package.version == version for sub_package in package_index[package] @@ -93,10 +93,10 @@ def check_existing_packages( def check_available_binary( - package_index: Dict[str, List[WhlPackage]], + package_index: dict[str, list[WhlPackage]], skip_binary: str, - packages: List[str], - constraints: List[str], + packages: list[str], + constraints: list[str], ) -> str: """Check if binary exists and ignore this skip.""" if skip_binary == ":none:": @@ -108,7 +108,7 @@ def check_available_binary( package_map = create_package_map(packages + constraints) # View of package map limited to packages in --skip-binary - binary_package_map = {} + binary_package_map: dict[str, AwesomeVersion] = {} for binary in list_binary: if not (version := package_map.get(binary)): print( @@ -119,7 +119,7 @@ def check_available_binary( binary_package_map[binary] = version print(f"Checking if binaries already exist for packages {binary_package_map}") - list_found: Set[str] = check_existing_packages(package_index, binary_package_map) + list_found = check_existing_packages(package_index, binary_package_map) print(f"Packages already exist: {list_found}") list_needed = binary_package_map.keys() - list_found @@ -132,11 +132,11 @@ def check_available_binary( def remove_local_wheels( - package_index: Dict[str, List[WhlPackage]], - skip_exists: List[str], - packages: List[str], + package_index: dict[str, list[WhlPackage]], + skip_exists: list[str], + packages: list[str], wheels_dir: Path, -) -> str: +) -> None: """Remove existing wheels if they already exist in the index to avoid syncing.""" package_map = create_package_map(packages) binary_package_map = { diff --git a/builder/pip.py b/builder/pip.py index 1b3def38..41bc5bcd 100644 --- a/builder/pip.py +++ b/builder/pip.py @@ -1,8 +1,9 @@ """Pip build commands.""" +from __future__ import annotations + import os from pathlib import Path -from typing import List, Optional from .utils import run_command @@ -13,7 +14,7 @@ def build_wheels_package( output: Path, skip_binary: str, timeout: int, - constraint: Optional[Path] = None, + constraint: Path | None = None, ) -> None: """Build wheels from a requirements file into output.""" cpu = os.cpu_count() or 4 @@ -38,7 +39,7 @@ def build_wheels_requirement( output: Path, skip_binary: str, timeout: int, - constraint: Optional[Path] = None, + constraint: Path | None = None, ) -> None: """Build wheels from a requirements file into output.""" cpu = os.cpu_count() or 4 @@ -74,9 +75,9 @@ def build_wheels_local( ) -def parse_requirements(requirement: Path) -> List[str]: +def parse_requirements(requirement: Path) -> list[str]: """Parse a requirement files into an array.""" - requirement_list = set() + requirement_list: set[str] = set() with requirement.open("r") as data: for line in data: line = line.strip() @@ -96,8 +97,8 @@ def parse_requirements(requirement: Path) -> List[str]: def extract_packages( - requirement: Path, requirement_diff: Optional[Path] = None -) -> List[str]: + requirement: Path, requirement_diff: Path | None = None +) -> list[str]: """Extract packages they need build.""" packages = parse_requirements(requirement) @@ -110,13 +111,13 @@ def extract_packages( return list(set(packages) - set(packages_diff)) -def write_requirement(requirement: Path, packages: List[str]) -> None: +def write_requirement(requirement: Path, packages: list[str]) -> None: """Write packages list to a requirement file.""" requirement.write_text("\n".join(packages)) def install_pips(index: str, pips: str) -> None: - """Install all pipy string formated as 'package1;package2'.""" + """Install all pipy string formatted as 'package1;package2'.""" packages = " ".join(pips.split(";")) run_command( diff --git a/builder/upload/__init__.py b/builder/upload/__init__.py index 631c8d46..fe69238e 100644 --- a/builder/upload/__init__.py +++ b/builder/upload/__init__.py @@ -1,12 +1,14 @@ """Supported upload function.""" +from __future__ import annotations + from pathlib import Path from importlib import import_module -def run_upload(plugin: str, local: Path, remote: str) -> None: +def run_upload(plugin_name: str, local: Path, remote: str) -> None: """Load a plugin and start upload.""" - plugin = import_module(f".{plugin}", "builder.upload") + plugin = import_module(f".{plugin_name}", "builder.upload") # Run upload plugin.upload(local, remote) diff --git a/builder/upload/rsync.py b/builder/upload/rsync.py index fd7977ce..f6337956 100644 --- a/builder/upload/rsync.py +++ b/builder/upload/rsync.py @@ -1,5 +1,7 @@ """Upload plugin rsync.""" +from __future__ import annotations + from pathlib import Path from ..utils import run_command diff --git a/builder/utils.py b/builder/utils.py index 860219ed..3c2e4ad7 100644 --- a/builder/utils.py +++ b/builder/utils.py @@ -1,17 +1,18 @@ """Some utils for builder.""" +from __future__ import annotations + from functools import cache import os from pathlib import Path import subprocess import sys -from typing import Dict, Optional, Tuple import requests @cache -def alpine_version() -> Tuple[str, str]: +def alpine_version() -> tuple[str, str]: """Return alpine version for index server.""" version = Path("/etc/alpine-release").read_text(encoding="utf-8").split(".") @@ -37,7 +38,7 @@ def check_url(url: str) -> None: def run_command( - cmd: str, env: Optional[Dict[str, str]] = None, timeout: Optional[int] = None + cmd: str, env: dict[str, str] | None = None, timeout: int | None = None ) -> None: """Implement subprocess.run but handle timeout different.""" subprocess.run( diff --git a/builder/wheel.py b/builder/wheel.py index 7fa3e679..b17cbe13 100644 --- a/builder/wheel.py +++ b/builder/wheel.py @@ -1,12 +1,14 @@ """Utils for wheel.""" +from __future__ import annotations + from contextlib import suppress from pathlib import Path import re import shutil from subprocess import CalledProcessError from tempfile import TemporaryDirectory -from typing import Dict, Final +from typing import Final from awesomeversion import AwesomeVersion @@ -59,9 +61,9 @@ def check_abi_platform(abi: str, platform: str) -> bool: return True -def fix_wheels_unmatch_requirements(wheels_folder: Path) -> Dict[str, AwesomeVersion]: +def fix_wheels_unmatch_requirements(wheels_folder: Path) -> dict[str, AwesomeVersion]: """Check Wheels against our min requirements.""" - result = {} + result: dict[str, AwesomeVersion] = {} for wheel_file in wheels_folder.glob("*.whl"): package = _RE_PACKAGE_FULL.fullmatch(wheel_file.name) if not package: diff --git a/tests/test_infra.py b/tests/test_infra.py index 482ac71a..d24937c6 100644 --- a/tests/test_infra.py +++ b/tests/test_infra.py @@ -127,7 +127,7 @@ def test_check_available_binary_skip_constraint() -> None: def test_check_available_binary_for_missing_constraint() -> None: - """Test case where skip binary is for constraint notin the index.""" + """Test case where skip binary is for constraint not in the index.""" package_index = infra.extract_packages_from_index("https://example.com") assert ( infra.check_available_binary( @@ -168,7 +168,7 @@ def test_remove_local_wheel(tmppath: Path) -> None: wheels_dir=tmppath, ) - # grpc is removed + # grpcio is removed assert {p.name for p in tmppath.glob("*.whl")} == { "google_cloud_pubsub-2.9.0-py2.py3-none-any.whl", } @@ -197,7 +197,7 @@ def test_remove_local_wheel_preserves_newer(tmppath: Path) -> None: wheels_dir=tmppath, ) - # grpc is removed + # grpcio is not removed assert {p.name for p in tmppath.glob("*.whl")} == { "grpcio-1.43.0-cp310-cp310-musllinux_1_2_x86_64.whl", "google_cloud_pubsub-2.9.0-py2.py3-none-any.whl",