Skip to content

Commit 56f0ed0

Browse files
committed
added extension migration
1 parent e25e615 commit 56f0ed0

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

pystac/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
warnings.filterwarnings("ignore", category=DeprecationWarning)
101101
import pystac.extensions.label
102102
import pystac.extensions.mgrs
103+
import pystac.extensions.mlm
103104
import pystac.extensions.pointcloud
104105
import pystac.extensions.projection
105106
import pystac.extensions.raster
@@ -123,6 +124,7 @@
123124
pystac.extensions.item_assets.ITEM_ASSETS_EXTENSION_HOOKS,
124125
pystac.extensions.label.LABEL_EXTENSION_HOOKS,
125126
pystac.extensions.mgrs.MGRS_EXTENSION_HOOKS,
127+
pystac.extensions.mlm.MLM_EXTENSION_HOOKS,
126128
pystac.extensions.pointcloud.POINTCLOUD_EXTENSION_HOOKS,
127129
pystac.extensions.projection.PROJECTION_EXTENSION_HOOKS,
128130
pystac.extensions.raster.RASTER_EXTENSION_HOOKS,

pystac/extensions/mlm.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
PropertiesExtension,
2020
)
2121
from pystac.extensions.classification import Classification
22+
from pystac.extensions.hooks import ExtensionHooks
2223
from pystac.extensions.raster import DataType
24+
from pystac.serialization.identify import STACJSONDescription, STACVersionID
2325
from pystac.utils import StringEnum, get_required
2426

2527
T = TypeVar(
@@ -1718,6 +1720,7 @@ class _AssetMLMExtension(ABC):
17181720
Abstract base class for (derived) MLM asset extensions.
17191721
"""
17201722

1723+
name: Literal["mlm"] = "mlm"
17211724
asset: pystac.Asset
17221725
asset_href: str
17231726
properties: dict[str, Any]
@@ -2009,3 +2012,41 @@ def __init__(self, item_asset: pystac.ItemAssetDefinition):
20092012

20102013
def __repr__(self) -> str:
20112014
return f"<ItemAssetsMLMExtension ItemAssetDefinition={self.asset_defn}"
2015+
2016+
2017+
class MLMExtensionHooks(ExtensionHooks):
2018+
schema_uri: str = SCHEMA_URI_PATTERN.format(version=DEFAULT_VERSION)
2019+
prev_extension_ids = {
2020+
SCHEMA_URI_PATTERN.format(version=v)
2021+
for v in SUPPORTED_VERSIONS
2022+
if v != DEFAULT_VERSION
2023+
}
2024+
stac_object_types = {pystac.STACObjectType.ITEM, pystac.STACObjectType.COLLECTION}
2025+
2026+
def migrate(
2027+
self, obj: dict[str, Any], version: STACVersionID, info: STACJSONDescription
2028+
) -> None:
2029+
# migrate from 1.0.0 to 1.1.0
2030+
if SCHEMA_URI_PATTERN.format(version="1.0.0") in info.extensions:
2031+
# no migrations needed
2032+
pass
2033+
2034+
# migrate from 1.1.0 to 1.2.0
2035+
if SCHEMA_URI_PATTERN.format(version="1.1.0") in info.extensions:
2036+
# no migrations needed
2037+
pass
2038+
2039+
# migrate from 1.2.0 to 1.3.0
2040+
if SCHEMA_URI_PATTERN.format(version="1.2.0") in info.extensions:
2041+
# no migration needed
2042+
pass
2043+
2044+
# migrate from 1.3.0 to 1.4.0
2045+
if SCHEMA_URI_PATTERN.format(version="1.3.0") in info.extensions:
2046+
# no migration needed
2047+
pass
2048+
2049+
super().migrate(obj, version, info)
2050+
2051+
2052+
MLM_EXTENSION_HOOKS: ExtensionHooks = MLMExtensionHooks()

0 commit comments

Comments
 (0)