Skip to content

Commit f83109c

Browse files
author
Jon Duckworth
authored
Merge pull request #563 from duckontheweb/change/gh-481-common-metadata
Use extension-like API for CommonMetadata
2 parents 3dff1b6 + 5a72a2a commit f83109c

File tree

9 files changed

+891
-1172
lines changed

9 files changed

+891
-1172
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Objects](https://github.com/stac-extensions/pointcloud#schema-object)
1919
([#548](https://github.com/stac-utils/pystac/pull/548))
2020
- `to_dict` and equality definition for `extensions.item_asset.AssetDefinition` ([#564](https://github.com/stac-utils/pystac/pull/564))
21+
- `Asset.common_metadata` property ([#563](https://github.com/stac-utils/pystac/pull/563))
2122

2223
### Removed
2324

pystac/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@
3030
Extent,
3131
SpatialExtent,
3232
TemporalExtent,
33-
Provider,
34-
ProviderRole,
3533
Summaries,
3634
)
35+
from pystac.common_metadata import CommonMetadata
3736
from pystac.summaries import RangeSummary
38-
from pystac.item import Item, Asset, CommonMetadata
37+
from pystac.item import Item, Asset
3938
from pystac.item_collection import ItemCollection
40-
39+
from pystac.provider import ProviderRole, Provider
4140
import pystac.validation
4241

4342
import pystac.extensions.hooks

pystac/asset.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from copy import copy
22
from typing import Any, Dict, List, Optional, TYPE_CHECKING, Union
33

4-
from pystac.utils import is_absolute_href, make_absolute_href
4+
from pystac import common_metadata
5+
from pystac import utils
56

67
if TYPE_CHECKING:
78
from pystac.collection import Collection as Collection_Type
9+
from pystac.common_metadata import CommonMetadata as CommonMetadata_Type
810
from pystac.item import Item as Item_Type
911

1012

@@ -94,11 +96,11 @@ def get_absolute_href(self) -> Optional[str]:
9496
str: The absolute HREF of this asset, or None if an absolute HREF could not
9597
be determined.
9698
"""
97-
if is_absolute_href(self.href):
99+
if utils.is_absolute_href(self.href):
98100
return self.href
99101
else:
100102
if self.owner is not None:
101-
return make_absolute_href(self.href, self.owner.get_self_href())
103+
return utils.make_absolute_href(self.href, self.owner.get_self_href())
102104
else:
103105
return None
104106

@@ -145,6 +147,12 @@ def clone(self) -> "Asset":
145147
extra_fields=self.extra_fields,
146148
)
147149

150+
@property
151+
def common_metadata(self) -> "CommonMetadata_Type":
152+
"""Access the asset's common metadata fields as a
153+
:class:`~pystac.CommonMetadata` object."""
154+
return common_metadata.CommonMetadata(self)
155+
148156
def __repr__(self) -> str:
149157
return "<Asset href={}>".format(self.href)
150158

pystac/collection.py

Lines changed: 3 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from copy import deepcopy
22
from datetime import datetime
3-
from enum import Enum
43
from pystac.errors import STACTypeError
54
from typing import (
65
Any,
@@ -34,6 +33,7 @@
3433

3534
if TYPE_CHECKING:
3635
from pystac.item import Item as Item_Type
36+
from pystac.provider import Provider as Provider_Type
3737

3838
T = TypeVar("T")
3939

@@ -409,108 +409,6 @@ def from_items(
409409
return Extent(spatial=spatial, temporal=temporal, extra_fields=extra_fields)
410410

411411

412-
class ProviderRole(str, Enum):
413-
"""Enumerates the allows values of the Provider "role" field."""
414-
415-
LICENSOR = "licensor"
416-
PRODUCER = "producer"
417-
PROCESSOR = "processor"
418-
HOST = "host"
419-
420-
421-
class Provider:
422-
"""Provides information about a provider of STAC data. A provider is any of the
423-
organizations that captured or processed the content of the collection and therefore
424-
influenced the data offered by this collection. May also include information about
425-
the final storage provider hosting the data.
426-
427-
Args:
428-
name : The name of the organization or the individual.
429-
description : Optional multi-line description to add further provider
430-
information such as processing details for processors and producers,
431-
hosting details for hosts or basic contact information.
432-
roles : Optional roles of the provider. Any of
433-
licensor, producer, processor or host.
434-
url : Optional homepage on which the provider describes the dataset
435-
and publishes contact information.
436-
extra_fields : Optional dictionary containing additional top-level fields
437-
defined on the Provider object.
438-
"""
439-
440-
name: str
441-
"""The name of the organization or the individual."""
442-
443-
description: Optional[str]
444-
"""Optional multi-line description to add further provider
445-
information such as processing details for processors and producers,
446-
hosting details for hosts or basic contact information."""
447-
448-
roles: Optional[List[ProviderRole]]
449-
"""Optional roles of the provider. Any of
450-
licensor, producer, processor or host."""
451-
452-
url: Optional[str]
453-
"""Optional homepage on which the provider describes the dataset
454-
and publishes contact information."""
455-
456-
extra_fields: Dict[str, Any]
457-
"""Dictionary containing additional top-level fields defined on the Provider
458-
object."""
459-
460-
def __init__(
461-
self,
462-
name: str,
463-
description: Optional[str] = None,
464-
roles: Optional[List[ProviderRole]] = None,
465-
url: Optional[str] = None,
466-
extra_fields: Optional[Dict[str, Any]] = None,
467-
):
468-
self.name = name
469-
self.description = description
470-
self.roles = roles
471-
self.url = url
472-
self.extra_fields = extra_fields or {}
473-
474-
def to_dict(self) -> Dict[str, Any]:
475-
"""Generate a dictionary representing the JSON of this Provider.
476-
477-
Returns:
478-
dict: A serialization of the Provider that can be written out as JSON.
479-
"""
480-
d: Dict[str, Any] = {"name": self.name}
481-
if self.description is not None:
482-
d["description"] = self.description
483-
if self.roles is not None:
484-
d["roles"] = self.roles
485-
if self.url is not None:
486-
d["url"] = self.url
487-
488-
d.update(self.extra_fields)
489-
490-
return d
491-
492-
@staticmethod
493-
def from_dict(d: Dict[str, Any]) -> "Provider":
494-
"""Constructs an Provider from a dict.
495-
496-
Returns:
497-
Provider: The Provider deserialized from the JSON dict.
498-
"""
499-
return Provider(
500-
name=d["name"],
501-
description=d.get("description"),
502-
roles=d.get(
503-
"roles",
504-
),
505-
url=d.get("url"),
506-
extra_fields={
507-
k: v
508-
for k, v in d.items()
509-
if k not in {"name", "description", "roles", "url"}
510-
},
511-
)
512-
513-
514412
class Collection(Catalog):
515413
"""A Collection extends the Catalog spec with additional metadata that helps
516414
enable discovery.
@@ -583,7 +481,7 @@ def __init__(
583481
catalog_type: Optional[CatalogType] = None,
584482
license: str = "proprietary",
585483
keywords: Optional[List[str]] = None,
586-
providers: Optional[List[Provider]] = None,
484+
providers: Optional[List["Provider_Type"]] = None,
587485
summaries: Optional[Summaries] = None,
588486
):
589487
super().__init__(
@@ -695,7 +593,7 @@ def from_dict(
695593
keywords = d.get("keywords")
696594
providers = d.get("providers")
697595
if providers is not None:
698-
providers = list(map(lambda x: Provider.from_dict(x), providers))
596+
providers = list(map(lambda x: pystac.Provider.from_dict(x), providers))
699597
summaries = d.get("summaries")
700598
if summaries is not None:
701599
summaries = Summaries(summaries)

0 commit comments

Comments
 (0)