Skip to content

Commit 6236686

Browse files
committed
Allow all from_file overrides to set a stac_io implementation
1 parent 3e21956 commit 6236686

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

pystac/catalog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,8 @@ def full_copy(
939939
return cast(Catalog, super().full_copy(root, parent))
940940

941941
@classmethod
942-
def from_file(cls, href: str) -> "Catalog":
943-
result = super().from_file(href)
942+
def from_file(cls, href: str, stac_io: Optional[pystac.StacIO] = None) -> "Catalog":
943+
result = super().from_file(href, stac_io)
944944
if not isinstance(result, Catalog):
945945
raise pystac.STACTypeError(f"{result} is not a {Catalog}.")
946946
return result

pystac/collection.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,10 @@ def full_copy(
749749
return cast(Collection, super().full_copy(root, parent))
750750

751751
@classmethod
752-
def from_file(cls, href: str) -> "Collection":
753-
result = super().from_file(href)
752+
def from_file(
753+
cls, href: str, stac_io: Optional[pystac.StacIO] = None
754+
) -> "Collection":
755+
result = super().from_file(href, stac_io)
754756
if not isinstance(result, Collection):
755757
raise pystac.STACTypeError(f"{result} is not a {Collection}.")
756758
return result

pystac/item.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,8 @@ def full_copy(
973973
return cast(Item, super().full_copy(root, parent))
974974

975975
@classmethod
976-
def from_file(cls, href: str) -> "Item":
977-
result = super().from_file(href)
976+
def from_file(cls, href: str, stac_io: Optional[pystac.StacIO] = None) -> "Item":
977+
result = super().from_file(href, stac_io)
978978
if not isinstance(result, Item):
979979
raise pystac.STACTypeError(f"{result} is not a {Item}.")
980980
return result

pystac/stac_object.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,8 @@ def from_file(
453453

454454
if not is_absolute_href(href):
455455
href = make_absolute_href(href)
456-
d = stac_io.read_json(href)
457456

458-
o = stac_io.stac_object_from_dict(d, href, None)
457+
o = stac_io.read_stac_object(href)
459458

460459
# Set the self HREF, if it's not already set to something else.
461460
if o.get_self_href() is None:

0 commit comments

Comments
 (0)