Skip to content

utils

get_artifacts_from_artifactdef(db, artifact_entries)

Converts LineaArtifactDef list to a LineaArtfact list by initializing the artifacts from the db provided Artifact entries are specified as name and optionally version as the end user would specify.

Source code in lineapy/graph_reader/utils.py
25
26
27
28
29
30
31
32
33
34
35
def get_artifacts_from_artifactdef(
    db: RelationalLineaDB, artifact_entries: List[LineaArtifactDef]
) -> List[LineaArtifact]:
    """
    Converts LineaArtifactDef list to a LineaArtfact list by initializing the artifacts from the db provided
    Artifact entries are specified as name and optionally version as the end user would specify.
    """
    return [
        LineaArtifact.get_artifact_from_def(db, art_def)
        for art_def in artifact_entries
    ]

group_artifacts_by_session(all_linea_artifacts)

This helper function is used to group target and reuse_precomputed artifacts so that we can create SessionArtifacts for each Session.

Source code in lineapy/graph_reader/utils.py
38
39
40
41
42
43
44
45
46
47
48
49
50
def group_artifacts_by_session(
    all_linea_artifacts: List[LineaArtifact],
) -> Iterable[Tuple[LineaID, List[LineaArtifact]]]:
    """
    This helper function is used to group target and reuse_precomputed artifacts so that we can
    create SessionArtifacts for each Session.
    """
    # This function returns a generator
    #
    for session_id, artifacts_by_session in groupby(
        all_linea_artifacts, lambda d: d._session_id
    ):
        yield session_id, list(artifacts_by_session)

is_import_node(graph, node_id)

Given node_id, check whether it is a CallNode doing module import

Source code in lineapy/graph_reader/utils.py
10
11
12
13
14
15
16
17
18
19
20
21
22
def is_import_node(graph: Graph, node_id: LineaID) -> bool:
    """
    Given node_id, check whether it is a CallNode doing module import
    """
    node = graph.get_node(node_id)
    if isinstance(node, CallNode) and hasattr(node, "function_id"):
        lookup_node_id = node.__dict__.get("function_id", None)
        if lookup_node_id is not None:
            lookup_node = graph.get_node(lookup_node_id)
            if isinstance(lookup_node, LookupNode):
                lookup_node_name = lookup_node.__dict__.get("name", "")
                return lookup_node_name in ["l_import", "getattr"]
    return False

Was this helpful?

Help us improve docs with your feedback!