-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
200 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .azure import local_azure_blob_implementation, LocalAzureBlobClient, LocalAzureBlobPath | ||
from .gs import local_gs_implementation, LocalGSClient, LocalGSPath | ||
from .s3 import local_s3_implementation, LocalS3Client, LocalS3Path | ||
|
||
__all__ = [ | ||
"local_azure_blob_implementation", | ||
"LocalAzureBlobClient", | ||
"LocalAzureBlobPath", | ||
"local_gs_implementation", | ||
"LocalGSClient", | ||
"LocalGSPath", | ||
"local_s3_implementation", | ||
"LocalS3Client", | ||
"LocalS3Path", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from ...cloudpath import CloudImplementation | ||
from ..localclient import LocalClient | ||
from ..localpath import LocalPath | ||
|
||
|
||
local_gs_implementation = CloudImplementation() | ||
"""Replacement for "gs" CloudImplementation meta object in cloudpathlib.implementation_registry""" | ||
|
||
|
||
class LocalGSClient(LocalClient): | ||
"""Replacement for GSClient that uses the local file system. Intended as a monkeypatch | ||
substitute when writing tests. | ||
""" | ||
|
||
_cloud_meta = local_gs_implementation | ||
|
||
|
||
LocalGSClient.GSPath = LocalGSClient.CloudPath # type: ignore | ||
|
||
|
||
class LocalGSPath(LocalPath): | ||
"""Replacement for GSPath that uses the local file system. Intended as a monkeypatch substitute | ||
when writing tests. | ||
""" | ||
|
||
cloud_prefix: str = "gs://" | ||
_cloud_meta = local_gs_implementation | ||
|
||
@property | ||
def drive(self) -> str: | ||
return self.bucket | ||
|
||
def mkdir(self, parents=False, exist_ok=False): | ||
# not possible to make empty directory on gs | ||
pass | ||
|
||
@property | ||
def bucket(self) -> str: | ||
return self._no_prefix.split("/", 1)[0] | ||
|
||
@property | ||
def blob(self) -> str: | ||
key = self._no_prefix_no_drive | ||
|
||
# key should never have starting slash for | ||
# use with boto, etc. | ||
if key.startswith("/"): | ||
key = key[1:] | ||
|
||
return key | ||
|
||
@property | ||
def etag(self): | ||
return self.client._md5(self) | ||
|
||
|
||
LocalGSPath.__name__ = "GSPath" | ||
|
||
local_gs_implementation._client_class = LocalGSClient | ||
local_gs_implementation._path_class = LocalGSPath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from ...cloudpath import CloudImplementation | ||
from ..localclient import LocalClient | ||
from ..localpath import LocalPath | ||
|
||
|
||
local_s3_implementation = CloudImplementation() | ||
"""Replacement for "s3" CloudImplementation meta object in cloudpathlib.implementation_registry""" | ||
|
||
|
||
class LocalS3Client(LocalClient): | ||
"""Replacement for S3Client that uses the local file system. Intended as a monkeypatch | ||
substitute when writing tests. | ||
""" | ||
|
||
_cloud_meta = local_s3_implementation | ||
|
||
|
||
LocalS3Client.S3Path = LocalS3Client.CloudPath # type: ignore | ||
|
||
|
||
class LocalS3Path(LocalPath): | ||
"""Replacement for S3Path that uses the local file system. Intended as a monkeypatch substitute | ||
when writing tests. | ||
""" | ||
|
||
cloud_prefix: str = "s3://" | ||
_cloud_meta = local_s3_implementation | ||
|
||
@property | ||
def drive(self) -> str: | ||
return self.bucket | ||
|
||
def mkdir(self, parents=False, exist_ok=False): | ||
# not possible to make empty directory on s3 | ||
pass | ||
|
||
@property | ||
def bucket(self) -> str: | ||
return self._no_prefix.split("/", 1)[0] | ||
|
||
@property | ||
def key(self) -> str: | ||
key = self._no_prefix_no_drive | ||
|
||
# key should never have starting slash for | ||
# use with boto, etc. | ||
if key.startswith("/"): | ||
key = key[1:] | ||
|
||
return key | ||
|
||
@property | ||
def etag(self): | ||
return self.client._md5(self) | ||
|
||
|
||
LocalS3Path.__name__ = "S3Path" | ||
|
||
local_s3_implementation._client_class = LocalS3Client | ||
local_s3_implementation._path_class = LocalS3Path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters