11from __future__ import annotations
22
3- import warnings
4-
5- warnings .warn (
6- message = "pystac.layout is deprecated" ,
7- category = DeprecationWarning ,
8- )
9-
103import posixpath
114from abc import ABC , abstractmethod
125from collections import OrderedDict
136from collections .abc import Callable
147from typing import TYPE_CHECKING , Any
158
16- import pystac
17- from pystac .utils import is_file_path
9+ from . errors import STACError
10+ from .utils import is_file_path
1811
1912if TYPE_CHECKING :
20- from pystac .catalog import Catalog
21- from pystac .collection import Collection
22- from pystac .item import Item
23- from pystac .stac_object import STACObject
13+ from .catalog import Catalog
14+ from .collection import Collection
15+ from .item import Item
16+ from .stac_object import STACObject
2417
2518
2619class TemplateError (Exception ):
@@ -132,15 +125,16 @@ def __init__(self, template: str, defaults: dict[str, str] | None = None) -> Non
132125
133126 def _get_template_value (self , stac_object : STACObject , template_var : str ) -> Any :
134127 if template_var in self .ITEM_TEMPLATE_VARS :
135- if isinstance (stac_object , pystac . Item ):
128+ if isinstance (stac_object , Item ):
136129 # Datetime
137130 dt = stac_object .datetime
138131 if dt is None :
139132 dt = stac_object .common_metadata .start_datetime
140133 if dt is None :
141- raise pystac . TemplateError (
134+ raise TemplateError (
142135 f"Item { stac_object } does not have a datetime or "
143- f"datetime range set; cannot template { template_var } in { self .template } "
136+ f"datetime range set; cannot template { template_var } "
137+ f"in { self .template } "
144138 )
145139
146140 if template_var == "year" :
@@ -156,20 +150,22 @@ def _get_template_value(self, stac_object: STACObject, template_var: str) -> Any
156150 if template_var == "collection" :
157151 if stac_object .collection_id is not None :
158152 return stac_object .collection_id
159- raise pystac . TemplateError (
153+ raise TemplateError (
160154 f"Item { stac_object } does not have a collection ID set; "
161155 f"cannot template { template_var } in { self .template } "
162156 )
163157 else :
164- raise pystac .TemplateError (
165- f'"{ template_var } " cannot be used to template non-Item { stac_object } in { self .template } '
158+ raise TemplateError (
159+ f'"{ template_var } " cannot be used to template non-Item "'
160+ f"{ stac_object } in { self .template } "
166161 )
167162
168163 # Allow dot-notation properties for arbitrary object values.
169164 props = template_var .split ("." )
170- prop_source : pystac .STACObject | dict [str , Any ] | None = None
171- error = pystac .TemplateError (
172- f"Cannot find property { template_var } on { stac_object } for template { self .template } "
165+ prop_source : STACObject | dict [str , Any ] | None = None
166+ error = TemplateError (
167+ f"Cannot find property { template_var } on { stac_object } for template "
168+ f"{ self .template } "
173169 )
174170
175171 try :
@@ -199,7 +195,7 @@ def _get_template_value(self, stac_object: STACObject, template_var: str) -> Any
199195 if not hasattr (v , prop ):
200196 raise error
201197 v = getattr (v , prop )
202- except pystac . TemplateError as e :
198+ except TemplateError as e :
203199 if template_var in self .defaults :
204200 return self .defaults [template_var ]
205201 raise e
@@ -222,7 +218,7 @@ def get_template_values(self, stac_object: STACObject) -> dict[str, Any]:
222218 stac object.
223219
224220 Raises:
225- pystac. TemplateError: If a value for a template variable cannot be
221+ TemplateError: If a value for a template variable cannot be
226222 derived from the stac object and there is no default,
227223 this error will be raised.
228224 """
@@ -268,14 +264,14 @@ def get_href(
268264 if is_file_path (parent_dir ):
269265 parent_dir = os .path .dirname (parent_dir )
270266
271- if isinstance (stac_object , pystac . Item ):
267+ if isinstance (stac_object , Item ):
272268 return self .get_item_href (stac_object , parent_dir )
273- elif isinstance (stac_object , pystac . Collection ):
269+ elif isinstance (stac_object , Collection ):
274270 return self .get_collection_href (stac_object , parent_dir , is_root )
275- elif isinstance (stac_object , pystac . Catalog ):
271+ elif isinstance (stac_object , Catalog ):
276272 return self .get_catalog_href (stac_object , parent_dir , is_root )
277273 else :
278- raise pystac . STACError (f"Unknown STAC object type { stac_object } " )
274+ raise STACError (f"Unknown STAC object type { stac_object } " )
279275
280276 @abstractmethod
281277 def get_catalog_href (self , cat : Catalog , parent_dir : str , is_root : bool ) -> str :
0 commit comments