Skip to content

Commit 96a0298

Browse files
authored
Configure the filename for saving the item (#129)
* Configure the filename for saving the item
1 parent 7ee8533 commit 96a0298

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

CHANGELOG.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,25 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Added
11+
12+
- download_item_assets and download_items_assets methods now accept a parameter `file_name` for configuring the filename to save the STAC Item as. If unset, it defaults to `item.json` and if set to `None` the filename is inferred from the ID.
13+
814
## [0.5.0] - 2024-05-08
915

10-
## Deprecated
16+
### Deprecated
1117

1218
- Support for Python 3.8 has been removed.
1319
- CLI flags `--skip-upload` and `--skip-validation` deprecated in favor of `--upload/--no-upload` and `--validate/no-validate`
1420
- Task constructor arguments `skip_upload` and `skip_validation` deprecated in favor of `upload` and `validate`
1521

16-
## Fixed
22+
### Fixed
1723

1824
- Several CLI arguments were missing `help` descriptions
1925

20-
## Changed
26+
### Changed
2127

2228
- Replaced the use of fsspec with stac-asset for downloading Item Assets
2329
- `--local` flag no longer turns off validation
@@ -30,7 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3036
- Collection assignment now assigns the first matching collection expression, rather
3137
than the last.
3238

33-
## Added
39+
### Added
3440

3541
- Property `collection_mapping` to `Task` class to retrieve the collection mappings
3642
from upload_options

stactask/asset_io.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ async def download_item_assets(
2121
path_template: str = "${collection}/${id}",
2222
config: Optional[DownloadConfig] = None,
2323
keep_non_downloaded: bool = True,
24+
file_name: Optional[str] = "item.json",
2425
) -> Item:
2526
return await stac_asset.download_item(
2627
item=item.clone(),
2728
directory=LayoutTemplate(path_template).substitute(item),
28-
file_name="item.json",
29+
file_name=file_name,
2930
config=config,
3031
keep_non_downloaded=keep_non_downloaded,
3132
)
@@ -36,6 +37,7 @@ async def download_items_assets(
3637
path_template: str = "${collection}/${id}",
3738
config: Optional[DownloadConfig] = None,
3839
keep_non_downloaded: bool = True,
40+
file_name: Optional[str] = "item.json",
3941
) -> list[Item]:
4042
return await asyncio.gather(
4143
*[
@@ -45,6 +47,7 @@ async def download_items_assets(
4547
path_template=path_template,
4648
config=config,
4749
keep_non_downloaded=keep_non_downloaded,
50+
file_name=file_name,
4851
)
4952
)
5053
for item in items

stactask/task.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def download_item_assets(
243243
path_template: str = "${collection}/${id}",
244244
config: Optional[DownloadConfig] = None,
245245
keep_non_downloaded: bool = True,
246+
file_name: Optional[str] = "item.json",
246247
) -> Item:
247248
"""Download provided asset keys for the given item. Assets are
248249
saved in workdir in a directory (as specified by path_template), and
@@ -256,13 +257,15 @@ def download_item_assets(
256257
where to store downloaded files.
257258
keep_original_filenames (Optional[bool]): Controls whether original
258259
file names should be used, or asset key + extension.
260+
file_name (Optional[str]): The name of the item file to save.
259261
"""
260262
return asyncio.get_event_loop().run_until_complete(
261263
download_item_assets(
262264
item,
263265
path_template=str(self._workdir / path_template),
264266
config=config,
265267
keep_non_downloaded=keep_non_downloaded,
268+
file_name=file_name,
266269
)
267270
)
268271

@@ -272,6 +275,7 @@ def download_items_assets(
272275
path_template: str = "${collection}/${id}",
273276
config: Optional[DownloadConfig] = None,
274277
keep_non_downloaded: bool = True,
278+
file_name: Optional[str] = "item.json",
275279
) -> list[Item]:
276280
"""Download provided asset keys for the given items. Assets are
277281
saved in workdir in a directory (as specified by path_template), and
@@ -286,6 +290,7 @@ def download_items_assets(
286290
where to store downloaded files.
287291
keep_original_filenames (Optional[bool]): Controls whether original
288292
file names should be used, or asset key + extension.
293+
file_name (Optional[str]): The name of the item file to save.
289294
"""
290295
return list(
291296
asyncio.get_event_loop().run_until_complete(
@@ -294,6 +299,7 @@ def download_items_assets(
294299
path_template=str(self._workdir / path_template),
295300
config=config,
296301
keep_non_downloaded=keep_non_downloaded,
302+
file_name=file_name,
297303
)
298304
)
299305
)

0 commit comments

Comments
 (0)