Skip to content

Commit aa1cdf8

Browse files
committed
Issue deprecation warnings for STAC_IO
1 parent c53428b commit aa1cdf8

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

pystac/stac_io.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Type,
1313
Union,
1414
)
15+
import warnings
1516

1617
from urllib.parse import urlparse
1718
from urllib.request import urlopen
@@ -256,11 +257,21 @@ class STAC_IO:
256257

257258
@staticmethod
258259
def read_text_method(uri: str) -> str:
260+
warnings.warn(
261+
"STAC_IO is deprecated. "
262+
"Please use instances of StacIO (e.g. StacIO.default()).",
263+
DeprecationWarning,
264+
)
259265
return StacIO.default().read_text(uri)
260266

261267
@staticmethod
262268
def write_text_method(uri: str, txt: str) -> None:
263269
"""Default method for writing text."""
270+
warnings.warn(
271+
"STAC_IO is deprecated. "
272+
"Please use instances of StacIO (e.g. StacIO.default()).",
273+
DeprecationWarning,
274+
)
264275
return StacIO.default().write_text(uri, txt)
265276

266277
@staticmethod
@@ -269,6 +280,11 @@ def stac_object_from_dict(
269280
href: Optional[str] = None,
270281
root: Optional["Catalog_Type"] = None,
271282
) -> "STACObject_Type":
283+
warnings.warn(
284+
"STAC_IO is deprecated. "
285+
"Please use instances of StacIO (e.g. StacIO.default()).",
286+
DeprecationWarning,
287+
)
272288
return pystac.serialization.stac_object_from_dict(d, href, root)
273289

274290
# This is set in __init__.py

tests/test_stac_io.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import unittest
2+
import warnings
3+
4+
from pystac.stac_io import STAC_IO
5+
from tests.utils import TestCases
6+
7+
8+
class StacIOTest(unittest.TestCase):
9+
def test_stac_io_issues_warnings(self):
10+
with warnings.catch_warnings(record=True) as w:
11+
# Cause all warnings to always be triggered.
12+
warnings.simplefilter("always")
13+
# Trigger a warning.
14+
STAC_IO.read_text(
15+
TestCases.get_path("data-files/collections/multi-extent.json")
16+
)
17+
18+
# Verify some things
19+
self.assertEqual(len(w), 1)
20+
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))

0 commit comments

Comments
 (0)