Skip to content

Commit 72cb40c

Browse files
committed
Update docstrings for version extension
1 parent 46fbaa7 commit 72cb40c

File tree

2 files changed

+102
-51
lines changed

2 files changed

+102
-51
lines changed

docs/api.rst

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ SingleFileSTACCatalogExt
484484
Version Extension
485485
-----------------
486486

487-
Implements the :stac-ext:`Version Extension <version>`.
487+
Implements the :stac-ext:`Versioning Indicators Extension <version>`.
488488

489489
VersionRelType
490490
~~~~~~~~~~~~~~
@@ -493,25 +493,26 @@ VersionRelType
493493
:members:
494494
:show-inheritance:
495495

496-
VersionCollectionExt
497-
~~~~~~~~~~~~~~~~~~~~
496+
VersionExtension
497+
~~~~~~~~~~~~~~~~
498498

499-
**TEMPORARILY REMOVED**
499+
.. autoclass:: pystac.extensions.version.VersionExtension
500+
:members:
501+
:show-inheritance:
500502

501-
.. .. autoclass:: pystac.extensions.version.VersionCollectionExt
502-
.. :members:
503-
.. :undoc-members:
504-
.. :show-inheritance:
503+
CollectionVersionExtension
504+
~~~~~~~~~~~~~~~~~~~~~~~~~~
505505

506-
VersionItemExt
507-
~~~~~~~~~~~~~~
506+
.. autoclass:: pystac.extensions.version.CollectionVersionExtension
507+
:members:
508+
:show-inheritance:
508509

509-
**TEMPORARILY REMOVED**
510+
ItemVersionExtension
511+
~~~~~~~~~~~~~~~~~~~~
510512

511-
.. .. autoclass:: pystac.extensions.version.VersionItemExt
512-
.. :members:
513-
.. :undoc-members:
514-
.. :show-inheritance:
513+
.. autoclass:: pystac.extensions.version.ItemVersionExtension
514+
:members:
515+
:show-inheritance:
515516

516517
View Geometry Extension
517518
-----------------------

pystac/extensions/version.py

Lines changed: 86 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
"""Implements the Version extension.
1+
"""Implements the Versioning Indicators extension.
22
3-
https://github.com/stac-extensions/version
3+
:stac-ext:version
44
"""
55
from enum import Enum
66
from pystac.utils import get_required, map_opt
@@ -50,18 +50,19 @@ class VersionExtension(
5050
PropertiesExtension,
5151
ExtensionManagementMixin[Union[pystac.Collection, pystac.Item]],
5252
):
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`).
5558
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:
5861
59-
Attributes:
60-
item : The item that is being extended.
62+
.. code-block:: python
6163
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)
6566
"""
6667

6768
obj: pystac.STACObject
@@ -77,16 +78,18 @@ def apply(
7778
predecessor: Optional[T] = None,
7879
successor: Optional[T] = None,
7980
) -> 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`.
8183
8284
Args:
8385
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.
9093
"""
9194
self.version = version
9295
if deprecated is not None:
@@ -100,11 +103,8 @@ def apply(
100103

101104
@property
102105
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`."""
108108
return get_required(self._get_property(VERSION, str), self, VERSION)
109109

110110
@version.setter
@@ -113,7 +113,14 @@ def version(self, v: str) -> None:
113113

114114
@property
115115
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+
"""
117124
return self._get_property(DEPRECATED, bool)
118125

119126
@deprecated.setter
@@ -122,50 +129,66 @@ def deprecated(self, v: Optional[bool]) -> None:
122129

123130
@property
124131
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+
"""
126135
return map_opt(
127136
lambda x: cast(T, x),
128137
next(iter(self.obj.get_stac_objects(VersionRelType.LATEST)), None),
129138
)
130139

131140
@latest.setter
132-
def latest(self, item: Optional[T]) -> None:
141+
def latest(self, item_or_collection: Optional[T]) -> None:
133142
self.obj.clear_links(VersionRelType.LATEST)
134-
if item is not None:
143+
if item_or_collection is not None:
135144
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+
)
137148
)
138149

139150
@property
140151
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+
"""
142156
return map_opt(
143157
lambda x: cast(T, x),
144158
next(iter(self.obj.get_stac_objects(VersionRelType.PREDECESSOR)), None),
145159
)
146160

147161
@predecessor.setter
148-
def predecessor(self, item: Optional[T]) -> None:
162+
def predecessor(self, item_or_collection: Optional[T]) -> None:
149163
self.obj.clear_links(VersionRelType.PREDECESSOR)
150-
if item is not None:
164+
if item_or_collection is not None:
151165
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+
)
153171
)
154172

155173
@property
156174
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+
"""
158179
return map_opt(
159180
lambda x: cast(T, x),
160181
next(iter(self.obj.get_stac_objects(VersionRelType.SUCCESSOR)), None),
161182
)
162183

163184
@successor.setter
164-
def successor(self, item: Optional[T]) -> None:
185+
def successor(self, item_or_collection: Optional[T]) -> None:
165186
self.obj.clear_links(VersionRelType.SUCCESSOR)
166-
if item is not None:
187+
if item_or_collection is not None:
167188
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+
)
169192
)
170193

171194
@classmethod
@@ -174,6 +197,16 @@ def get_schema_uri(cls) -> str:
174197

175198
@staticmethod
176199
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+
"""
177210
if isinstance(obj, pystac.Collection):
178211
return cast(VersionExtension[T], CollectionVersionExtension(obj))
179212
if isinstance(obj, pystac.Item):
@@ -185,6 +218,15 @@ def ext(obj: T) -> "VersionExtension[T]":
185218

186219

187220
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+
188230
def __init__(self, collection: pystac.Collection):
189231
self.collection = collection
190232
self.properties = collection.extra_fields
@@ -196,6 +238,14 @@ def __repr__(self) -> str:
196238

197239

198240
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+
199249
def __init__(self, item: pystac.Item):
200250
self.item = item
201251
self.properties = item.properties

0 commit comments

Comments
 (0)