Skip to content

Commit

Permalink
azure/gcs: fix container/bucket creation
Browse files Browse the repository at this point in the history
Calling mkdir with parents=True now calls makedirs, which is
not implemented for gcsfs and adlfs, requiring us to use these
workarounds to properly create buckets/containers.

See fsspec/universal_pathlib#166
  • Loading branch information
dtrifiro committed Dec 15, 2023
1 parent 9606d66 commit dcca75d
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/pytest_servers/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,19 @@ def azure(
connection_string: str,
**kwargs,
) -> UPath:
"""Create a new container and returns an UPath instance."""
"""Create a new container and return an UPath instance."""
from azure.storage.blob import BlobServiceClient

container_name = f"pytest-servers-{random_string()}"
client = BlobServiceClient.from_connection_string(conn_str=connection_string)
client.create_container(container_name)

path = UPath(
f"az://{container_name}",
connection_string=connection_string,
# To actually get an error instead of a false-positive
# "Container exists", see https://github.com/fsspec/adlfs/pull/415
assume_container_exists=False,
**kwargs,
)
path.mkdir(parents=True, exist_ok=False)
return path
path.fs.client.create_container(container_name)

def memory(
self,
Expand Down Expand Up @@ -262,10 +263,7 @@ def gcs(
**client_kwargs,
**kwargs,
)
if version_aware:
path.fs.mkdir(bucket_name, enable_versioning=True, exist_ok=False)
else:
path.mkdir(parents=True, exist_ok=False)
path.fs.mkdir(bucket_name, enable_versioning=version_aware, exist_ok=False)

# UPath adds a trailing slash here, due to which
# gcsfs.isdir() returns False.
Expand Down

0 comments on commit dcca75d

Please sign in to comment.