orchestrata_ultimate.refactor.codemod.analysis.abstraction

Reference › orchestrata_ultimate › refactor › codemod › analysis › abstraction

AbstractionAnalyzer is a read-only adapter over CodeIntelligenceGraph.abstraction_level in _cig. analyze(target) resolves a module path or dotted name to a graph node, using the shared resolver in protocol, and returns an AbstractionLevel record (see _types). It adds no graph methods and changes nothing; only the analysis facade imports it.

At a glance

Source src/orchestrata_ultimate/refactor/codemod/analysis/abstraction.py
Lines of code 43
Classes 1
Functions 0
Imports (internal) orchestrata_ultimate.core.base.traces, orchestrata_ultimate.refactor.codemod._cig, orchestrata_ultimate.refactor.codemod._types, orchestrata_ultimate.refactor.codemod.analysis.protocol
Imported by orchestrata_ultimate.refactor.codemod.analysis
Tests that import it none

Class diagram

Class diagram orchestrata_ultimate.refactor.codemod.analysis.abstraction

Dependency diagram

Dependency diagram orchestrata_ultimate.refactor.codemod.analysis.abstraction

API

Classes

AbstractionAnalyzer

Decorators: traces(spec='110', story='US-110-006', reqs=['REQ-110-031', 'REQ-110-032']) · Line 18

Abstract (Protocol/ABC) to concrete class ratio of one module.

Method Signature Summary
__init__ __init__(cig: CodeIntelligenceGraph) -> None
analyze analyze(target: str | None = None) -> AbstractionLevel Abstraction level of target (a module path).
_resolve _resolve(target: str) -> int

Source

Permalink: https://gitlab.com/MSamy/orchestrata-ultimate-architecture/-/blob/a4cbc2bdf/src/orchestrata_ultimate/refactor/codemod/analysis/abstraction.py

"""AbstractionAnalyzer — read-only adapter over ``CodeIntelligenceGraph.abstraction_level``."""

from __future__ import annotations

from typing import TYPE_CHECKING

from orchestrata_ultimate.core.base.traces import traces
from orchestrata_ultimate.refactor.codemod._types import AbstractionLevel
from orchestrata_ultimate.refactor.codemod.analysis.protocol import resolve_node_id

if TYPE_CHECKING:
    from orchestrata_ultimate.refactor.codemod._cig import CodeIntelligenceGraph

__all__ = ["AbstractionAnalyzer"]


@traces(spec="110", story="US-110-006", reqs=["REQ-110-031", "REQ-110-032"])
class AbstractionAnalyzer:
    """Abstract (Protocol/ABC) to concrete class ratio of one module."""

    name = "abstraction_level"

    @traces(spec="110", story="US-110-006", reqs=["REQ-110-031", "REQ-110-032"])
    def __init__(self, cig: CodeIntelligenceGraph) -> None:
        self._cig = cig

    @traces(spec="110", story="US-110-006", reqs=["REQ-110-031", "REQ-110-032"])
    def analyze(self, target: str | None = None) -> AbstractionLevel:
        """Abstraction level of ``target`` (a module path).

        Raises:
            ValueError: ``target`` is missing or names no module in the graph.
        """
        if target is None:
            raise ValueError("abstraction_level requires a target module")
        return self._cig.abstraction_level(self._resolve(target))

    @traces(spec="110", story="US-110-006", reqs=["REQ-110-031"])
    def _resolve(self, target: str) -> int:
        node_id = resolve_node_id(self._cig, target)
        if node_id is None:
            raise ValueError(f"module '{target}' not found in CIG")
        return node_id