Source code for mafw.scripts.cli.list.operations

#  Copyright 2026 European Union
#  Author: Bulgheroni Antonio (antonio.bulgheroni@ec.europa.eu)
#  SPDX-License-Identifier: EUPL-1.2
"""Processor discovery and table construction for the list command.\n\n:author: Bulgheroni Antonio\n"""

from typing import Any

from rich.align import Align
from rich.table import Table

from mafw.lazy_import import LazyImportProcessor
from mafw.plugin_manager import get_plugin_manager


[docs] def _build_processor_table() -> Align: """Discover processors and return the formatted summary table.""" plugins = get_plugin_manager().load_plugins({'processors'}) available_processors: list[Any] = plugins.processor_list table = Table( title='Available processors', header_style='orange3', expand=True, title_style='italic red', ) table.add_column('Processor Name', justify='left', style='cyan') table.add_column('Package Name', justify='left', style='cyan') table.add_column('Module', justify='left', style='cyan') mafw_processors = 0 other_processors = 0 for processor in available_processors: if isinstance(processor, LazyImportProcessor): package, module = processor.plugin_qualname.split('.', 1) name = processor.plugin_name else: package, module = processor.__module__.split('.', 1) name = processor.__name__ table.add_row(name, package, module) if package == 'mafw': mafw_processors += 1 else: other_processors += 1 table.caption = ( f'Total processors = {len(available_processors)}, internal = {mafw_processors}, external = {other_processors}' ) table.caption_style = 'italic green' return Align.center(table)