|
16 | 16 | """Provide a software system element model.""" |
17 | 17 |
|
18 | 18 |
|
19 | | -from typing import TYPE_CHECKING, Iterable, List, Set |
| 19 | +from typing import Iterable, List, Set |
20 | 20 |
|
21 | 21 | from pydantic import Field |
22 | 22 |
|
|
26 | 26 | from .tags import Tags |
27 | 27 |
|
28 | 28 |
|
29 | | -if TYPE_CHECKING: # pragma: no cover |
30 | | - from .model import Model |
31 | | - |
32 | | - |
33 | 29 | __all__ = ("SoftwareSystem", "SoftwareSystemIO") |
34 | 30 |
|
35 | 31 |
|
@@ -114,33 +110,27 @@ def __iadd__(self, container: Container) -> "SoftwareSystem": |
114 | 110 | f"{container.parent}. Cannot add to {self}." |
115 | 111 | ) |
116 | 112 | self._containers.add(container) |
117 | | - model = self.model |
118 | | - model += container |
| 113 | + if self.is_in_model: |
| 114 | + model = self.model |
| 115 | + model += container |
119 | 116 | return self |
120 | 117 |
|
121 | 118 | def get_container_with_name(self, name: str) -> Container: |
122 | 119 | """Return the container with the given name, or None.""" |
123 | 120 | return next((c for c in self._containers if c.name == name), None) |
124 | 121 |
|
125 | 122 | @classmethod |
126 | | - def hydrate( |
127 | | - cls, software_system_io: SoftwareSystemIO, model: "Model" |
128 | | - ) -> "SoftwareSystem": |
129 | | - """Create a new SoftwareSystem instance and hydrate it from its IO. |
130 | | -
|
131 | | - This will also automatically register with the model. |
132 | | - """ |
| 123 | + def hydrate(cls, software_system_io: SoftwareSystemIO) -> "SoftwareSystem": |
| 124 | + """Create a new SoftwareSystem instance and hydrate it from its IO.""" |
133 | 125 | software_system = cls( |
134 | 126 | **cls.hydrate_arguments(software_system_io), |
135 | 127 | location=software_system_io.location, |
136 | 128 | ) |
137 | | - model += software_system |
138 | 129 |
|
139 | 130 | for container_io in software_system_io.containers: |
140 | 131 | software_system += Container.hydrate( |
141 | 132 | container_io, |
142 | 133 | software_system=software_system, |
143 | | - model=model, |
144 | 134 | ) |
145 | 135 |
|
146 | 136 | return software_system |
0 commit comments