Skip to content

solidworks_mcp.progress.com_coverage

solidworks_mcp.progress.com_coverage

How much of the SolidWorks COM API the adapters call, counted by text.

The method names come from a committed snapshot of the type library, so counting needs no SolidWorks. A name counts as called when the adapter source uses it as an attribute (model.ForceRebuild3) or passes it as a string (flag_members(obj, "EditDelete")). A name scan can't tell IFeature.Name from IComponent2.Name, so the figures are approximate.

Attributes

CORE_INTERFACES module-attribute

CORE_INTERFACES = ('ISldWorks', 'IModelDoc2', 'IModelDocExtension', 'IPartDoc', 'IAssemblyDoc', 'IDrawingDoc', 'IFeatureManager', 'ISketchManager', 'ISelectionMgr', 'IComponent2', 'IFeature', 'ISketch')

_ATTRIBUTE module-attribute

_ATTRIBUTE = re.compile('\\.([A-Z]\\w*)\\b')

_QUOTED module-attribute

_QUOTED = re.compile('[\\"\']([A-Z]\\w+)[\\"\']')

Classes

ComCoverage dataclass

ComCoverage(interfaces: tuple[InterfaceCoverage, ...], api_covered: int, api_total: int, type_library: str)

Coverage of the core interfaces and of the whole API.

Attributes:

Name Type Description
interfaces tuple[InterfaceCoverage, ...]

One entry per core interface, in CORE_INTERFACES order.

api_covered int

Distinct method names called, across the whole API.

api_total int

Distinct method names in the whole API.

type_library str

The snapshot's source, which carries its version.

Attributes
core_covered property
core_covered: int

Called methods summed over the core interfaces.

core_total property
core_total: int

Methods summed over the core interfaces.

InterfaceCoverage dataclass

InterfaceCoverage(name: str, covered: tuple[str, ...], total: int)

The methods of one interface that the adapters call.

Attributes:

Name Type Description
name str

The interface, e.g. IModelDoc2.

covered tuple[str, ...]

The called method names, sorted.

total int

How many methods the interface has.

Snapshot dataclass

Snapshot(type_library: str, interfaces: Mapping[str, frozenset[str]])

The type library's interface and method names.

Attributes:

Name Type Description
type_library str

Where it came from (the gen_py wrapper's name).

interfaces Mapping[str, frozenset[str]]

Interface name to its method names.

Methods:
from_json classmethod
from_json(text: str) -> Snapshot

Read a snapshot written by :meth:to_json.

Parameters:

Name Type Description Default
text str

The JSON text.

required

Returns:

Name Type Description
Snapshot Snapshot

The parsed snapshot.

Source code in src/solidworks_mcp/progress/com_coverage.py
@classmethod
def from_json(cls, text: str) -> Snapshot:
    """Read a snapshot written by :meth:`to_json`.

    Args:
        text: The JSON text.

    Returns:
        Snapshot: The parsed snapshot.
    """
    raw = json.loads(text)
    return cls(
        raw["type_library"],
        {name: frozenset(methods) for name, methods in raw["interfaces"].items()},
    )
load classmethod
load(path: Path) -> Snapshot

Read the committed snapshot file.

Parameters:

Name Type Description Default
path Path

The snapshot's path.

required

Returns:

Name Type Description
Snapshot Snapshot

The parsed snapshot.

Source code in src/solidworks_mcp/progress/com_coverage.py
@classmethod
def load(cls, path: Path) -> Snapshot:
    """Read the committed snapshot file.

    Args:
        path: The snapshot's path.

    Returns:
        Snapshot: The parsed snapshot.
    """
    return cls.from_json(path.read_text(encoding="utf-8"))
to_json
to_json() -> str

The snapshot as committed: sorted, one interface per line.

Returns:

Name Type Description
str str

JSON text ending in a newline.

Source code in src/solidworks_mcp/progress/com_coverage.py
def to_json(self) -> str:
    """The snapshot as committed: sorted, one interface per line.

    Returns:
        str: JSON text ending in a newline.
    """
    lines = [
        f"  {json.dumps(name)}: {json.dumps(sorted(methods))}"
        for name, methods in sorted(self.interfaces.items())
    ]
    body = ",\n".join(lines)
    return (
        f'{{\n "type_library": {json.dumps(self.type_library)},\n'
        f' "interfaces": {{\n{body}\n }}\n}}\n'
    )

Functions:

adapter_sources

adapter_sources(adapters_dir: Path) -> list[str]

The text of every Python file under the adapters package.

Parameters:

Name Type Description Default
adapters_dir Path

src/solidworks_mcp/adapters.

required

Returns:

Type Description
list[str]

list[str]: One string per file, in path order.

Source code in src/solidworks_mcp/progress/com_coverage.py
def adapter_sources(adapters_dir: Path) -> list[str]:
    """The text of every Python file under the adapters package.

    Args:
        adapters_dir: ``src/solidworks_mcp/adapters``.

    Returns:
        list[str]: One string per file, in path order.
    """
    return [p.read_text(encoding="utf-8") for p in sorted(adapters_dir.rglob("*.py"))]

called_names

called_names(sources: Iterable[str]) -> set[str]

Capitalised names the source uses as attributes or string literals.

Parameters:

Name Type Description Default
sources Iterable[str]

The text of each source file.

required

Returns:

Type Description
set[str]

set[str]: Candidate COM member names (not yet matched to the API).

Source code in src/solidworks_mcp/progress/com_coverage.py
def called_names(sources: Iterable[str]) -> set[str]:
    """Capitalised names the source uses as attributes or string literals.

    Args:
        sources: The text of each source file.

    Returns:
        set[str]: Candidate COM member names (not yet matched to the API).
    """
    found: set[str] = set()
    for text in sources:
        found.update(_ATTRIBUTE.findall(text))
        found.update(_QUOTED.findall(text))
    return found

measure

measure(snapshot: Snapshot, called: set[str]) -> ComCoverage

Coverage of the core interfaces and the whole API.

Parameters:

Name Type Description Default
snapshot Snapshot

The type library's names.

required
called set[str]

Names found in the adapter source.

required

Returns:

Name Type Description
ComCoverage ComCoverage

The counts.

Source code in src/solidworks_mcp/progress/com_coverage.py
def measure(snapshot: Snapshot, called: set[str]) -> ComCoverage:
    """Coverage of the core interfaces and the whole API.

    Args:
        snapshot: The type library's names.
        called: Names found in the adapter source.

    Returns:
        ComCoverage: The counts.
    """
    every = set().union(*snapshot.interfaces.values())
    interfaces = tuple(
        InterfaceCoverage(
            name,
            tuple(sorted(snapshot.interfaces.get(name, frozenset()) & called)),
            len(snapshot.interfaces.get(name, frozenset())),
        )
        for name in CORE_INTERFACES
    )
    return ComCoverage(
        interfaces, len(every & called), len(every), snapshot.type_library
    )