Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ABFS support #49

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
13 changes: 7 additions & 6 deletions src/stac_asset/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,10 @@ async def download_item(

if config.file_name:
item_path = directory_as_path / config.file_name
item.set_self_href(str(item_path))
else:
self_href = item.get_self_href()
if self_href:
item_path = directory_as_path / os.path.basename(self_href)
else:
item_path = None
item.set_self_href(str(item_path))
item_path = None
item.set_self_href(None)

file_names: Set[str] = set()
assets: Dict[str, Tuple[Asset, Path]] = dict()
Expand Down Expand Up @@ -222,6 +219,10 @@ def guess_client_class(asset: Asset, config: Config) -> Type[Client]:
"invalid alternate asset definition (missing href): "
f"{alternate}"
)
if asset.href.startswith("abfs://") and asset.media_type == "application/x-parquet":
storage_account = asset.extra_fields["table:storage_options"]["account_name"]
asset.href = f"https://{storage_account}.blob.core.windows.net/{asset.href[7:]}"
asset.media_type = None
return guess_client_class_from_href(asset.href)


Expand Down
11 changes: 11 additions & 0 deletions tests/test_planetary_computer_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from pathlib import Path

import pytest
import stac_asset
from pystac import Item
from stac_asset import Config, PlanetaryComputerClient

pytestmark = [
Expand All @@ -20,3 +22,12 @@ async def test_download(tmp_path: Path, asset_href: str) -> None:
await client.download_href(asset_href, tmp_path / "out.tif")

assert os.path.getsize(tmp_path / "out.tif") == 4096


async def test_abfs(tmp_path: Path) -> None:
href = (
"https://planetarycomputer.microsoft.com/api/stac/v1/"
"collections/ms-buildings/items/Vatican%20City_2022-07-06"
)
await stac_asset.download_item(Item.from_file(href), tmp_path)
assert os.path.getsize(tmp_path / "Vatican%20City_2022-07-06") == 2260