1
- """Implements the Version extension.
1
+ """Implements the Versioning Indicators extension.
2
2
3
- https://github.com/ stac-extensions/ version
3
+ : stac-ext: version
4
4
"""
5
5
from enum import Enum
6
6
from pystac .utils import get_required , map_opt
@@ -50,18 +50,19 @@ class VersionExtension(
50
50
PropertiesExtension ,
51
51
ExtensionManagementMixin [Union [pystac .Collection , pystac .Item ]],
52
52
):
53
- """VersionItemExt extends Item to add version and deprecated properties
54
- along with links to the latest, predecessor, and successor Items.
53
+ """An abstract class that can be used to extend the properties of an
54
+ :class:`~pystac.Item` or :class:`~pystac.Collection` with properties from the
55
+ :stac-ext:`Versioning Indicators Extension <version>`. This class is generic over
56
+ the type of STAC Object to be extended (e.g. :class:`~pystac.Item`,
57
+ :class:`~pystac.Collection`).
55
58
56
- Args:
57
- item : The item to be extended.
59
+ To create a concrete instance of :class:`VersionExtension`, use the
60
+ :meth:`VersionExtension.ext` method. For example:
58
61
59
- Attributes:
60
- item : The item that is being extended.
62
+ .. code-block:: python
61
63
62
- Note:
63
- Using VersionItemExt to directly wrap an item will add the 'version'
64
- extension ID to the item's stac_extensions.
64
+ >>> item: pystac.Item = ...
65
+ >>> version_ext = VersionExtension.ext(item)
65
66
"""
66
67
67
68
obj : pystac .STACObject
@@ -77,16 +78,18 @@ def apply(
77
78
predecessor : Optional [T ] = None ,
78
79
successor : Optional [T ] = None ,
79
80
) -> None :
80
- """Applies version extension properties to the extended Item.
81
+ """Applies version extension properties to the extended :class:`~pystac.Item` or
82
+ :class:`~pystac.Collection`.
81
83
82
84
Args:
83
85
version : The version string for the item.
84
- deprecated : Optional flag set to True if an Item is
85
- deprecated with the potential to be removed. Defaults to false
86
- if not present.
87
- latest : Item with the latest (e.g., current) version.
88
- predecessor : Item with the previous version.
89
- successor : Item with the next most recent version.
86
+ deprecated : Optional flag set to ``True`` if an Item is deprecated with the
87
+ potential to be removed. Defaults to ``False`` if not present.
88
+ latest : Item representing the latest (e.g., current) version.
89
+ predecessor : Item representing the resource containing the predecessor
90
+ version in the version history.
91
+ successor : Item representing the resource containing the successor version
92
+ in the version history.
90
93
"""
91
94
self .version = version
92
95
if deprecated is not None :
@@ -100,11 +103,8 @@ def apply(
100
103
101
104
@property
102
105
def version (self ) -> str :
103
- """Get or sets a version string of the item.
104
-
105
- Returns:
106
- str
107
- """
106
+ """Get or sets a version string of the :class:`~pystac.Item` or
107
+ :class:`pystac.Collection`."""
108
108
return get_required (self ._get_property (VERSION , str ), self , VERSION )
109
109
110
110
@version .setter
@@ -113,7 +113,14 @@ def version(self, v: str) -> None:
113
113
114
114
@property
115
115
def deprecated (self ) -> Optional [bool ]:
116
- """Get or sets is the item is deprecated."""
116
+ """Get or sets whether the item is deprecated.
117
+
118
+ A value of ``True`` specifies that the Collection or Item is deprecated with the
119
+ potential to be removed. It should be transitioned out of usage as soon as
120
+ possible and users should refrain from using it in new projects. A link with
121
+ relation type ``latest-version`` SHOULD be added to the links and MUST refer to
122
+ the resource that can be used instead.
123
+ """
117
124
return self ._get_property (DEPRECATED , bool )
118
125
119
126
@deprecated .setter
@@ -122,50 +129,66 @@ def deprecated(self, v: Optional[bool]) -> None:
122
129
123
130
@property
124
131
def latest (self ) -> Optional [T ]:
125
- """Get or sets the most recent version."""
132
+ """Gets or sets the :class:`~pystac.Link` to the :class:`~pystac.Item`
133
+ representing the most recent version.
134
+ """
126
135
return map_opt (
127
136
lambda x : cast (T , x ),
128
137
next (iter (self .obj .get_stac_objects (VersionRelType .LATEST )), None ),
129
138
)
130
139
131
140
@latest .setter
132
- def latest (self , item : Optional [T ]) -> None :
141
+ def latest (self , item_or_collection : Optional [T ]) -> None :
133
142
self .obj .clear_links (VersionRelType .LATEST )
134
- if item is not None :
143
+ if item_or_collection is not None :
135
144
self .obj .add_link (
136
- pystac .Link (VersionRelType .LATEST , item , pystac .MediaType .JSON )
145
+ pystac .Link (
146
+ VersionRelType .LATEST , item_or_collection , pystac .MediaType .JSON
147
+ )
137
148
)
138
149
139
150
@property
140
151
def predecessor (self ) -> Optional [T ]:
141
- """Get or sets the previous item."""
152
+ """Gets or sets the :class:`~pystac.Link` to the :class:`~pystac.Item`
153
+ representing the resource containing the predecessor version in the version
154
+ history.
155
+ """
142
156
return map_opt (
143
157
lambda x : cast (T , x ),
144
158
next (iter (self .obj .get_stac_objects (VersionRelType .PREDECESSOR )), None ),
145
159
)
146
160
147
161
@predecessor .setter
148
- def predecessor (self , item : Optional [T ]) -> None :
162
+ def predecessor (self , item_or_collection : Optional [T ]) -> None :
149
163
self .obj .clear_links (VersionRelType .PREDECESSOR )
150
- if item is not None :
164
+ if item_or_collection is not None :
151
165
self .obj .add_link (
152
- pystac .Link (VersionRelType .PREDECESSOR , item , pystac .MediaType .JSON )
166
+ pystac .Link (
167
+ VersionRelType .PREDECESSOR ,
168
+ item_or_collection ,
169
+ pystac .MediaType .JSON ,
170
+ )
153
171
)
154
172
155
173
@property
156
174
def successor (self ) -> Optional [T ]:
157
- """Get or sets the next item."""
175
+ """Gets or sets the :class:`~pystac.Link` to the :class:`~pystac.Item`
176
+ representing the resource containing the successor version in the version
177
+ history.
178
+ """
158
179
return map_opt (
159
180
lambda x : cast (T , x ),
160
181
next (iter (self .obj .get_stac_objects (VersionRelType .SUCCESSOR )), None ),
161
182
)
162
183
163
184
@successor .setter
164
- def successor (self , item : Optional [T ]) -> None :
185
+ def successor (self , item_or_collection : Optional [T ]) -> None :
165
186
self .obj .clear_links (VersionRelType .SUCCESSOR )
166
- if item is not None :
187
+ if item_or_collection is not None :
167
188
self .obj .add_link (
168
- pystac .Link (VersionRelType .SUCCESSOR , item , pystac .MediaType .JSON )
189
+ pystac .Link (
190
+ VersionRelType .SUCCESSOR , item_or_collection , pystac .MediaType .JSON
191
+ )
169
192
)
170
193
171
194
@classmethod
@@ -174,6 +197,16 @@ def get_schema_uri(cls) -> str:
174
197
175
198
@staticmethod
176
199
def ext (obj : T ) -> "VersionExtension[T]" :
200
+ """Extends the given STAC Object with properties from the :stac-ext:`Versioning
201
+ Indicators Extension <version>`.
202
+
203
+ This extension can be applied to instances of :class:`~pystac.Item` or
204
+ :class:`~pystac.Collection`.
205
+
206
+ Raises:
207
+
208
+ pystac.ExtensionTypeError : If an invalid object type is passed.
209
+ """
177
210
if isinstance (obj , pystac .Collection ):
178
211
return cast (VersionExtension [T ], CollectionVersionExtension (obj ))
179
212
if isinstance (obj , pystac .Item ):
@@ -185,6 +218,15 @@ def ext(obj: T) -> "VersionExtension[T]":
185
218
186
219
187
220
class CollectionVersionExtension (VersionExtension [pystac .Collection ]):
221
+ """A concrete implementation of :class:`VersionExtension` on a
222
+ :class:`~pystac.Collection` that extends the properties of the Collection to
223
+ include properties defined in the :stac-ext:`Versioning Indicators Extension
224
+ <version>`.
225
+
226
+ This class should generally not be instantiated directly. Instead, call
227
+ :meth:`VersionExtension.ext` on an :class:`~pystac.Collection` to extend it.
228
+ """
229
+
188
230
def __init__ (self , collection : pystac .Collection ):
189
231
self .collection = collection
190
232
self .properties = collection .extra_fields
@@ -196,6 +238,14 @@ def __repr__(self) -> str:
196
238
197
239
198
240
class ItemVersionExtension (VersionExtension [pystac .Item ]):
241
+ """A concrete implementation of :class:`VersionExtension` on an
242
+ :class:`~pystac.Item` that extends the properties of the Item to include properties
243
+ defined in the :stac-ext:`Versioning Indicators Extension <version>`.
244
+
245
+ This class should generally not be instantiated directly. Instead, call
246
+ :meth:`VersionExtension.ext` on an :class:`~pystac.Item` to extend it.
247
+ """
248
+
199
249
def __init__ (self , item : pystac .Item ):
200
250
self .item = item
201
251
self .properties = item .properties
0 commit comments