Skip to content

solidworks_mcp.progress.snapshot

solidworks_mcp.progress.snapshot

Refresh the committed type-library snapshot (Windows, SolidWorks installed).

Run after a SolidWorks upgrade, then regenerate the progress files::

python -m solidworks_mcp.progress.snapshot
python -m solidworks_mcp.progress.generate

It reads the pywin32 gen_py wrapper of sldworks.tlb; SolidWorks itself doesn't need to be running.

Attributes

SNAPSHOT_PATH module-attribute

SNAPSHOT_PATH = Path('docs/assets/progress/com_snapshot.json')

Classes

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:

main

main(root: Path | None = None) -> Path

Write the snapshot under root.

Parameters:

Name Type Description Default
root Path | None

The repository root; the current directory when omitted.

None

Returns:

Name Type Description
Path Path

The file written.

Source code in src/solidworks_mcp/progress/snapshot.py
def main(root: Path | None = None) -> Path:
    """Write the snapshot under ``root``.

    Args:
        root: The repository root; the current directory when omitted.

    Returns:
        Path: The file written.
    """
    path = (root or Path.cwd()) / SNAPSHOT_PATH
    path.parent.mkdir(parents=True, exist_ok=True)
    path.write_text(take_snapshot().to_json(), encoding="utf-8", newline="\n")
    return path

take_snapshot

take_snapshot() -> Snapshot

Read the installed type library's interface and method names.

Returns:

Name Type Description
Snapshot Snapshot

The names, with the wrapper's module name as its source.

Raises:

Type Description
RuntimeError

If the gen_py wrapper isn't available.

Source code in src/solidworks_mcp/progress/snapshot.py
def take_snapshot() -> Snapshot:
    """Read the installed type library's interface and method names.

    Returns:
        Snapshot: The names, with the wrapper's module name as its source.

    Raises:
        RuntimeError: If the gen_py wrapper isn't available.
    """
    library = sw_type_info.type_library_name()
    if library is None:
        raise RuntimeError(
            "The SolidWorks type library isn't available: run this on Windows "
            "with SolidWorks and pywin32 installed."
        )
    # The module name carries the IID and version; keep the part after gen_py.
    return Snapshot(library.rsplit(".", 1)[-1], sw_type_info.all_interface_methods())