Skip to content

Commit e378487

Browse files
authored
Don't use deprecated methods from pystac (#455)
* fix: don't use deprecated methods * feat: error on pystac warnings
1 parent 51df4b0 commit e378487

File tree

11 files changed

+31
-39
lines changed

11 files changed

+31
-39
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
### Fixed
1515

1616
- `reproject_shape` without a precision ([#454](https://github.com/stac-utils/stactools/pull/454))
17+
- Don't use deprecated `Catalog.get_all_items` ([#455](https://github.com/stac-utils/stactools/pull/455))
1718

1819
## [0.5.0] - 2023-08-04
1920

pyproject.toml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,11 @@ description = "Command line tool and Python library for working with STAC"
44
readme = "README.md"
55
authors = [
66
{ name = "Rob Emanuele", email = "[email protected]" },
7-
{ name = "Pete Gadomski", email = "[email protected]" },
7+
{ name = "Pete Gadomski", email = "[email protected]" },
88
]
9-
maintainers = [{ name = "Pete Gadomski", email = "[email protected]" }]
9+
maintainers = [{ name = "Pete Gadomski", email = "[email protected]" }]
1010
license = { text = "Apache-2.0" }
11-
keywords = [
12-
"pystac",
13-
"imagery",
14-
"raster",
15-
"catalog",
16-
"STAC",
17-
]
11+
keywords = ["pystac", "imagery", "raster", "catalog", "STAC"]
1812
classifiers = [
1913
"Development Status :: 4 - Beta",
2014
"License :: OSI Approved :: Apache Software License",
@@ -100,11 +94,8 @@ strict = true
10094
warn_unused_ignores = true
10195

10296
[[tool.mypy.overrides]]
103-
module = [
104-
"fsspec",
105-
"osgeo",
106-
"rasterio",
107-
"s3fs",
108-
"shapely"
109-
]
97+
module = ["fsspec", "osgeo", "rasterio", "s3fs", "shapely"]
11098
ignore_missing_imports = true
99+
100+
[tool.pytest.ini_options]
101+
filterwarnings = ["error:::pystac[.*]"]

src/stactools/core/add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def add_item(
2222
move_assets (bool): If true, move the asset files alongside the target item.
2323
"""
2424

25-
target_item_ids = [item.id for item in target_catalog.get_all_items()]
25+
target_item_ids = [item.id for item in target_catalog.get_items(recursive=True)]
2626
if source_item.id in target_item_ids:
2727
raise ValueError(
2828
f"An item with ID {source_item.id} already exists in the target catalog"

src/stactools/core/copy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def move_all_assets(
259259
the catalog or collection.
260260
"""
261261

262-
for item in catalog.get_all_items():
262+
for item in catalog.get_items(recursive=True):
263263
move_assets(
264264
item, asset_subdirectory, make_hrefs_relative, copy, ignore_conflicts
265265
)

src/stactools/core/layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def layout_catalog(
4646
"""
4747

4848
if remove_existing_subcatalogs:
49-
items = catalog.get_all_items()
49+
items = catalog.get_items(recursive=True)
5050
for item in items:
5151
parent = item.get_parent()
5252
assert parent is not None

src/stactools/core/merge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def merge_all_items(
108108
Returns:
109109
pystac.Catalog or pystac.Collection: The ``target_catalog``
110110
"""
111-
source_items = source_catalog.get_all_items()
111+
source_items = source_catalog.get_items(recursive=True)
112112
ids_to_items = {item.id: item for item in source_items}
113113

114114
parent_dir = os.path.dirname(target_catalog.self_href)
@@ -128,7 +128,7 @@ def merge_all_items(
128128
source_catalog = new_source_catalog
129129
target_catalog.add_child(source_catalog, source_catalog.title)
130130
else:
131-
for item in target_catalog.get_all_items():
131+
for item in target_catalog.get_items(recursive=True):
132132
source_item = ids_to_items.get(item.id)
133133
if source_item is not None:
134134
merge_items(

tests/cli/commands/test_add.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ def item_path() -> str:
1818
def test_add_item(item_path: str, tmp_planet_disaster: pystac.Collection):
1919
collection = tmp_planet_disaster
2020
collection_path = collection.get_self_href()
21-
items = list(collection.get_all_items())
21+
items = list(collection.get_items(recursive=True))
2222
assert len(items) == 5
2323

2424
runner = CliRunner()
2525
result = runner.invoke(cli, ["add", item_path, collection_path])
2626
assert result.exit_code == 0
2727

2828
collection_after = pystac.read_file(collection_path)
29-
items = list(collection_after.get_all_items())
29+
items = list(collection_after.get_items(recursive=True))
3030
assert len(items) == 6
3131

3232

@@ -35,7 +35,7 @@ def test_add_item_to_specific_collection(
3535
):
3636
collection = tmp_planet_disaster
3737
collection_path = collection.get_self_href()
38-
items = list(collection.get_all_items())
38+
items = list(collection.get_items(recursive=True))
3939
assert len(items) == 5
4040
item_before = pystac.read_file(item_path)
4141

@@ -62,7 +62,7 @@ def test_add_item_to_missing_collection(
6262
):
6363
collection = tmp_planet_disaster
6464
collection_path = collection.get_self_href()
65-
items = list(collection.get_all_items())
65+
items = list(collection.get_items(recursive=True))
6666
assert len(items) == 5
6767

6868
runner = CliRunner()

tests/cli/commands/test_add_raster.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
def test_add_raster_to_items(tmp_planet_disaster: pystac.Collection):
1010
collection = tmp_planet_disaster
1111
collection_path = collection.get_self_href()
12-
items = list(collection.get_all_items())
12+
items = list(collection.get_items(recursive=True))
1313
item_path = pystac.utils.make_absolute_href(
1414
items[0].get_self_href(), collection_path
1515
)
@@ -19,7 +19,7 @@ def test_add_raster_to_items(tmp_planet_disaster: pystac.Collection):
1919
assert result.exit_code == 0
2020

2121
updated = pystac.read_file(collection_path)
22-
item = list(updated.get_all_items())[0]
22+
item = list(updated.get_items(recursive=True))[0]
2323
asset = item.get_assets().get("analytic")
2424
assert asset is not None
2525
expected = expected_json("rasterbands.json")

tests/cli/commands/test_copy.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
def test_copy(tmp_path: Path, planet_disaster: pystac.Collection) -> None:
1313
collection_path = planet_disaster.get_self_href()
14-
item_ids = set([i.id for i in planet_disaster.get_all_items()])
14+
item_ids = set([i.id for i in planet_disaster.get_items(recursive=True)])
1515

1616
runner = CliRunner()
1717
result = runner.invoke(cli, ["copy", collection_path, str(tmp_path)])
1818
assert result.exit_code == 0
1919

2020
copy_cat = pystac.read_file(tmp_path / "collection.json")
21-
copy_cat_ids = set([i.id for i in copy_cat.get_all_items()])
21+
copy_cat_ids = set([i.id for i in copy_cat.get_items(recursive=True)])
2222

2323
assert copy_cat_ids == item_ids
2424

@@ -34,7 +34,7 @@ def test_copy_to_relative(tmp_path: Path, planet_disaster: pystac.Collection) ->
3434
assert result.exit_code == 0
3535

3636
dst_cat = pystac.read_file(dst_dir / "collection.json")
37-
for item in dst_cat.get_all_items():
37+
for item in dst_cat.get_items(recursive=True):
3838
item_href = item.get_self_href()
3939
for asset in item.assets.values():
4040
href = asset.href
@@ -96,7 +96,7 @@ def test_move_assets(tmp_path: Path, planet_disaster: pystac.Collection) -> None
9696
assert result.exit_code == 0
9797

9898
cat2 = pystac.read_file(cat_href)
99-
for item in cat2.get_all_items():
99+
for item in cat2.get_items(recursive=True):
100100
item_href = item.get_self_href()
101101
for asset in item.assets.values():
102102
href = asset.href
@@ -121,7 +121,7 @@ def test_copy_assets(tmp_path: Path, planet_disaster: pystac.Collection) -> None
121121
assert result.exit_code == 0
122122

123123
cat2 = pystac.read_file(tmp_path / "collection.json")
124-
for item in cat2.get_all_items():
124+
for item in cat2.get_items(recursive=True):
125125
assert all(v.href.startswith("./") for v in item.assets.values())
126126

127127
assert (

tests/cli/commands/test_merge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def two_planet_disaster_subsets(tmp_path: Path):
2525
col = pystac.Collection.from_file(
2626
test_data.get_path("data-files/planet-disaster/collection.json")
2727
)
28-
for item in list(col.get_all_items()):
28+
for item in list(col.get_items(recursive=True)):
2929
if item.id != item_id:
3030
item.get_parent().remove_item(item.id)
3131
col.update_extent_from_items()
@@ -47,7 +47,7 @@ def test_merge_moves_assets(two_planet_disaster_subsets: List[str]):
4747

4848
target_col = pystac.read_file(col_paths[1])
4949

50-
items = list(target_col.get_all_items())
50+
items = list(target_col.get_items(recursive=True))
5151
assert len(items) == 2
5252

5353
for item in items:

0 commit comments

Comments
 (0)