Files
revng-revng/python/revng/model/mixins.py
Giacomo Vercesi 3e3779498e Implement python interface for revng
Add a python interface (`revng.profile`) for interacting with the rev.ng
infrastructure as a whole; either through the CLI (`CLIProject`) or the
GraphQL API (`DaemonProject`).
2025-05-07 10:48:51 +02:00

38 lines
883 B
Python

#
# This file is distributed under the MIT License. See LICENSE.md for details.
#
from typing import Mapping
class AllMixin:
"""
Base mixin for all the objects in the `Binary` that don't support getting the artifacts.
"""
_project = None
_keys = None
class _ArtifactMixin(AllMixin):
"""
Mixin used to implement the get_artifact function
"""
def get_artifact(self, artifact_name: str):
"""
Fetch the artifacts from the `Binary`.
"""
result = self._project.get_artifact(artifact_name, [self]) # type: ignore[attr-defined]
if isinstance(result, Mapping):
keys = list(result.keys())
assert len(keys) == 1
return result[keys[0]]
else:
return result
BinaryMixin = _ArtifactMixin
FunctionMixin = _ArtifactMixin
TypeDefinitionMixin = _ArtifactMixin