Esempio n. 1
0
    def parse(self, catalog_entry: CatalogEntry) -> Optional[List[Component]]:
        components: List[Component] = []

        definition = catalog_entry.entry_data.definition
        if not definition:
            return None

        entry_reference = catalog_entry.entry_reference

        # Parse the component definition for all defined Operator classes
        try:
            parsed_class_nodes = self._parse_all_classes(definition)
            num_operator_classes = len(parsed_class_nodes)
        except Exception as e:
            self.log.error(
                f"Content associated with identifier '{entry_reference}' could not be parsed: {e}. Skipping..."
            )
            return None

        for component_class, content in parsed_class_nodes.items():
            if not content.get("init_function"):
                # Without the init function, class can't be parsed for properties
                self.log.warning(
                    f"Operator '{component_class}' associated with identifier '{entry_reference}' "
                    f"does not have an __init__ function. Skipping...")
                continue

            # Assign component name and unique id
            component_id = catalog_entry.id
            if num_operator_classes > 1:
                # This file contains more than one operator and id must be adjusted
                # to include the Operator class name as well
                component_id += f":{component_class}"

            # Get the properties for this Operator class
            try:
                component_properties: List[
                    ComponentParameter] = self._parse_properties_from_init(
                        **content)
            except Exception as e:
                self.log.error(
                    f"Properties of operator '{component_class}' associated with identifier '{entry_reference}' "
                    f"could not be parsed: {e}. Skipping...")
                continue

            component = catalog_entry.get_component(
                id=component_id,
                name=component_class,
                description=DEFAULT_DESCRIPTION,
                properties=component_properties,
                file_extension=self._file_types[0],
            )

            components.append(component)

        return components
Esempio n. 2
0
    def parse(self, catalog_entry: CatalogEntry) -> Optional[List[Component]]:
        # Get YAML object from component definition
        component_yaml = self._read_component_yaml(catalog_entry)
        if not component_yaml:
            return None

        # Assign component_id and description
        description = ""
        if component_yaml.get("description"):
            # Remove whitespace characters and replace with spaces
            description = " ".join(component_yaml.get("description").split())

        component_properties = self._parse_properties(component_yaml)

        component = catalog_entry.get_component(
            id=catalog_entry.id,
            name=component_yaml.get("name"),
            description=description,
            properties=component_properties,
            file_extension=self._file_types[0],
        )

        return [component]