Skip to content

Commit fdfc773

Browse files
committed
Improve gardenlinux.oci docstrings
Signed-off-by: Tobias Wolf <[email protected]>
1 parent 095332c commit fdfc773

File tree

9 files changed

+249
-110
lines changed

9 files changed

+249
-110
lines changed

.github/actions/features_parse/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ outputs:
1111
runs:
1212
using: composite
1313
steps:
14-
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/[email protected].0
14+
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/[email protected].2
1515
- id: result
1616
shell: bash
1717
run: |

.github/actions/flavors_parse/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ outputs:
1313
runs:
1414
using: composite
1515
steps:
16-
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/[email protected].0
16+
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/[email protected].2
1717
- id: matrix
1818
shell: bash
1919
run: |

.github/actions/setup/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Installs the given GardenLinux Python library
33
inputs:
44
version:
55
description: GardenLinux Python library version
6-
default: "0.7.0"
6+
default: "0.7.2"
77
runs:
88
using: composite
99
steps:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "gardenlinux"
3-
version = "0.7.0"
3+
version = "0.7.2"
44
description = "Contains tools to work with the features directory of gardenlinux, for example deducting dependencies from feature sets or validating cnames"
55
authors = ["Garden Linux Maintainers <[email protected]>"]
66
license = "Apache-2.0"

