Skip to content

Commit aa11815

Browse files
committed
feat, wip: abfs support
1 parent 7bed669 commit aa11815

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/stac_asset/functions.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,10 @@ async def download_item(
6262

6363
if config.file_name:
6464
item_path = directory_as_path / config.file_name
65+
item.set_self_href(str(item_path))
6566
else:
66-
self_href = item.get_self_href()
67-
if self_href:
68-
item_path = directory_as_path / os.path.basename(self_href)
69-
else:
70-
item_path = None
71-
item.set_self_href(str(item_path))
67+
item_path = None
68+
item.set_self_href(None)
7269

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

227228

tests/test_planetary_computer_client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from pathlib import Path
33

44
import pytest
5+
import stac_asset
6+
from pystac import Item
57
from stac_asset import Config, PlanetaryComputerClient
68

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

2224
assert os.path.getsize(tmp_path / "out.tif") == 4096
25+
26+
27+
async def test_abfs(tmp_path: Path) -> None:
28+
href = (
29+
"https://planetarycomputer.microsoft.com/api/stac/v1/"
30+
"collections/ms-buildings/items/Vatican%20City_2022-07-06"
31+
)
32+
await stac_asset.download_item(Item.from_file(href), tmp_path)
33+
assert os.path.getsize(tmp_path / "Vatican%20City_2022-07-06") == 2260

0 commit comments

Comments
 (0)