Skip to content

Commit

Permalink
add support for non-async filesystems (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
ircwaves authored Jan 4, 2024
1 parent 54352d0 commit 033437e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- ([#72]) Given that `_get_file` is part of the `AsyncFileSystem` spec, this
adds the synchronous `get_file` as a way to retrieve files if `_get_file` is
not found.

## [v0.3.0] - 2023-12-20

### Changed
Expand Down
10 changes: 9 additions & 1 deletion stactask/asset_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@
async def download_file(fs: AbstractFileSystem, src: str, dest: str) -> None:
async with sem:
logger.debug(f"{src} start")
await fs._get_file(src, dest)
if hasattr(fs, "_get_file"):
await fs._get_file(src, dest)
elif hasattr(fs, "get_file"):
fs.get_file(src, dest)
else:
raise NotImplementedError(
"stactask only supports filesystems providing"
" `get_file` or `_get_file` interface"
)
logger.debug(f"{src} completed")


Expand Down
19 changes: 19 additions & 0 deletions tests/test_task_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@ def test_download_item_asset(tmp_path: Path, item_collection: Dict[str, Any]) ->
assert filename.is_file() is True


def test_download_item_asset_local(
tmp_path: Path, item_collection: Dict[str, Any]
) -> None:
t = NothingTask(item_collection, workdir=tmp_path / "test-task-download-item-asset")
item = t.download_item_assets(t.items[0], assets=["tileinfo_metadata"])
fname = item.assets["tileinfo_metadata"].href
filename = Path(fname)
assert filename.is_file() is True
# Downloaded to local, as in prev test.
# With the asset hrefs updated by the prev download, we "download" again to subdir
item = t.download_item_assets(
item, assets=["tileinfo_metadata"], path_template="again/${collection}/${id}"
)
href = item.assets["tileinfo_metadata"].href
assert "again" in href
filename = Path(href)
assert filename.is_file() is True


# @vcr.use_cassette(str(cassettepath / 'download_assets'))
def test_download_item_assets(tmp_path: Path, item_collection: Dict[str, Any]) -> None:
t = NothingTask(
Expand Down

0 comments on commit 033437e

Please sign in to comment.