Skip to content

Commit

Permalink
feat, wip: abfs support
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Aug 7, 2023
1 parent 7bed669 commit aa11815
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
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

0 comments on commit aa11815

Please sign in to comment.