Skip to content

Commit

Permalink
Export AssetDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
jsignell committed Dec 16, 2024
1 parent c80e307 commit a688988
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pystac/extensions/item_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import pystac
from pystac.extensions.base import ExtensionManagementMixin
from pystac.extensions.hooks import ExtensionHooks
from pystac.item_assets import (
ItemAssetDefinition as AssetDefinition,
)
from pystac.item_assets import ItemAssetDefinition
from pystac.serialization.identify import STACJSONDescription, STACVersionID
from pystac.utils import get_required

Expand All @@ -21,6 +19,12 @@
ITEM_ASSETS_PROP = "item_assets"


class AssetDefinition(ItemAssetDefinition):
def __init__(cls, *args: Any, **kwargs: Any) -> None:
# TODO: deprecation warning in here.
super().__init__(*args, **kwargs)


class ItemAssetsExtension(ExtensionManagementMixin[pystac.Collection]):
name: Literal["item_assets"] = "item_assets"
collection: pystac.Collection
Expand All @@ -29,16 +33,16 @@ def __init__(self, collection: pystac.Collection) -> None:
self.collection = collection

@property
def item_assets(self) -> dict[str, AssetDefinition]:
def item_assets(self) -> dict[str, ItemAssetDefinition]:
"""Gets or sets a dictionary of assets that can be found in member Items. Maps
the asset key to an :class:`AssetDefinition` instance."""
result: dict[str, Any] = get_required(
self.collection.extra_fields.get(ITEM_ASSETS_PROP), self, ITEM_ASSETS_PROP
)
return {k: AssetDefinition(v, self.collection) for k, v in result.items()}
return {k: ItemAssetDefinition(v, self.collection) for k, v in result.items()}

@item_assets.setter
def item_assets(self, v: dict[str, AssetDefinition]) -> None:
def item_assets(self, v: dict[str, ItemAssetDefinition]) -> None:
self.collection.extra_fields[ITEM_ASSETS_PROP] = {
k: asset_def.properties for k, asset_def in v.items()
}
Expand Down

0 comments on commit a688988

Please sign in to comment.