diff options
author | Dmitrii Agibov <dmitrii.agibov@arm.com> | 2022-09-08 14:24:39 +0100 |
---|---|---|
committer | Dmitrii Agibov <dmitrii.agibov@arm.com> | 2022-09-09 17:21:48 +0100 |
commit | f5b293d0927506c2a979a091bf0d07ecc78fa181 (patch) | |
tree | 4de585b7cb6ed34da8237063752270189a730a41 /src/mlia/tools/metadata/corstone.py | |
parent | cde0c6ee140bd108849bff40467d8f18ffc332ef (diff) | |
download | mlia-f5b293d0927506c2a979a091bf0d07ecc78fa181.tar.gz |
MLIA-386 Simplify typing in the source code
- Enable deferred annotations evaluation
- Use builtin types for type hints whenever possible
- Use | syntax for union types
- Rename mlia.core._typing into mlia.core.typing
Change-Id: I3f6ffc02fa069c589bdd9e8bddbccd504285427a
Diffstat (limited to 'src/mlia/tools/metadata/corstone.py')
-rw-r--r-- | src/mlia/tools/metadata/corstone.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/mlia/tools/metadata/corstone.py b/src/mlia/tools/metadata/corstone.py index 023369c..feef7ad 100644 --- a/src/mlia/tools/metadata/corstone.py +++ b/src/mlia/tools/metadata/corstone.py @@ -6,6 +6,8 @@ The import of subprocess module raises a B404 bandit error. MLIA usage of subprocess is needed and can be considered safe hence disabling the security check. """ +from __future__ import annotations + import logging import platform import subprocess # nosec @@ -14,7 +16,6 @@ from dataclasses import dataclass from pathlib import Path from typing import Callable from typing import Iterable -from typing import List from typing import Optional import mlia.backend.manager as backend_manager @@ -40,7 +41,7 @@ class BackendInfo: backend_path: Path copy_source: bool = True - system_config: Optional[str] = None + system_config: str | None = None PathChecker = Callable[[Path], Optional[BackendInfo]] @@ -55,10 +56,10 @@ class BackendMetadata: name: str, description: str, system_config: str, - apps_resources: List[str], + apps_resources: list[str], fvp_dir_name: str, - download_artifact: Optional[DownloadArtifact], - supported_platforms: Optional[List[str]] = None, + download_artifact: DownloadArtifact | None, + supported_platforms: list[str] | None = None, ) -> None: """ Initialize BackendMetadata. @@ -100,7 +101,7 @@ class BackendInstallation(Installation): backend_runner: backend_manager.BackendRunner, metadata: BackendMetadata, path_checker: PathChecker, - backend_installer: Optional[BackendInstaller], + backend_installer: BackendInstaller | None, ) -> None: """Init the backend installation.""" self.backend_runner = backend_runner @@ -209,13 +210,13 @@ class PackagePathChecker: """Package path checker.""" def __init__( - self, expected_files: List[str], backend_subfolder: Optional[str] = None + self, expected_files: list[str], backend_subfolder: str | None = None ) -> None: """Init the path checker.""" self.expected_files = expected_files self.backend_subfolder = backend_subfolder - def __call__(self, backend_path: Path) -> Optional[BackendInfo]: + def __call__(self, backend_path: Path) -> BackendInfo | None: """Check if directory contains all expected files.""" resolved_paths = (backend_path / file for file in self.expected_files) if not all_files_exist(resolved_paths): @@ -238,9 +239,9 @@ class StaticPathChecker: def __init__( self, static_backend_path: Path, - expected_files: List[str], + expected_files: list[str], copy_source: bool = False, - system_config: Optional[str] = None, + system_config: str | None = None, ) -> None: """Init static path checker.""" self.static_backend_path = static_backend_path @@ -248,7 +249,7 @@ class StaticPathChecker: self.copy_source = copy_source self.system_config = system_config - def __call__(self, backend_path: Path) -> Optional[BackendInfo]: + def __call__(self, backend_path: Path) -> BackendInfo | None: """Check if directory equals static backend path with all expected files.""" if backend_path != self.static_backend_path: return None @@ -271,7 +272,7 @@ class CompoundPathChecker: """Init compound path checker.""" self.path_checkers = path_checkers - def __call__(self, backend_path: Path) -> Optional[BackendInfo]: + def __call__(self, backend_path: Path) -> BackendInfo | None: """Iterate over checkers and return first non empty backend info.""" first_resolved_backend_info = ( backend_info @@ -401,7 +402,7 @@ def get_corstone_310_installation() -> Installation: return corstone_310 -def get_corstone_installations() -> List[Installation]: +def get_corstone_installations() -> list[Installation]: """Get Corstone installations.""" return [ get_corstone_300_installation(), |