Skip to content

Commit c1bb46b

Browse files
committed
repository: Improve docstrings
Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent 3e4ef61 commit c1bb46b

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

examples/repository/_simplerepo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def __init__(self) -> None:
5959
self.signer_cache: Dict[str, List[Signer]] = defaultdict(list)
6060
# all target content
6161
self.target_cache: Dict[str, bytes] = {}
62-
# version cache for snapshot and all targets, updated in close()
62+
# version cache for snapshot and all targets, updated in close().
63+
# The 'defaultdict(lambda: ...)' trick allows close() to easily modify
64+
# the version without always creating a new MetaFile
6365
self._snapshot_info = MetaFile(1)
6466
self._targets_infos: Dict[str, MetaFile] = defaultdict(
6567
lambda: MetaFile(1)

tuf/repository/_repository.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,31 @@ def close(self, role: str, md: Metadata, sign_only: bool = False) -> None:
5555
@property
5656
@abstractmethod
5757
def targets_infos(self) -> Dict[str, MetaFile]:
58-
"""Returns the current targets version information
58+
"""Returns the MetaFiles for current targets metadatas
5959
60-
Not that there is a difference between this and the published snapshot
61-
meta: This dictionary reflects the targets metadata that currently
62-
exists in the repository, but the dictionary published by snapshot()
63-
will also include metadata that no longer exists in the repository.
60+
This property is used by snapshot() to update Snapshot.meta.
61+
62+
Note that there is a difference between this return value and
63+
Snapshot.meta: This dictionary reflects the targets metadata that
64+
currently exists in the repository but Snapshot.meta also includes
65+
metadata that used to exist, but no longer exists, in the repository.
6466
"""
6567
raise NotImplementedError
6668

6769
@property
6870
@abstractmethod
6971
def snapshot_info(self) -> MetaFile:
70-
"""Returns the information matching current snapshot metadata"""
72+
"""Returns the MetaFile for current snapshot metadata
73+
74+
This property is used by timestamp() to update Timestamp.meta.
75+
"""
7176
raise NotImplementedError
7277

7378
@contextmanager
7479
def edit(
7580
self, role: str, init: bool = False
7681
) -> Generator[Signed, None, None]:
77-
"""Context manager for editing a roles metadata
82+
"""Context manager for editing a role's metadata
7883
7984
Context manager takes care of loading the roles metadata (or creating
8085
new metadata if 'init'), updating expiry and version. The caller can do
@@ -106,7 +111,7 @@ def snapshot(self, force: bool = False) -> Tuple[bool, Dict[str, MetaFile]]:
106111
107112
Returns: Tuple of
108113
- True if snapshot was created, False if not
109-
- Meta information for targets metadata that was removed from snapshot
114+
- MetaFiles for targets versions removed from snapshot meta
110115
"""
111116

112117
# Snapshot update is needed if
@@ -149,7 +154,7 @@ def timestamp(self, force: bool = False) -> Tuple[bool, Optional[MetaFile]]:
149154
150155
Returns: Tuple of
151156
- True if timestamp was created, False if not
152-
- Meta information for snapshot metadata that was removed from timestamp
157+
- MetaFile for snapshot version removed from timestamp (if any)
153158
"""
154159
update_version = force
155160
removed = None

0 commit comments

Comments
 (0)