Skip to content

Commit

Permalink
Document __init__
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Maruseac <[email protected]>
  • Loading branch information
mihaimaruseac committed Jul 20, 2024
1 parent 53ce736 commit 7e0d225
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions model_signing/serialization/serialize_by_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,15 @@ def __init__(
"""Builds a node in the digest tree.
Don't call this from outside of the class. Instead, use `build_tree`.
Args:
path: Path included in the node.
digest: Optional hash of the path. Files must have a digest,
directories never have one.
"""
self._path = path
self._digest = digest
self._children: set[_FileDigestTree] = set()
self._children: list[_FileDigestTree] = []

@classmethod
def build_tree(
Expand All @@ -212,10 +217,14 @@ def build_tree(
file = file_item.path
node = cls(file, file_item.digest)
for parent in file.parents:
if parent not in path_to_node:
path_to_node[parent] = cls(parent)
parent_node = path_to_node[parent]
parent_node._children.add(node)
if parent in path_to_node:
parent_node = path_to_node[parent]
parent_node._children.append(node)
break # everything else already exists

parent_node = cls(parent) # no digest for directories
parent_node._children.append(node)
path_to_node[parent] = parent_node
node = parent_node

# Handle empty model
Expand Down

0 comments on commit 7e0d225

Please sign in to comment.