src/gardenlinux/oci/container.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Container(Registry):
3939
:author: Garden Linux Maintainers
4040
:copyright: Copyright 2024 SAP SE
4141
:package: gardenlinux
42-
:subpackage: flavors
42+
:subpackage: oci
4343
:since: 0.7.0
4444
:license: https://www.apache.org/licenses/LICENSE-2.0
4545
Apache License, Version 2.0
@@ -401,7 +401,7 @@ def push_manifest_and_artifacts(
401401
cleanup_blob = True
402402

403403
manifest.append_layer(layer)
404-
layer_dict = layer.to_dict()
404+
layer_dict = layer.dict
405405

406406
self._logger.debug(f"Layer: {layer_dict}")
407407

src/gardenlinux/oci/index.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,25 @@
77

88

99
class Index(dict):
10+
"""
11+
OCI image index
12+
13+
:author: Garden Linux Maintainers
14+
:copyright: Copyright 2024 SAP SE
15+
:package: gardenlinux
16+
:subpackage: oci
17+
:since: 0.7.0
18+
:license: https://www.apache.org/licenses/LICENSE-2.0
19+
Apache License, Version 2.0
20+
"""
21+
1022
def __init__(self, *args, **kwargs):
23+
"""
24+
Constructor __init__(Index)
25+
26+
:since: 0.7.0
27+
"""
28+
1129
dict.__init__(self)
1230

1331
self.update(deepcopy(EmptyIndex))
@@ -16,10 +34,24 @@ def __init__(self, *args, **kwargs):
1634

1735
@property
1836
def json(self):
37+
"""
38+
Returns the OCI image index as a JSON
39+
40+
:return: (bytes) OCI image index as JSON
41+
:since: 0.7.0
42+
"""
43+
1944
return json.dumps(self).encode("utf-8")
2045

2146
@property
2247
def manifests_as_dict(self):
48+
"""
49+
Returns the OCI image manifests of the index
50+
51+
:return: (dict) OCI image manifests with CNAME or digest as key
52+
:since: 0.7.0
53+
"""
54+
2355
manifests = {}
2456

2557
for manifest in self["manifests"]:
@@ -33,6 +65,14 @@ def manifests_as_dict(self):
3365
return manifests
3466

3567
def append_manifest(self, manifest):
68+
"""
69+
Appends the given OCI image manifest to the index
70+
71+
:param manifest: OCI image manifest
72+
73+
:since: 0.7.0
74+
"""
75+
3676
if not isinstance(manifest, dict):
3777
raise RuntimeError("Unexpected manifest type given")
3878

src/gardenlinux/oci/layer.py

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,34 @@
1313

1414

1515
class Layer(_Layer, Mapping):
16+
"""
17+
OCI image layer
18+
19+
:author: Garden Linux Maintainers
20+
:copyright: Copyright 2024 SAP SE
21+
:package: gardenlinux
22+
:subpackage: oci
23+
:since: 0.7.0
24+
:license: https://www.apache.org/licenses/LICENSE-2.0
25+
Apache License, Version 2.0
26+
"""
27+
1628
def __init__(
1729
self,
1830
blob_path: PathLike | str,
1931
media_type: Optional[str] = None,
2032
is_dir: bool = False,
2133
):
34+
"""
35+
Constructor __init__(Index)
36+
37+
:param blob_path: The path of the blob for the layer
38+
:param media_type: Media type for the blob (optional)
39+
:param is_dir: Is the blob a directory?
40+
41+
:since: 0.7.0
42+
"""
43+
2244
if not isinstance(blob_path, PathLike):
2345
blob_path = Path(blob_path)
2446

@@ -28,11 +50,26 @@ def __init__(
2850
ANNOTATION_TITLE: blob_path.name,
2951
}
3052

53+
@property
54+
def dict(self):
55+
"""
56+
Return a dictionary representation of the layer
57+
58+
:return: (dict) OCI manifest layer metadata dictionary
59+
:since: 0.7.2
60+
"""
61+
layer = _Layer.to_dict(self)
62+
layer["annotations"] = self._annotations
63+
64+
return layer
65+
3166
def __delitem__(self, key):
3267
"""
3368
python.org: Called to implement deletion of self[key].
3469
3570
:param key: Mapping key
71+
72+
:since: 0.7.0
3673
"""
3774

3875
if key == "annotations":
@@ -49,6 +86,7 @@ def __getitem__(self, key):
4986
:param key: Mapping key
5087
5188
:return: (mixed) Mapping key value
89+
:since: 0.7.0
5290
"""
5391

5492
if key == "annotations":
@@ -63,6 +101,7 @@ def __iter__(self):
63101
python.org: Return an iterator object.
64102
65103
:return: (object) Iterator object
104+
:since: 0.7.0
66105
"""
67106

68107
iter(_SUPPORTED_MAPPING_KEYS)
@@ -71,7 +110,8 @@ def __len__(self):
71110
"""
72111
python.org: Called to implement the built-in function len().
73112
74-
:return: (int) Number of database instance attributes
113+
:return: (int) Number of attributes
114+
:since: 0.7.0
75115
"""
76116

77117
return len(_SUPPORTED_MAPPING_KEYS)
@@ -82,6 +122,8 @@ def __setitem__(self, key, value):
82122
83123
:param key: Mapping key
84124
:param value: self[key] value
125+
126+
:since: 0.7.0
85127
"""
86128

87129
if key == "annotations":
@@ -91,21 +133,16 @@ def __setitem__(self, key, value):
91133
f"'{self.__class__.__name__}' object is not subscriptable except for keys: {_SUPPORTED_MAPPING_KEYS}"
92134
)
93135

94-
def to_dict(self):
95-
"""
96-
Return a dictionary representation of the layer
97-
"""
98-
layer = _Layer.to_dict(self)
99-
layer["annotations"] = self._annotations
100-
101-
return layer
102-
103136
@staticmethod
104137
def generate_metadata_from_file_name(file_name: PathLike | str, arch: str) -> dict:
105138
"""
106-
:param str file_name: file_name of the blob
107-
:param str arch: the arch of the target image
108-
:return: dict of oci layer metadata for a given layer file
139+
Generates OCI manifest layer metadata for the given file path and name.
140+
141+
:param file_name: File path and name of the target layer
142+
:param arch: The arch of the target image
143+
144+
:return: (dict) OCI manifest layer metadata dictionary
145+
:since: 0.7.0
109146
"""
110147

111148
if not isinstance(file_name, PathLike):
@@ -122,8 +159,12 @@ def generate_metadata_from_file_name(file_name: PathLike | str, arch: str) -> di
122159
@staticmethod
123160
def lookup_media_type_for_file_name(file_name: str) -> str:
124161
"""
125-
:param str file_name: file_name of the target layer
126-
:return: mediatype
162+
Looks up the media type based on file extension.
163+
164+
:param file_name: File path and name of the target layer
165+
166+
:return: (str) Media type
167+
:since: 0.7.0
127168
"""
128169

129170
if not isinstance(file_name, PathLike):

0 commit comments

Comments
 (0)