Skip to content

Commit 29a147a

Browse files
pjbulljayqi
andauthored
Support versions of GCS without transfer_manager (#410)
* Fix 408 * Version and changelog * add warning * update history PR * Tweak description of change * Update HISTORY.md Co-authored-by: Jay Qi <[email protected]> --------- Co-authored-by: Jay Qi <[email protected]>
1 parent 6d13512 commit 29a147a

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

HISTORY.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
# cloudpathlib Changelog
22

3-
## 0.18.0 (2024-02-25)
3+
## v0.18.1 (2024-02-26)
4+
5+
- 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])
6+
7+
Includes all changes from v0.18.0.
8+
9+
**Note: This is the last planned Python 3.7 compatible release version.**
10+
11+
## 0.18.0 (2024-02-25) (Yanked)
12+
413
- Implement sliced downloads in GSClient. (Issue [#387](https://github.com/drivendataorg/cloudpathlib/issues/387), PR [#389](https://github.com/drivendataorg/cloudpathlib/pull/389))
514
- 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))
615
- Stream to and from Azure Blob Storage. (PR [#403](https://github.com/drivendataorg/cloudpathlib/pull/403))
716
- 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))
817

9-
**Note: This is the last planned Python 3.7 compatible release version.**
18+
**Note: This version was [yanked](https://pypi.org/help/#yanked) due to incompatibility with google-cloud-storage <2.7.0 that causes an import error.**
1019

1120
## 0.17.0 (2023-12-21)
1221

cloudpathlib/gs/gsclient.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
from pathlib import Path, PurePosixPath
55
from typing import Any, Callable, Dict, Iterable, Optional, TYPE_CHECKING, Tuple, Union
6+
import warnings
67

78
from ..client import Client, register_client_class
89
from ..cloudpath import implementation_registry
@@ -16,13 +17,17 @@
1617
from google.api_core.exceptions import NotFound
1718
from google.auth.exceptions import DefaultCredentialsError
1819
from google.cloud.storage import Client as StorageClient
19-
from google.cloud.storage import transfer_manager
20-
2120

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

2524

25+
try:
26+
from google.cloud.storage import transfer_manager
27+
except ImportError:
28+
transfer_manager = None
29+
30+
2631
@register_client_class("gs")
2732
class GSClient(Client):
2833
"""Client class for Google Cloud Storage which handles authentication with GCP for
@@ -80,7 +85,7 @@ def __init__(
8085
writing a file to the cloud. Defaults to `mimetypes.guess_type`. Must return a tuple (content type, content encoding).
8186
download_chunks_concurrently_kwargs (Optional[Dict[str, Any]]): Keyword arguments to pass to
8287
[`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)
83-
for sliced parallel downloads.
88+
for sliced parallel downloads; Only available in `google-cloud-storage` version 2.7.0 or later, otherwise ignored and a warning is emitted.
8489
"""
8590
if application_credentials is None:
8691
application_credentials = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
@@ -125,11 +130,16 @@ def _download_file(self, cloud_path: GSPath, local_path: Union[str, os.PathLike]
125130

126131
local_path = Path(local_path)
127132

128-
if self.download_chunks_concurrently_kwargs is not None:
133+
if transfer_manager is not None and self.download_chunks_concurrently_kwargs is not None:
129134
transfer_manager.download_chunks_concurrently(
130135
blob, local_path, **self.download_chunks_concurrently_kwargs
131136
)
132137
else:
138+
if transfer_manager is None and self.download_chunks_concurrently_kwargs is not None:
139+
warnings.warn(
140+
"Ignoring `download_chunks_concurrently_kwargs` for version of google-cloud-storage that does not support them (<2.7.0)."
141+
)
142+
133143
blob.download_to_filename(local_path)
134144

135145
return local_path

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
44

55
[project]
66
name = "cloudpathlib"
7-
version = "0.18.0"
7+
version = "0.18.1"
88
description = "pathlib-style classes for cloud storage services."
99
readme = "README.md"
1010
authors = [{ name = "DrivenData", email = "[email protected]" }]

0 commit comments

Comments
 (0)