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

Support versions of GCS without transfer_manager #410

Merged
merged 6 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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: 11 additions & 2 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
# cloudpathlib Changelog

## 0.18.0 (2024-02-25)
## v0.18.1 (2024-02-26)

- Fixed import error due to incompatible `google-cloud-storage` by not using `transfer_manager` if it is not available. ([Issue #408](https://github.com/drivendataorg/cloudpathlib/issues/408), (PR #410)[https://github.com/drivendataorg/cloudpathlib/pull/410])

Includes all changes from v0.18.0.

**Note: This is the last planned Python 3.7 compatible release version.**

## 0.18.0 (2024-02-25) (Yanked)

- Implement sliced downloads in GSClient. (Issue [#387](https://github.com/drivendataorg/cloudpathlib/issues/387), PR [#389](https://github.com/drivendataorg/cloudpathlib/pull/389))
- Implement `as_url` with presigned parameter for all backends. (Issue [#235](https://github.com/drivendataorg/cloudpathlib/issues/235), PR [#236](https://github.com/drivendataorg/cloudpathlib/pull/236))
- Stream to and from Azure Blob Storage. (PR [#403](https://github.com/drivendataorg/cloudpathlib/pull/403))
- Implement `file:` URI scheme support for `AnyPath`. (Issue [#401](https://github.com/drivendataorg/cloudpathlib/issues/401), PR [#404](https://github.com/drivendataorg/cloudpathlib/pull/404))

**Note: This is the last planned Python 3.7 compatible release version.**
**Note: This version was [yanked](https://pypi.org/help/#yanked) due to a missing version floor on the google-cloud-storage dependency that can cause an import error.**
pjbull marked this conversation as resolved.
Show resolved Hide resolved

## 0.17.0 (2023-12-21)

Expand Down
18 changes: 14 additions & 4 deletions cloudpathlib/gs/gsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
from pathlib import Path, PurePosixPath
from typing import Any, Callable, Dict, Iterable, Optional, TYPE_CHECKING, Tuple, Union
import warnings

from ..client import Client, register_client_class
from ..cloudpath import implementation_registry
Expand All @@ -16,13 +17,17 @@
from google.api_core.exceptions import NotFound
from google.auth.exceptions import DefaultCredentialsError
from google.cloud.storage import Client as StorageClient
from google.cloud.storage import transfer_manager


except ModuleNotFoundError:
implementation_registry["gs"].dependencies_loaded = False


try:
from google.cloud.storage import transfer_manager
except ImportError:
transfer_manager = None

Check warning on line 28 in cloudpathlib/gs/gsclient.py

View check run for this annotation

Codecov / codecov/patch

cloudpathlib/gs/gsclient.py#L27-L28

Added lines #L27 - L28 were not covered by tests


@register_client_class("gs")
class GSClient(Client):
"""Client class for Google Cloud Storage which handles authentication with GCP for
Expand Down Expand Up @@ -80,7 +85,7 @@
writing a file to the cloud. Defaults to `mimetypes.guess_type`. Must return a tuple (content type, content encoding).
download_chunks_concurrently_kwargs (Optional[Dict[str, Any]]): Keyword arguments to pass to
[`download_chunks_concurrently`](https://cloud.google.com/python/docs/reference/storage/latest/google.cloud.storage.transfer_manager#google_cloud_storage_transfer_manager_download_chunks_concurrently)
for sliced parallel downloads.
for sliced parallel downloads; Only available in `google-cloud-storage` version 2.7.0 or later, otherwise ignored and a warning is emitted.
"""
if application_credentials is None:
application_credentials = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
Expand Down Expand Up @@ -125,11 +130,16 @@

local_path = Path(local_path)

if self.download_chunks_concurrently_kwargs is not None:
if transfer_manager is not None and self.download_chunks_concurrently_kwargs is not None:
transfer_manager.download_chunks_concurrently(
blob, local_path, **self.download_chunks_concurrently_kwargs
)
else:
if transfer_manager is None and self.download_chunks_concurrently_kwargs is not None:
warnings.warn(

Check warning on line 139 in cloudpathlib/gs/gsclient.py

View check run for this annotation

Codecov / codecov/patch

cloudpathlib/gs/gsclient.py#L139

Added line #L139 was not covered by tests
"Ignoring `download_chunks_concurrently_kwargs` for version of google-cloud-storage that does not support them (<2.7.0)."
)

blob.download_to_filename(local_path)

return local_path
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"

[project]
name = "cloudpathlib"
version = "0.18.0"
version = "0.18.1"
description = "pathlib-style classes for cloud storage services."
readme = "README.md"
authors = [{ name = "DrivenData", email = "info@drivendata.org" }]
Expand Down
Loading