Skip to content

Commit 3186644

Browse files
committed
Move Provider to separate module
1 parent 9a7498b commit 3186644

File tree

4 files changed

+117
-112
lines changed

4 files changed

+117
-112
lines changed

pystac/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,13 @@
3030
Extent,
3131
SpatialExtent,
3232
TemporalExtent,
33-
Provider,
34-
ProviderRole,
3533
Summaries,
3634
)
3735
from pystac.common_metadata import CommonMetadata
3836
from pystac.summaries import RangeSummary
3937
from pystac.item import Item, Asset
4038
from pystac.item_collection import ItemCollection
41-
39+
from pystac.provider import ProviderRole, Provider
4240
import pystac.validation
4341

4442
import pystac.extensions.hooks

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)

pystac/common_metadata.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pystac import utils
66

77
if TYPE_CHECKING:
8-
from pystac.collection import Provider
8+
from pystac.provider import Provider
99
from pystac.asset import Asset
1010

1111

@@ -91,11 +91,15 @@ def set_start_datetime(
9191
"""
9292
if asset is None:
9393
self.properties["start_datetime"] = (
94-
None if start_datetime is None else utils.datetime_to_str(start_datetime)
94+
None
95+
if start_datetime is None
96+
else utils.datetime_to_str(start_datetime)
9597
)
9698
else:
9799
asset.extra_fields["start_datetime"] = (
98-
None if start_datetime is None else utils.datetime_to_str(start_datetime)
100+
None
101+
if start_datetime is None
102+
else utils.datetime_to_str(start_datetime)
99103
)
100104

101105
@property
@@ -206,7 +210,9 @@ def providers(self) -> Optional[List["Provider"]]:
206210
def providers(self, v: Optional[List["Provider"]]) -> None:
207211
self.set_providers(v)
208212

209-
def get_providers(self, asset: Optional["Asset"] = None) -> Optional[List["Provider"]]:
213+
def get_providers(
214+
self, asset: Optional["Asset"] = None
215+
) -> Optional[List["Provider"]]:
210216
"""Gets an Item or an Asset providers.
211217
212218
If an Asset is supplied and the Item property exists on the Asset,

pystac/provider.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
from enum import Enum
2+
from typing import Any, Dict, List, Optional
3+
4+
class ProviderRole(str, Enum):
5+
"""Enumerates the allows values of the Provider "role" field."""
6+
7+
LICENSOR = "licensor"
8+
PRODUCER = "producer"
9+
PROCESSOR = "processor"
10+
HOST = "host"
11+
12+
13+
class Provider:
14+
"""Provides information about a provider of STAC data. A provider is any of the
15+
organizations that captured or processed the content of the collection and therefore
16+
influenced the data offered by this collection. May also include information about
17+
the final storage provider hosting the data.
18+
19+
Args:
20+
name : The name of the organization or the individual.
21+
description : Optional multi-line description to add further provider
22+
information such as processing details for processors and producers,
23+
hosting details for hosts or basic contact information.
24+
roles : Optional roles of the provider. Any of
25+
licensor, producer, processor or host.
26+
url : Optional homepage on which the provider describes the dataset
27+
and publishes contact information.
28+
extra_fields : Optional dictionary containing additional top-level fields
29+
defined on the Provider object.
30+
"""
31+
32+
name: str
33+
"""The name of the organization or the individual."""
34+
35+
description: Optional[str]
36+
"""Optional multi-line description to add further provider
37+
information such as processing details for processors and producers,
38+
hosting details for hosts or basic contact information."""
39+
40+
roles: Optional[List[ProviderRole]]
41+
"""Optional roles of the provider. Any of
42+
licensor, producer, processor or host."""
43+
44+
url: Optional[str]
45+
"""Optional homepage on which the provider describes the dataset
46+
and publishes contact information."""
47+
48+
extra_fields: Dict[str, Any]
49+
"""Dictionary containing additional top-level fields defined on the Provider
50+
object."""
51+
52+
def __init__(
53+
self,
54+
name: str,
55+
description: Optional[str] = None,
56+
roles: Optional[List[ProviderRole]] = None,
57+
url: Optional[str] = None,
58+
extra_fields: Optional[Dict[str, Any]] = None,
59+
):
60+
self.name = name
61+
self.description = description
62+
self.roles = roles
63+
self.url = url
64+
self.extra_fields = extra_fields or {}
65+
66+
def to_dict(self) -> Dict[str, Any]:
67+
"""Generate a dictionary representing the JSON of this Provider.
68+
69+
Returns:
70+
dict: A serialization of the Provider that can be written out as JSON.
71+
"""
72+
d: Dict[str, Any] = {"name": self.name}
73+
if self.description is not None:
74+
d["description"] = self.description
75+
if self.roles is not None:
76+
d["roles"] = self.roles
77+
if self.url is not None:
78+
d["url"] = self.url
79+
80+
d.update(self.extra_fields)
81+
82+
return d
83+
84+
@staticmethod
85+
def from_dict(d: Dict[str, Any]) -> "Provider":
86+
"""Constructs an Provider from a dict.
87+
88+
Returns:
89+
Provider: The Provider deserialized from the JSON dict.
90+
"""
91+
return Provider(
92+
name=d["name"],
93+
description=d.get("description"),
94+
roles=d.get(
95+
"roles",
96+
),
97+
url=d.get("url"),
98+
extra_fields={
99+
k: v
100+
for k, v in d.items()
101+
if k not in {"name", "description", "roles", "url"}
102+
},
103+
)

0 commit comments

Comments
 (0)