orchestrata_tools.context.dependency_summary

Reference › orchestrata_tools › context › dependency_summary

This module summarises what a codebase imports, for the LLM context built in project_context. DependencySummarizer takes an ASTCodebase (see ast_models). summarize walks every import and classifies it by its top-level package: internal modules (names starting with the project package prefixes), standard-library modules from the class constant STDLIB_MODULES, or everything else as an external package. It returns a DependencySummary with the three sorted lists and the total import count.

At a glance

Source src/orchestrata_tools/context/dependency_summary.py
Lines of code 94
Classes 2
Functions 0
Imports (internal) orchestrata_tools.models.ast_models
Imported by orchestrata_tools.context.project_context
Tests that import it tests/test_orchestrata_tools.py

Class diagram

Class diagram orchestrata_tools.context.dependency_summary

Dependency diagram

Dependency diagram orchestrata_tools.context.dependency_summary

API

Classes

DependencySummary (dataclass)

Decorators: dataclass · Line 13

Summary of internal and external dependencies.

Attribute Type Default
internal_modules list[str] field(default_factory=list)
external_packages list[str] field(default_factory=list)
stdlib_imports list[str] field(default_factory=list)
total_imports int 0

DependencySummarizer

Line 22

Summarize dependencies from AST imports.

Method Signature Summary
__init__ __init__(codebase: ASTCodebase)
summarize summarize() -> DependencySummary

Source

Permalink: https://gitlab.com/MSamy/orchestrata-ultimate-architecture/-/blob/a4cbc2bdf/src/orchestrata_tools/context/dependency_summary.py

"""Summarize codebase dependencies for LLM context."""

from __future__ import annotations

from dataclasses import dataclass, field
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from orchestrata_tools.models.ast_models import ASTCodebase


@dataclass
class DependencySummary:
    """Summary of internal and external dependencies."""

    internal_modules: list[str] = field(default_factory=list)
    external_packages: list[str] = field(default_factory=list)
    stdlib_imports: list[str] = field(default_factory=list)
    total_imports: int = 0


class DependencySummarizer:
    """Summarize dependencies from AST imports."""

    STDLIB_MODULES = {
        "abc",
        "argparse",
        "asyncio",
        "base64",
        "collections",
        "copy",
        "csv",
        "dataclasses",
        "datetime",
        "enum",
        "functools",
        "hashlib",
        "importlib",
        "inspect",
        "io",
        "itertools",
        "json",
        "logging",
        "math",
        "operator",
        "os",
        "pathlib",
        "pickle",
        "random",
        "re",
        "shutil",
        "signal",
        "socket",
        "string",
        "subprocess",
        "sys",
        "tempfile",
        "textwrap",
        "threading",
        "time",
        "traceback",
        "types",
        "typing",
        "uuid",
        "warnings",
        "xml",
        "zipfile",
    }

    def __init__(self, codebase: ASTCodebase):
        self.codebase = codebase

    def summarize(self) -> DependencySummary:
        internal = set()
        external = set()
        stdlib = set()

        for imp in self.codebase.all_imports:
            module = imp.module.split(".")[0]
            if module.startswith("orchestrata_ultimate") or module.startswith(
                "orchestrata_tools"
            ):
                internal.add(imp.module)
            elif module in self.STDLIB_MODULES:
                stdlib.add(module)
            elif module:
                external.add(module)

        return DependencySummary(
            internal_modules=sorted(internal),
            external_packages=sorted(external),
            stdlib_imports=sorted(stdlib),
            total_imports=len(list(self.codebase.all_imports)),
        )