aboutsummaryrefslogtreecommitdiff
path: root/src/mlia/utils
diff options
context:
space:
mode:
authorDmitrii Agibov <dmitrii.agibov@arm.com>2022-07-21 14:06:03 +0100
committerBenjamin Klimczak <benjamin.klimczak@arm.com>2022-08-19 10:23:23 +0100
commita8ee1aee3e674c78a77801d1bf2256881ab6b4b9 (patch)
tree8463b24ba0446a49b3e012477b0834c3b5415b86 /src/mlia/utils
parent76ec769ad8f8ed53ec3ff829fdd34d53db8229fd (diff)
downloadmlia-a8ee1aee3e674c78a77801d1bf2256881ab6b4b9.tar.gz
MLIA-549 Refactor API module to support several target profiles
- Move target specific details out of API module - Move common logic for workflow event handler into a separate class Change-Id: Ic4a22657b722af1c1fead1d478f606ac57325788
Diffstat (limited to 'src/mlia/utils')
-rw-r--r--src/mlia/utils/filesystem.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/mlia/utils/filesystem.py b/src/mlia/utils/filesystem.py
index 7975905..0c28d35 100644
--- a/src/mlia/utils/filesystem.py
+++ b/src/mlia/utils/filesystem.py
@@ -11,6 +11,7 @@ from pathlib import Path
from tempfile import mkstemp
from tempfile import TemporaryDirectory
from typing import Any
+from typing import cast
from typing import Dict
from typing import Generator
from typing import Iterable
@@ -32,12 +33,12 @@ def get_vela_config() -> Path:
def get_profiles_file() -> Path:
- """Get the Ethos-U profiles file."""
+ """Get the profiles file."""
return get_mlia_resources() / "profiles.json"
def get_profiles_data() -> Dict[str, Dict[str, Any]]:
- """Get the Ethos-U profile values as a dictionary."""
+ """Get the profile values as a dictionary."""
with open(get_profiles_file(), encoding="utf-8") as json_file:
profiles = json.load(json_file)
@@ -47,14 +48,17 @@ def get_profiles_data() -> Dict[str, Dict[str, Any]]:
return profiles
-def get_profile(target: str) -> Dict[str, Any]:
+def get_profile(target_profile: str) -> Dict[str, Any]:
"""Get settings for the provided target profile."""
- profiles = get_profiles_data()
+ if not target_profile:
+ raise Exception("Target profile is not provided")
- if target not in profiles:
- raise Exception(f"Unable to find target profile {target}")
+ profiles = get_profiles_data()
- return profiles[target]
+ try:
+ return profiles[target_profile]
+ except KeyError as err:
+ raise Exception(f"Unable to find target profile {target_profile}") from err
def get_supported_profile_names() -> List[str]:
@@ -62,6 +66,12 @@ def get_supported_profile_names() -> List[str]:
return list(get_profiles_data().keys())
+def get_target(target_profile: str) -> str:
+ """Return target for the provided target_profile."""
+ profile_data = get_profile(target_profile)
+ return cast(str, profile_data["target"])
+
+
@contextmanager
def temp_file(suffix: Optional[str] = None) -> Generator[Path, None, None]:
"""Create temp file and remove it after."""