Skip to content

Commit 1547836

Browse files
committed
Use Enum for Provider role field
1 parent 34708f2 commit 1547836

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

docs/api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ TemporalExtent
8686
:members:
8787
:undoc-members:
8888

89+
ProviderRole
90+
~~~~~~~~~~~~
91+
92+
.. autoclass:: pystac.ProviderRole
93+
:members:
94+
:undoc-members:
95+
:show-inheritance:
96+
8997
Provider
9098
~~~~~~~~
9199

pystac/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
SpatialExtent,
3333
TemporalExtent,
3434
Provider,
35+
ProviderRole,
3536
Summaries,
3637
)
3738
from pystac.summaries import RangeSummary

pystac/collection.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from copy import deepcopy
22
from datetime import datetime as Datetime
3+
from enum import Enum
34
from pystac.errors import STACTypeError
45
from typing import (
56
Any,
@@ -408,6 +409,18 @@ def from_items(
408409
return Extent(spatial=spatial, temporal=temporal, extra_fields=extra_fields)
409410

410411

412+
class ProviderRole(str, Enum):
413+
"""Enumerates the allows values of the Provider "role" field."""
414+
415+
def __str__(self) -> str:
416+
return str(self.value)
417+
418+
LICENSOR = "licensor"
419+
PRODUCER = "producer"
420+
PROCESSOR = "processor"
421+
HOST = "host"
422+
423+
411424
class Provider:
412425
"""Provides information about a provider of STAC data. A provider is any of the
413426
organizations that captured or processed the content of the collection and therefore
@@ -436,7 +449,7 @@ class Provider:
436449
information such as processing details for processors and producers,
437450
hosting details for hosts or basic contact information."""
438451

439-
roles: Optional[List[str]]
452+
roles: Optional[List[ProviderRole]]
440453
"""Optional roles of the provider. Any of
441454
licensor, producer, processor or host."""
442455

@@ -452,7 +465,7 @@ def __init__(
452465
self,
453466
name: str,
454467
description: Optional[str] = None,
455-
roles: Optional[List[str]] = None,
468+
roles: Optional[List[ProviderRole]] = None,
456469
url: Optional[str] = None,
457470
extra_fields: Optional[Dict[str, Any]] = None,
458471
):

tests/test_item.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import unittest
88

99
import pystac
10-
from pystac import Asset, Item, Provider
10+
from pystac import Asset, Item, Provider, ProviderRole
1111
from pystac.validation import validate_dict
1212
import pystac.serialization.common_properties
1313
from pystac.item import CommonMetadata
@@ -532,7 +532,7 @@ def test_asset_providers(self) -> None:
532532
pystac.Provider(
533533
name="USGS",
534534
url="https://landsat.usgs.gov/",
535-
roles=["producer", "licensor"],
535+
roles=[ProviderRole.PRODUCER, ProviderRole.LICENSOR],
536536
)
537537
]
538538

@@ -546,7 +546,9 @@ def test_asset_providers(self) -> None:
546546
# Set
547547
set_value = [
548548
pystac.Provider(
549-
name="John Snow", url="https://cholera.com/", roles=["producer"]
549+
name="John Snow",
550+
url="https://cholera.com/",
551+
roles=[ProviderRole.PRODUCER],
550552
)
551553
]
552554
cm.set_providers(set_value, item.assets["analytic"])

0 commit comments

Comments
 (0)