Skip to content

Commit 06f269d

Browse files
committed
Remove deprecated STAC_IO class
1 parent f9573f8 commit 06f269d

File tree

4 files changed

+3
-227
lines changed

4 files changed

+3
-227
lines changed

docs/api.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,6 @@ DuplicateKeyReportingMixin
185185
:members:
186186
:show-inheritance:
187187

188-
STAC_IO
189-
~~~~~~~
190-
191-
.. deprecated:: 1.0.0-beta.1
192-
Use :class:`pystac.StacIO` instead. This class will be removed in v1.0.0.
193-
194-
.. autoclass:: pystac.stac_io.STAC_IO
195-
:members:
196-
:undoc-members:
197-
198188
Layout
199189
------
200190

pystac/stac_io.py

Lines changed: 0 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
Type,
1212
Union,
1313
)
14-
import warnings
1514

1615
from urllib.request import urlopen
1716
from urllib.error import HTTPError
@@ -388,169 +387,3 @@ def _report_duplicate_object_names(
388387
else:
389388
result[key] = value
390389
return result
391-
392-
393-
class STAC_IO:
394-
"""DEPRECATED: Methods used to read and save STAC json.
395-
Allows users of the library to set their own methods
396-
(e.g. for reading and writing from cloud storage)
397-
398-
Note: The static methods of this class are deprecated. Move to using
399-
instance methods of a specific instance of StacIO.
400-
"""
401-
402-
@staticmethod
403-
def issue_deprecation_warning() -> None:
404-
warnings.warn(
405-
"STAC_IO is deprecated and will be removed in v1.0.0. "
406-
"Please use instances of StacIO (e.g. StacIO.default()) instead.",
407-
DeprecationWarning,
408-
)
409-
410-
def __init__(self) -> None:
411-
STAC_IO.issue_deprecation_warning()
412-
413-
def __init_subclass__(cls) -> None:
414-
STAC_IO.issue_deprecation_warning()
415-
416-
@staticmethod
417-
def read_text_method(uri: str) -> str:
418-
STAC_IO.issue_deprecation_warning()
419-
return StacIO.default().read_text(uri)
420-
421-
@staticmethod
422-
def write_text_method(uri: str, txt: str) -> None:
423-
"""Default method for writing text."""
424-
STAC_IO.issue_deprecation_warning()
425-
return StacIO.default().write_text(uri, txt)
426-
427-
@staticmethod
428-
def stac_object_from_dict(
429-
d: Dict[str, Any],
430-
href: Optional[str] = None,
431-
root: Optional["Catalog_Type"] = None,
432-
) -> "STACObject_Type":
433-
STAC_IO.issue_deprecation_warning()
434-
if identify_stac_object_type(d) == pystac.STACObjectType.ITEM:
435-
collection_cache = None
436-
if root is not None:
437-
collection_cache = root._resolved_objects.as_collection_cache()
438-
439-
# Merge common properties in case this is an older STAC object.
440-
merge_common_properties(
441-
d, json_href=href, collection_cache=collection_cache
442-
)
443-
444-
info = identify_stac_object(d)
445-
446-
d = migrate_to_latest(d, info)
447-
448-
if info.object_type == pystac.STACObjectType.CATALOG:
449-
return pystac.Catalog.from_dict(d, href=href, root=root, migrate=False)
450-
451-
if info.object_type == pystac.STACObjectType.COLLECTION:
452-
return pystac.Collection.from_dict(d, href=href, root=root, migrate=False)
453-
454-
if info.object_type == pystac.STACObjectType.ITEM:
455-
return pystac.Item.from_dict(d, href=href, root=root, migrate=False)
456-
457-
raise ValueError(f"Unknown STAC object type {info.object_type}")
458-
459-
# This is set in __init__.py
460-
_STAC_OBJECT_CLASSES = None
461-
462-
@classmethod
463-
def read_text(cls, uri: str) -> str:
464-
"""Read text from the given URI.
465-
466-
Args:
467-
uri : The URI from which to read text.
468-
469-
Returns:
470-
str: The text contained in the file at the location specified by the uri.
471-
472-
Note:
473-
This method uses the :func:`STAC_IO.read_text_method
474-
<STAC_IO.read_text_method>`. If you want to modify the behavior of
475-
STAC_IO in order to enable additional URI types, replace that member
476-
with your own implementation.
477-
"""
478-
return cls.read_text_method(uri)
479-
480-
@classmethod
481-
def write_text(cls, uri: str, txt: str) -> None:
482-
"""Write the given text to a file at the given URI.
483-
484-
Args:
485-
uri : The URI of the file to write the text to.
486-
txt : The text to write.
487-
488-
Note:
489-
This method uses the :func:`STAC_IO.write_text_method
490-
<STAC_IO.write_text_method>`. If you want to modify the behavior of
491-
STAC_IO in order to enable additional URI types, replace that member
492-
with your own implementation.
493-
"""
494-
cls.write_text_method(uri, txt)
495-
496-
@classmethod
497-
def read_json(cls, uri: str) -> Dict[str, Any]:
498-
"""Read a dict from the given URI.
499-
500-
Args:
501-
uri : The URI from which to read.
502-
503-
Returns:
504-
dict: A dict representation of the JSON contained in the file at the
505-
given uri.
506-
507-
Note:
508-
This method uses the :func:`STAC_IO.read_text_method
509-
<STAC_IO.read_text_method>`. If you want to modify the behavior of
510-
STAC_IO in order to enable additional URI types, replace that member
511-
with your own implementation.
512-
"""
513-
STAC_IO.issue_deprecation_warning()
514-
result: Dict[str, Any] = json.loads(STAC_IO.read_text(uri))
515-
return result
516-
517-
@classmethod
518-
def read_stac_object(
519-
cls, uri: str, root: Optional["Catalog_Type"] = None
520-
) -> "STACObject_Type":
521-
"""Read a STACObject from a JSON file at the given URI.
522-
523-
Args:
524-
uri : The URI from which to read.
525-
root : Optional root of the catalog for this object.
526-
If provided, the root's resolved object cache can be used to search for
527-
previously resolved instances of the STAC object.
528-
529-
Returns:
530-
STACObject: The deserialized STACObject from the serialized JSON
531-
contained in the file at the given uri.
532-
533-
Note:
534-
This method uses the :func:`STAC_IO.read_text_method
535-
<STAC_IO.read_text_method>`. If you want to modify the behavior of
536-
STAC_IO in order to enable additional URI types, replace that member
537-
with your own implementation.
538-
"""
539-
d = cls.read_json(uri)
540-
return cls.stac_object_from_dict(d, uri, root)
541-
542-
@classmethod
543-
def save_json(cls, uri: str, json_dict: Dict[str, Any]) -> None:
544-
"""Write a dict to the given URI as JSON.
545-
546-
Args:
547-
uri : The URI of the file to write the text to.
548-
json_dict : The JSON dict to write.
549-
550-
Note:
551-
This method uses the :func:`STAC_IO.write_text_method
552-
<STAC_IO.write_text_method>`. If you want to modify the behavior of
553-
STAC_IO in order to enable additional URI types, replace that member
554-
with your own implementation.
555-
"""
556-
STAC_IO.write_text(uri, json.dumps(json_dict, indent=4))

tests/test_stac_io.py

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,16 @@
11
import os
22
import unittest
3-
import warnings
43
import tempfile
54

65
import pystac
7-
from pystac.stac_io import STAC_IO, StacIO, DefaultStacIO, DuplicateKeyReportingMixin
6+
from pystac.stac_io import StacIO, DefaultStacIO, DuplicateKeyReportingMixin
87
from tests.utils import TestCases
98

109

1110
class StacIOTest(unittest.TestCase):
1211
def setUp(self) -> None:
1312
self.stac_io = StacIO.default()
1413

15-
def test_stac_io_issues_warnings(self) -> None:
16-
with warnings.catch_warnings(record=True) as w:
17-
# Cause all warnings to always be triggered.
18-
warnings.simplefilter("always")
19-
# Trigger a warning.
20-
STAC_IO.read_text(
21-
TestCases.get_path("data-files/collections/multi-extent.json")
22-
)
23-
24-
# Verify some things
25-
self.assertEqual(len(w), 1)
26-
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
27-
28-
with warnings.catch_warnings(record=True) as w:
29-
# Cause all warnings to always be triggered.
30-
warnings.simplefilter("always")
31-
# Trigger instantiation warning.
32-
_ = STAC_IO()
33-
34-
self.assertEqual(len(w), 1)
35-
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
36-
37-
with warnings.catch_warnings(record=True) as w:
38-
# Cause all warnings to always be triggered.
39-
warnings.simplefilter("always")
40-
41-
class CustomSTAC_IO(STAC_IO):
42-
pass
43-
44-
self.assertEqual(len(w), 1)
45-
self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
46-
47-
with warnings.catch_warnings(record=True) as w:
48-
# Cause all warnings to always be triggered.
49-
warnings.simplefilter("always")
50-
51-
d = STAC_IO.read_json(
52-
TestCases.get_path("data-files/item/sample-item.json")
53-
)
54-
_ = STAC_IO.stac_object_from_dict(d)
55-
56-
self.assertEqual(len(w), 3)
57-
self.assertTrue(
58-
all(issubclass(wrn.category, DeprecationWarning) for wrn in w)
59-
)
60-
6114
def test_read_write_collection(self) -> None:
6215
collection = pystac.read_file(
6316
TestCases.get_path("data-files/collections/multi-extent.json")

tests/utils/stac_io_mock.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66

77
class MockStacIO(pystac.StacIO):
8-
"""Creates a mock that records STAC_IO calls for testing and allows
9-
clients to replace STAC_IO functionality, all within a context scope.
8+
"""Creates a mock that records StacIO calls for testing and allows
9+
clients to replace StacIO functionality, all within a context scope.
1010
"""
1111

1212
def __init__(self) -> None:

0 commit comments

Comments
 (0)