blob: f257784be7ecfa4160ff65cb41679a5e37b44895 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""IP configuration module."""
from __future__ import annotations
from dataclasses import dataclass
from mlia.backend.registry import registry as backend_registry
from mlia.core.common import AdviceCategory
class IPConfiguration: # pylint: disable=too-few-public-methods
"""Base class for IP configuration."""
def __init__(self, target: str) -> None:
"""Init IP configuration instance."""
self.target = target
@dataclass
class TargetInfo:
"""Collect information about supported targets."""
supported_backends: list[str]
def __str__(self) -> str:
"""List supported backends."""
return ", ".join(sorted(self.supported_backends))
def is_supported(
self, advice: AdviceCategory | None = None, check_system: bool = False
) -> bool:
"""Check if any of the supported backends support this kind of advice."""
return any(
backend_registry.items[name].is_supported(advice, check_system)
for name in self.supported_backends
)
def filter_supported_backends(
self, advice: AdviceCategory | None = None, check_system: bool = False
) -> list[str]:
"""Get the list of supported backends filtered by the given arguments."""
return [
name
for name in self.supported_backends
if backend_registry.items[name].is_supported(advice, check_system)
]
|