Skip to content

Commit cb1ed9b

Browse files
committed
Merge branch 'main' into clone-items
2 parents be6923e + 1c49441 commit cb1ed9b

File tree

8 files changed

+40
-14
lines changed

8 files changed

+40
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
- Use `TypeVar` for alternate constructors ([#983](https://github.com/stac-utils/pystac/pull/983))
3434
- Behavior when required fields are missing in `Item.from_dict` ([#994](https://github.com/stac-utils/pystac/pull/994))
3535
- By default, `ItemCollection` now clones items in iterator (`clone_items=True`) ([#1016](https://github.com/stac-utils/pystac/pull/1016))
36+
- `TemplateError` in `layout.py` deprecated in favor of duplicate in `errors.py` ([#1018](https://github.com/stac-utils/pystac/pull/1018))
3637

3738
### Fixed
3839

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ help:
1212
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
1313

1414
livehtml:
15-
sphinx-autobuild -z ../pystac --host 0.0.0.0 ${SOURCEDIR} $(BUILDDIR)/html -d _build/doctrees
15+
sphinx-autobuild --watch ../pystac --host 0.0.0.0 ${SOURCEDIR} $(BUILDDIR)/html -d _build/doctrees
1616

1717
.PHONY: help Makefile
1818

docs/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ The following exceptions may be raised internally by the library.
166166
be present but is missing or ``None``.
167167
* :class:`pystac.STACValidationError`: Raised by validation calls if the STAC JSON is
168168
invalid.
169-
* :class:`pystac.layout.TemplateError`: Raised when an error occurs while converting a
169+
* :class:`pystac.TemplateError`: Raised when an error occurs while converting a
170170
template string into data for :class:`~pystac.layout.LayoutTemplate`.
171171

172172
Serialization

pystac/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
__all__ = [
66
"__version__",
7+
"TemplateError",
78
"STACError",
89
"STACTypeError",
910
"DuplicateObjectKeyError",
@@ -44,6 +45,7 @@
4445
from typing import Any, Dict, Optional
4546

4647
from pystac.errors import (
48+
TemplateError,
4749
STACError,
4850
STACTypeError,
4951
DuplicateObjectKeyError,

pystac/errors.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
from typing import Any, Optional, Union
22

33

4+
class TemplateError(Exception):
5+
"""Exception thrown when an error occurs during converting a template
6+
string into data for :class:`~pystac.layout.LayoutTemplate`
7+
"""
8+
9+
pass
10+
11+
412
class STACError(Exception):
513
"""A STACError is raised for errors relating to STAC, e.g. for
614
invalid formats or trying to operate on a STAC that does not have

pystac/layout.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import warnings
34
from abc import ABC, abstractmethod
45
from collections import OrderedDict
56
from string import Formatter
@@ -16,11 +17,25 @@
1617

1718

1819
class TemplateError(Exception):
19-
"""Exception thrown when an error occurs during converting a template
20+
"""DEPRECATED.
21+
22+
.. deprecated:: 1.7.0
23+
Use :class:`pystac.errors.TemplateError` instead.
24+
25+
Exception thrown when an error occurs during converting a template
2026
string into data for :class:`~pystac.layout.LayoutTemplate`
2127
"""
2228

23-
pass
29+
def __init__(self, *args, **kwargs) -> None: # type: ignore
30+
warnings.warn(
31+
message=(
32+
"TemplateError in pystac.layout is deprecated and will be "
33+
"removed in pystac version 2.0.0. Use TemplateError in "
34+
"pystac.errors instead."
35+
),
36+
category=DeprecationWarning,
37+
)
38+
super().__init__(*args, **kwargs)
2439

2540

2641
class LayoutTemplate:
@@ -114,7 +129,7 @@ def _get_template_value(self, stac_object: STACObject, template_var: str) -> Any
114129
if dt is None:
115130
dt = stac_object.common_metadata.start_datetime
116131
if dt is None:
117-
raise TemplateError(
132+
raise pystac.TemplateError(
118133
"Item {} does not have a datetime or "
119134
"datetime range set; cannot template {} in {}".format(
120135
stac_object, template_var, self.template
@@ -134,12 +149,12 @@ def _get_template_value(self, stac_object: STACObject, template_var: str) -> Any
134149
if template_var == "collection":
135150
if stac_object.collection_id is not None:
136151
return stac_object.collection_id
137-
raise TemplateError(
152+
raise pystac.TemplateError(
138153
f"Item {stac_object} does not have a collection ID set; "
139154
f"cannot template {template_var} in {self.template}"
140155
)
141156
else:
142-
raise TemplateError(
157+
raise pystac.TemplateError(
143158
'"{}" cannot be used to template non-Item {} in {}'.format(
144159
template_var, stac_object, self.template
145160
)
@@ -148,7 +163,7 @@ def _get_template_value(self, stac_object: STACObject, template_var: str) -> Any
148163
# Allow dot-notation properties for arbitrary object values.
149164
props = template_var.split(".")
150165
prop_source: Optional[Union[pystac.STACObject, Dict[str, Any]]] = None
151-
error = TemplateError(
166+
error = pystac.TemplateError(
152167
"Cannot find property {} on {} for template {}".format(
153168
template_var, stac_object, self.template
154169
)
@@ -181,7 +196,7 @@ def _get_template_value(self, stac_object: STACObject, template_var: str) -> Any
181196
if not hasattr(v, prop):
182197
raise error
183198
v = getattr(v, prop)
184-
except TemplateError as e:
199+
except pystac.TemplateError as e:
185200
if template_var in self.defaults:
186201
return self.defaults[template_var]
187202
raise e
@@ -204,7 +219,7 @@ def get_template_values(self, stac_object: STACObject) -> Dict[str, Any]:
204219
stac object.
205220
206221
Raises:
207-
TemplateError: If a value for a template variable cannot be
222+
pystac.TemplateError: If a value for a template variable cannot be
208223
derived from the stac object and there is no default,
209224
this error will be raised.
210225
"""
@@ -227,7 +242,7 @@ def substitute(self, stac_object: STACObject) -> str:
227242
from this stac object.
228243
229244
Raises:
230-
TemplateError: If a value for a template variable cannot be
245+
pystac.TemplateError: If a value for a template variable cannot be
231246
derived from the stac object and there is no default,
232247
this error will be raised.
233248
"""

requirements-docs.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Sphinx==5.0.1
2-
ipython==8.10.0
2+
ipython==8.11.0
33
jinja2<4.0
44
nbsphinx==0.8.12
55
pydata-sphinx-theme==0.9.0
6+
sphinx-autobuild==2021.3.14
67
sphinx-design==0.3.0
78
sphinxcontrib-fulltoc==1.2.0

tests/test_layout.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
BestPracticesLayoutStrategy,
1010
CustomLayoutStrategy,
1111
LayoutTemplate,
12-
TemplateError,
1312
TemplateLayoutStrategy,
1413
)
1514
from pystac.utils import JoinType, join_path_or_url
@@ -103,7 +102,7 @@ def test_throws_for_no_collection(self) -> None:
103102
item.set_collection(None)
104103
assert item.collection_id is None
105104

106-
with self.assertRaises(TemplateError):
105+
with self.assertRaises(pystac.TemplateError):
107106
template.get_template_values(item)
108107

109108
def test_nested_properties(self) -> None:

0 commit comments

Comments
 (0)