ml_switcheroo.analysis.dependencies¶

Static Dependency Analysis for Transpilation Safety.

This module provides the DependencyScanner, a LibCST visitor that identifies third-party dependencies imported in the source code.

It serves as a safety check during transpilation:

  1. Identifies imports (e.g., import pandas, from sklearn import metrics).

  2. Filters out Standard Library modules (e.g., os, sys, json).

  3. Filters out the Source Framework (e.g., torch), as these are handled by the core ImportFixer and PivotRewriter.

  4. Validates the remaining imports against the Semantics Manager.

If a third-party import (e.g., cv2) is found but not mapped in the semantics (Import Map), it warns the user that the target environment might lack the equivalent library or that the mapping logic is missing.

Classes¶

DependencyScanner

Scans for 3rd-party imports not covered by the Semantic Knowledge Base.

Module Contents¶

class ml_switcheroo.analysis.dependencies.DependencyScanner(semantics: ml_switcheroo.semantics.manager.SemanticsManager, source_fw: str)¶

Bases: libcst.CSTVisitor

Scans for 3rd-party imports not covered by the Semantic Knowledge Base.

semantics¶
source_fw¶
unknown_imports: Set[str]¶
visit_Import(node: libcst.Import) → None¶

Visits import x, import x.y. Checks the root package name.

visit_ImportFrom(node: libcst.ImportFrom) → None¶

Visits from x import y. Checks the module root package name.