Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
12 changes: 10 additions & 2 deletions gigl/common/utils/gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ def __init__(self, project: Optional[str] = None) -> None:
project (Optional[str]): The GCP project ID. Defaults to None.
"""
self.__storage_client = storage.Client(project=project)
# Upstream stub types .project as Optional[str], but Client.__init__
# raises if no project can be determined — so it's always a str here.
project = self.__storage_client.project
if not isinstance(project, str):
raise TypeError(
f"Expected storage client project to be a str, got {type(project).__name__}"
)
self.__project: str = project

def upload_from_string(self, gcs_path: GcsUri, content: str) -> None:
bucket_name, blob_name = self.get_bucket_and_blob_path_from_gcs_path(gcs_path)
Expand Down Expand Up @@ -133,7 +141,7 @@ def upload_files_to_gcs(
"""
if parallel:
_upload_files_to_gcs_parallel(
project=self.__storage_client.project, # ty: ignore[invalid-argument-type]
project=self.__project,
local_file_path_to_gcs_path_map=local_file_path_to_gcs_path_map,
)
else:
Expand All @@ -144,7 +152,7 @@ def upload_files_to_gcs(
_upload_file_to_gcs(
source_file_path=source_file_path,
dest_gcs_path=dest_gcs_path,
project=self.__storage_client.project,
project=self.__project,
gcs_utils_client=self.__storage_client,
)

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/utils/gcs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class TestGcsUtils(TestCase):
def test_upload_from_filelike(self, mock_storage_client):
# Mock the GCS client, bucket, and blob
mock_client = MagicMock(spec=Client)
mock_client.project = "test-project"
mock_bucket = MagicMock(spec=Bucket)
mock_blob = MagicMock(spec=Blob)

Expand Down Expand Up @@ -43,6 +44,7 @@ def test_upload_from_filelike(self, mock_storage_client):
def test_delete_files_in_bucket_dir(self):
# Mock the GCS client, bucket, and blob
mock_client = MagicMock(spec=Client)
mock_client.project = "test-project"
mock_bucket = MagicMock(spec=Bucket)

non_existent_bucket = "test-bucket"
Expand Down