Skip to content
Snippets Groups Projects
Commit 062a74cc authored by Martin Lange's avatar Martin Lange
Browse files

Merge branch 'renaming' into 'main'

Allow renaming

See merge request !243
parents 3b158b4c cbc301ca
No related branches found
No related tags found
1 merge request!243Allow renaming
Pipeline #134963 passed with stages
in 6 minutes and 13 seconds
......@@ -118,6 +118,11 @@ class IComponent(ABC):
After the method call, the component should have :attr:`.status` :attr:`.ComponentStatus.FINALIZED`.
"""
@property
@abstractmethod
def name(self):
"""Component name."""
@property
@abstractmethod
def inputs(self):
......@@ -154,6 +159,11 @@ class ITimeComponent(IComponent, ABC):
class IInput(ABC):
"""Interface for input slots."""
@property
@abstractmethod
def name(self):
"""Input name."""
@property
@abstractmethod
def is_static(self):
......@@ -247,6 +257,11 @@ class IInput(ABC):
class IOutput(ABC):
"""Interface for output slots."""
@property
@abstractmethod
def name(self):
"""Output name."""
@property
@abstractmethod
def time(self):
......@@ -438,10 +453,6 @@ class IOutput(ABC):
class IAdapter(IInput, IOutput, ABC):
"""Interface for adapters."""
@abstractmethod
def finalize(self):
"""Called at the end of each run. Can be used for cleanup."""
class NoBranchAdapter:
"""Interface to mark adapters as allowing only a single end point."""
......
......@@ -34,9 +34,15 @@ class Adapter(IAdapter, Input, Output, ABC):
def __init__(self):
Input.__init__(self, name=self.__class__.__name__)
Output.__init__(self, name=self.__class__.__name__)
self._name = self.__class__.__name__
self.source = None
self.targets = []
def with_name(self, name):
"""Renames the adapter and returns self."""
self._name = name
return self
@property
def time(self):
"""The output's time of the latest available data"""
......
......@@ -43,12 +43,18 @@ class Component(IComponent, Loggable, ABC):
def __init__(self):
Loggable.__init__(self)
self._name = self.__class__.__name__
self._status = ComponentStatus.CREATED
self._inputs = IOList(self, "INPUT")
self._outputs = IOList(self, "OUTPUT")
self.base_logger_name = None
self._connector: ConnectHelper = None
def with_name(self, name):
"""Renames the component and returns self."""
self._name = name
return self
@final
def initialize(self):
"""Initialize the component.
......@@ -211,7 +217,7 @@ class Component(IComponent, Loggable, ABC):
@property
def name(self):
"""Component name."""
return self.__class__.__name__
return self._name
@property
def logger_name(self):
......
......@@ -20,7 +20,7 @@ class Input(IInput, Loggable):
self.base_logger_name = None
if name is None:
raise ValueError("Input: needs a name.")
self.name = name
self._name = name
self._static = static
if info_kwargs:
if info is not None:
......@@ -30,6 +30,11 @@ class Input(IInput, Loggable):
self._in_info_exchanged = False
self._cached_data = None
@property
def name(self):
"""Input name."""
return self._name
@property
def is_static(self):
return self._static
......
......@@ -32,7 +32,7 @@ class Output(IOutput, Loggable):
self.base_logger_name = None
if name is None:
raise ValueError("Output: needs a name.")
self.name = name
self._name = name
self._static = static
if info_kwargs:
......@@ -51,6 +51,11 @@ class Output(IOutput, Loggable):
self._total_mem = 0
self._mem_counter = 0
@property
def name(self):
"""Input name."""
return self._name
@property
def time(self):
"""The output's time of the latest available data"""
......
......@@ -874,5 +874,15 @@ class TestNotImplemented(unittest.TestCase):
adapter._get_data(datetime(2000, 1, 1), None)
class TestRename(unittest.TestCase):
def test_rename_component(self):
comp = fm.modules.SimplexNoise().with_name("CompA")
self.assertEqual("CompA", comp.name)
def test_rename_adapter(self):
ada = fm.adapters.Scale(1.0).with_name("Scale-1")
self.assertEqual("Scale-1", ada.name)
if __name__ == "__main__":
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment