diff options
author | Benjamin Klimczak <benjamin.klimczak@arm.com> | 2023-01-11 12:32:02 +0000 |
---|---|---|
committer | Benjamin Klimczak <benjamin.klimczak@arm.com> | 2023-02-08 15:23:29 +0000 |
commit | a4fb8c72f15146c95df16c25e75f03344e9814fd (patch) | |
tree | ce6d9cf39951a0c85d2773d436cc5010ecf78a8f /src/mlia/utils/filesystem.py | |
parent | 09ecc5c8acb758e8def33155feb746a34dd7b560 (diff) | |
download | mlia-a4fb8c72f15146c95df16c25e75f03344e9814fd.tar.gz |
MLIA-591 Create interface for target profiles
New class 'TargetProfile' is used to load and verify target profiles.
Change-Id: I76373a923e2e5f55c4e95860635afe9fc5627a5d
Diffstat (limited to 'src/mlia/utils/filesystem.py')
-rw-r--r-- | src/mlia/utils/filesystem.py | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/src/mlia/utils/filesystem.py b/src/mlia/utils/filesystem.py index 4734a84..f92629b 100644 --- a/src/mlia/utils/filesystem.py +++ b/src/mlia/utils/filesystem.py @@ -11,16 +11,9 @@ from contextlib import contextmanager from pathlib import Path from tempfile import mkstemp from tempfile import TemporaryDirectory -from typing import Any -from typing import cast from typing import Generator from typing import Iterable -try: - import tomllib -except ModuleNotFoundError: - import tomli as tomllib # type: ignore - def get_mlia_resources() -> Path: """Get the path to the resources directory.""" @@ -39,50 +32,6 @@ def get_mlia_target_profiles_dir() -> Path: return get_mlia_resources() / "target_profiles" -def get_profile_toml_file(target_profile: str | Path) -> str | Path: - """Get the target profile toml file.""" - if not target_profile: - raise Exception("Target profile is not provided") - - profile_toml_file = Path(get_mlia_target_profiles_dir() / f"{target_profile}.toml") - if not profile_toml_file.is_file(): - profile_toml_file = Path(target_profile) - - if not profile_toml_file.exists(): - raise Exception(f"File not found: {profile_toml_file}.") - return profile_toml_file - - -def get_profile(target_profile: str | Path) -> dict[str, Any]: - """Get settings for the provided target profile.""" - if not target_profile: - raise Exception("Target profile is not provided") - - toml_file = get_profile_toml_file(target_profile) - - with open(toml_file, "rb") as file: - profile = tomllib.load(file) - - return cast(dict, profile) - - -def get_builtin_supported_profile_names() -> list[str]: - """Return list of default profiles in the target profiles directory.""" - return sorted( - [ - item.stem - for item in get_mlia_target_profiles_dir().iterdir() - if item.is_file() and item.suffix == ".toml" - ] - ) - - -def get_target(target_profile: str | Path) -> str: - """Return target for the provided target_profile.""" - profile = get_profile(target_profile) - return cast(str, profile["target"]) - - @contextmanager def temp_file(suffix: str | None = None) -> Generator[Path, None, None]: """Create temp file and remove it after.""" |