Skip to content

Commit

Permalink
Fixed optional dependency on azure-storage-blob (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Augspurger authored Nov 4, 2022
1 parent 9a2a3f5 commit 7970d3b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.4.9

## Bug fixes

* Fixed `ImportError` when the optional dependency `azure-storage-blob` isn't installed.

# 0.4.8

## New Features
Expand Down
12 changes: 10 additions & 2 deletions planetary_computer/_adlfs.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import typing

import azure.storage.blob
from planetary_computer.sas import get_token

if typing.TYPE_CHECKING:
import adlfs
import azure.storage.blob


def get_container_client(
account_name: str, container_name: str
) -> azure.storage.blob.ContainerClient:
) -> "azure.storage.blob.ContainerClient":
"""
Get a :class:`azure.storage.blob.ContainerClient` with credentials.
Expand All @@ -20,6 +20,14 @@ def get_container_client(
The :class:`azure.storage.blob.ContainerClient` with the short-lived SAS token
set as the credential.
"""
try:
import azure.storage.blob
except ImportError as e:
raise ImportError(
"'planetary_computer.get_container_clinent' requires "
"the optional dependency 'azure-storage-blob'."
) from e

token = get_token(account_name, container_name).token
return azure.storage.blob.ContainerClient(
f"https://{account_name}.blob.core.windows.net",
Expand Down
2 changes: 1 addition & 1 deletion planetary_computer/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Library version"""

__version__ = "0.4.8"
__version__ = "0.4.9"
2 changes: 1 addition & 1 deletion scripts/cibuild
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
# Install/upgrade dependencies
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
pip install -e .[adlfs]
pip install -e .[adlfs,azure]

./scripts/test
fi
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = planetary-computer
version = 0.4.8
version = 0.4.9
license_file = LICENSE
author = microsoft
author_email = planetarycomputer@microsoft.com
Expand All @@ -21,6 +21,7 @@ install_requires =

[options.extras_require]
adlfs = adlfs
azure = azure-storage-blob

[options.entry_points]
console_scripts =
Expand Down
6 changes: 6 additions & 0 deletions tests/test_adlfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ def test_get_adlfs_filesystem_raises(monkeypatch: Any) -> None:
planetary_computer.get_adlfs_filesystem("nrel", "oedi")


def test_get_container_client_raises(monkeypatch: Any) -> None:
monkeypatch.setitem(sys.modules, "azure", None)
with pytest.raises(ImportError):
planetary_computer.get_container_client("nrel", "oedi")


def test_get_adlfs_filesystem() -> None:
fs = planetary_computer.get_adlfs_filesystem("nrel", "oedi")
assert fs.account_url == "https://nrel.blob.core.windows.net"
Expand Down

0 comments on commit 7970d3b

Please sign in to comment.