Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions src/techui_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@

techui: Path = field(default=Path("techui.yaml"))

entities: defaultdict[str, list[Entity]] = field(
default_factory=lambda: defaultdict(list), init=False
)
# entity_registry: defaultdict[str, list[Entity]] = field(
# default_factory=lambda: defaultdict(list), init=False
# )
entity_registry: defaultdict[str, Entity] = field(init=False, repr=False)
_services_dir: Path = field(init=False, repr=False)
_write_directory: Path = field(init=False, repr=False)

Expand Down Expand Up @@ -102,6 +103,18 @@
logger_.debug(f"Removing generated file: {file_.name}")
os.remove(file_)

def _add_to_registry(self, entity: Entity):
pass

def _search_entity_registry(self, component_prefix: str):
entity_matches = [
entity_id
for entity_id, entity in self.entity_registry.items()
if entity.prefix == component_prefix
]

return entity_matches

def _extract_services(self):
"""
Finds the services folders in the services directory
Expand Down Expand Up @@ -180,8 +193,7 @@
macros=macros,
)

pv_root = prefix.split(":", maxsplit=1)[0]
self.entities[pv_root].append(new_entity)
self.entity_registry[prefix] = new_entity
break

def _generate_screen(self, screen_name: str):
Expand All @@ -198,7 +210,7 @@

def create_screens(self):
"""Create the screens for each component in techui.yaml"""
if len(self.entities) == 0:
if len(self.entity_registry) == 0:
logger_.critical(
"No ioc entities found. This [italic]normally[/italic]"
" suggests an issue with finding ixx-services."
Expand All @@ -210,25 +222,28 @@
for component_name, component in self.conf.components.items():
screen_entities: list[Entity] = []

# ONLY IF there is a matching component and entity, generate a screen
if component.prefix in self.entities.keys():
matched_entities = self._search_entity_registry(component.prefix)

# ONLY IF there is at least one matching component and entity,
# generate a screen
if matched_entities:
# Populate child labels for any entities
# with the same prefix as the component
for entity in self.entities[component.prefix]:
for entity in self.entity_registry[component]:

Check failure on line 232 in src/techui_builder/builder.py

View workflow job for this annotation

GitHub Actions / lint / run

Argument of type "Component" cannot be assigned to parameter "key" of type "str" in function "__getitem__"   "Component" is not assignable to "str" (reportArgumentType)
entity.child_labels = component.child_labels

Check failure on line 233 in src/techui_builder/builder.py

View workflow job for this annotation

GitHub Actions / lint / run

Cannot assign to attribute "child_labels" for class "tuple[str, Any]"   Attribute "child_labels" is unknown (reportAttributeAccessIssue)

screen_entities.extend(self.entities[component.prefix])
screen_entities.extend(self.entity_registry[component.prefix])

Check failure on line 235 in src/techui_builder/builder.py

View workflow job for this annotation

GitHub Actions / lint / run

Argument of type "Entity" cannot be assigned to parameter "iterable" of type "Iterable[Entity]" in function "extend"   "Entity" is incompatible with protocol "Iterable[Entity]"     "__iter__" is an incompatible type       Type "() -> TupleGenerator" is not assignable to type "() -> Iterator[_T_co@Iterable]"         Function return type "TupleGenerator" is incompatible with type "Iterator[_T_co@Iterable]"           "Generator[tuple[str, Any], None, None]" is not assignable to "Iterator[_T_co@Iterable]" (reportArgumentType)

if component.extras is not None:
# If component has any extras, add them to the entries to generate
for extra_p in component.extras:
if extra_p not in self.entities.keys():
if extra_p not in self.entity_registry.keys():
logger_.error(
f"Extra prefix {extra_p} for {component_name} does not"
" exist."
)
continue
screen_entities.extend(self.entities[extra_p])
screen_entities.extend(self.entity_registry[extra_p])

Check failure on line 246 in src/techui_builder/builder.py

View workflow job for this annotation

GitHub Actions / lint / run

Argument of type "Entity" cannot be assigned to parameter "iterable" of type "Iterable[Entity]" in function "extend"   "Entity" is incompatible with protocol "Iterable[Entity]"     "__iter__" is an incompatible type       Type "() -> TupleGenerator" is not assignable to type "() -> Iterator[_T_co@Iterable]"         Function return type "TupleGenerator" is incompatible with type "Iterator[_T_co@Iterable]"           "Generator[tuple[str, Any], None, None]" is not assignable to "Iterator[_T_co@Iterable]" (reportArgumentType)

# This is used by both generate and validate,
# so called beforehand for tidiness
Expand Down
Loading