Skip to content

PackageData

Contains all data collected for a package.

Attributes:

Name Type Description
package_name str

The name of the package.

modules dict[str, tuple[str, ModuleData]]

All modules and their ModuleData. The key is the name of the module. The value is a tuple of the path to the module and the ModuleData.

combined_module ModuleData

The combined ModuleData of all modules in the package.

Source code in src/library_analyzer/processing/api/purity_analysis/model/_module_data.py
@dataclass
class PackageData:
    """
    Contains all data collected for a package.

    Attributes
    ----------
    package_name :
        The name of the package.
    modules :
        All modules and their ModuleData.
        The key is the name of the module.
        The value is a tuple of the path to the module and the ModuleData.
    combined_module : ModuleData
        The combined ModuleData of all modules in the package.
    """

    package_name: str
    modules: dict[str, tuple[str, ModuleData]] = field(default_factory=dict)
    combined_module: ModuleData | None = field(default=None)

    def combine_modules(self) -> None:
        """Combine the data of all modules into one ModuleData.

        Combines the data of all modules in the package into one ModuleData.
        The scope of the new ModuleData is of type UnkownSymbol, and the children are the scopes of the modules.
        The classes, functions, and imports are combined into one dict each.

        Returns
        -------
        ModuleData
            The combined ModuleData.
        """
        combined_module = ModuleData(
            scope=Scope(UnknownSymbol(id=NodeID(None, self.package_name)), [], None),
            classes={},
            functions={},
            imports={},
        )

        for module_data in self.modules.values():
            combined_module.scope.children.extend(module_data[1].scope)
            combined_module.classes.update(module_data[1].classes)
            for name, functions in module_data[1].functions.items():
                combined_module.functions.setdefault(name, []).extend(functions)
            combined_module.imports.update(module_data[1].imports)

        self.combined_module = combined_module

combined_module: ModuleData | None = field(default=None) class-attribute instance-attribute

modules: dict[str, tuple[str, ModuleData]] = field(default_factory=dict) class-attribute instance-attribute

package_name: str instance-attribute

__init__(package_name, modules=dict(), combined_module=None)

combine_modules()

Combine the data of all modules into one ModuleData.

Combines the data of all modules in the package into one ModuleData. The scope of the new ModuleData is of type UnkownSymbol, and the children are the scopes of the modules. The classes, functions, and imports are combined into one dict each.

Returns:

Type Description
ModuleData

The combined ModuleData.

Source code in src/library_analyzer/processing/api/purity_analysis/model/_module_data.py
def combine_modules(self) -> None:
    """Combine the data of all modules into one ModuleData.

    Combines the data of all modules in the package into one ModuleData.
    The scope of the new ModuleData is of type UnkownSymbol, and the children are the scopes of the modules.
    The classes, functions, and imports are combined into one dict each.

    Returns
    -------
    ModuleData
        The combined ModuleData.
    """
    combined_module = ModuleData(
        scope=Scope(UnknownSymbol(id=NodeID(None, self.package_name)), [], None),
        classes={},
        functions={},
        imports={},
    )

    for module_data in self.modules.values():
        combined_module.scope.children.extend(module_data[1].scope)
        combined_module.classes.update(module_data[1].classes)
        for name, functions in module_data[1].functions.items():
            combined_module.functions.setdefault(name, []).extend(functions)
        combined_module.imports.update(module_data[1].imports)

    self.combined_module = combined_module