Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@

### Added

- "Public" `Catalog.stac_io` property to match "private" `Catalog._stac_io` attribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entry should be removed

([#590](https://github.com/stac-utils/pystac/pull/590))

### Removed

### Changed

- Enable [strict
mode](https://mypy.readthedocs.io/en/latest/command_line.html?highlight=strict%20mode#cmdoption-mypy-strict)
for `mypy` ([#591](https://github.com/stac-utils/pystac/pull/591))
- `Catalog.set_root` also sets `Catalog.stac_io` for the calling instance to be the same
as `root.stac_io`, if that value is not `None`
([#590](https://github.com/stac-utils/pystac/pull/590))

### Fixed

Expand Down
10 changes: 6 additions & 4 deletions pystac/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CatalogType(str, Enum):

See:
:stac-spec:`The best practices documentation on self-contained catalogs
<best-practices.md#self-contained-catalogs>`
<best-practices.md#self-contained-catalogs>`
"""

ABSOLUTE_PUBLISHED = "ABSOLUTE_PUBLISHED"
Expand All @@ -55,7 +55,7 @@ class CatalogType(str, Enum):

See:
:stac-spec:`The best practices documentation on published catalogs
<best-practices.md#published-catalogs>`
<best-practices.md#published-catalogs>`
"""

RELATIVE_PUBLISHED = "RELATIVE_PUBLISHED"
Expand All @@ -65,7 +65,7 @@ class CatalogType(str, Enum):

See:
:stac-spec:`The best practices documentation on published catalogs
<best-practices.md#published-catalogs>`
<best-practices.md#published-catalogs>`
"""

@classmethod
Expand Down Expand Up @@ -181,11 +181,13 @@ def __repr__(self) -> str:
return "<Catalog id={}>".format(self.id)

def set_root(self, root: Optional["Catalog"]) -> None:
STACObject.set_root(self, root)
super().set_root(root)
if root is not None:
root._resolved_objects = ResolvedObjectCache.merge(
root._resolved_objects, self._resolved_objects
)
if root._stac_io is not None:
self._stac_io = root._stac_io

def is_relative(self) -> bool:
return self.catalog_type in [
Expand Down
14 changes: 14 additions & 0 deletions tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
HIERARCHICAL_LINKS,
)
from pystac.extensions.label import LabelClasses, LabelExtension, LabelType
from pystac.stac_io import DefaultStacIO
from pystac.utils import is_absolute_href, join_path_or_url, JoinType
from tests.utils import (
TestCases,
Expand Down Expand Up @@ -107,6 +108,19 @@ def test_from_dict_set_root(self) -> None:
collection = Catalog.from_dict(cat_dict, root=root_cat)
self.assertIs(collection.get_root(), root_cat)

def test_from_dict_uses_root_stac_io(self) -> None:
class CustomStacIO(DefaultStacIO):
pass

path = TestCases.get_path("data-files/catalogs/test-case-1/catalog.json")
with open(path) as f:
cat_dict = json.load(f)
root_cat = pystac.Catalog(id="test", description="test desc")
root_cat._stac_io = CustomStacIO()

collection = Catalog.from_dict(cat_dict, root=root_cat)
self.assertIsInstance(collection._stac_io, CustomStacIO)

def test_read_remote(self) -> None:
# TODO: Move this URL to the main stac-spec repo once the example JSON is fixed.
catalog_url = (
Expand Down