daplapath 2.0.9__py3-none-any.whl → 2.0.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- daplapath/path.py +32 -4
- {daplapath-2.0.9.dist-info → daplapath-2.0.10.dist-info}/METADATA +1 -1
- daplapath-2.0.10.dist-info/RECORD +6 -0
- daplapath-2.0.9.dist-info/RECORD +0 -6
- {daplapath-2.0.9.dist-info → daplapath-2.0.10.dist-info}/LICENSE.md +0 -0
- {daplapath-2.0.9.dist-info → daplapath-2.0.10.dist-info}/WHEEL +0 -0
daplapath/path.py
CHANGED
|
@@ -31,6 +31,11 @@ try:
|
|
|
31
31
|
except ImportError:
|
|
32
32
|
pass
|
|
33
33
|
|
|
34
|
+
try:
|
|
35
|
+
from google.cloud import storage
|
|
36
|
+
except ImportError:
|
|
37
|
+
pass
|
|
38
|
+
|
|
34
39
|
# regex with the prefix '_v' followed by an integer of any length
|
|
35
40
|
VERSION_PATTERN = r"_v(\d+)\."
|
|
36
41
|
VERSION_PREFIX = "_v"
|
|
@@ -113,15 +118,26 @@ class LocalFileSystem(AbstractFileSystem):
|
|
|
113
118
|
return os.makedirs(path, exist_ok=exist_ok)
|
|
114
119
|
|
|
115
120
|
|
|
116
|
-
class
|
|
121
|
+
class MyGCSFileSystem(gcsfs.GCSFileSystem):
|
|
117
122
|
def isdir(self, path: str) -> bool:
|
|
118
123
|
"""Check if path is a directory."""
|
|
119
124
|
info = super(gcsfs.GCSFileSystem, self).info(path)
|
|
120
125
|
return info["type"] == "directory"
|
|
121
126
|
|
|
127
|
+
def rmdir(self, path: str) -> None:
|
|
128
|
+
"""Remove contents of a directory in GCS. It might take some time before files are actually deleted."""
|
|
129
|
+
path = pathlib.Path(path)
|
|
130
|
+
remaining = self.glob(str(path / "**"))
|
|
131
|
+
assert all(self.isdir(x) for x in remaining), remaining
|
|
132
|
+
storage_client = storage.Client()
|
|
133
|
+
bucket = storage_client.get_bucket(path.parts[0])
|
|
134
|
+
blobs = bucket.list_blobs(prefix="/".join(path.parts) + "/")
|
|
135
|
+
for blob in blobs:
|
|
136
|
+
blob.delete()
|
|
137
|
+
|
|
122
138
|
|
|
123
139
|
if any("dapla" in key.lower() for key in os.environ) and "gcsfs" in locals():
|
|
124
|
-
_config = Config(
|
|
140
|
+
_config = Config(MyGCSFileSystem)
|
|
125
141
|
else:
|
|
126
142
|
_config = Config(LocalFileSystem)
|
|
127
143
|
|
|
@@ -314,7 +330,14 @@ class Path(str, _PathBase):
|
|
|
314
330
|
return self._cp_or_mv(destination, "cp")
|
|
315
331
|
|
|
316
332
|
def mv(self, destination: "Path | str") -> "Path":
|
|
317
|
-
|
|
333
|
+
was_dir = self.isdir()
|
|
334
|
+
out_path = self._cp_or_mv(destination, "mv")
|
|
335
|
+
if was_dir:
|
|
336
|
+
try:
|
|
337
|
+
self.file_system.rmdir(str(self))
|
|
338
|
+
except (FileNotFoundError, NotADirectoryError):
|
|
339
|
+
pass
|
|
340
|
+
return out_path
|
|
318
341
|
|
|
319
342
|
def versions(self, include_versionless: bool = False) -> "PathSeries":
|
|
320
343
|
"""Returns a PathSeries of all versions of the file."""
|
|
@@ -698,7 +721,12 @@ class Path(str, _PathBase):
|
|
|
698
721
|
def partition_root(self) -> "Path":
|
|
699
722
|
if ".parquet" not in self:
|
|
700
723
|
return self
|
|
701
|
-
return self.split(".parquet")[0] + ".parquet"
|
|
724
|
+
return self._new(self.split(".parquet")[0] + ".parquet")
|
|
725
|
+
|
|
726
|
+
def is_partitioned(self) -> bool:
|
|
727
|
+
if ".parquet" not in self or self.isfile() and self.count(".parquet") != 2:
|
|
728
|
+
return False
|
|
729
|
+
return bool(len(self.glob("**/*.parquet")))
|
|
702
730
|
|
|
703
731
|
def isfile(self) -> bool:
|
|
704
732
|
return not self.isdir()
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
daplapath/__init__.py,sha256=Qdpwhl8y3-i_42-4-KVT-sPQtJqwWRENLFxROZ_rfbU,86
|
|
2
|
+
daplapath/path.py,sha256=2E09TCBAuxFNwfEmS-Utip9e1YXup4wFOSon4VAAGfs,55225
|
|
3
|
+
daplapath-2.0.10.dist-info/LICENSE.md,sha256=hxspefYgWP3U6OZFhCifqWMI5ksnKzgFxNKgQnG7Ozc,1074
|
|
4
|
+
daplapath-2.0.10.dist-info/METADATA,sha256=D20P6jlzE4vGpCnzaILe0pU8fpul8si7r2eEWiIE1tw,14698
|
|
5
|
+
daplapath-2.0.10.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
6
|
+
daplapath-2.0.10.dist-info/RECORD,,
|
daplapath-2.0.9.dist-info/RECORD
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
daplapath/__init__.py,sha256=Qdpwhl8y3-i_42-4-KVT-sPQtJqwWRENLFxROZ_rfbU,86
|
|
2
|
-
daplapath/path.py,sha256=8XFAPMmiDKxX_XLOORFJPmNf5BIkyf6drMdG--CwI94,54190
|
|
3
|
-
daplapath-2.0.9.dist-info/LICENSE.md,sha256=hxspefYgWP3U6OZFhCifqWMI5ksnKzgFxNKgQnG7Ozc,1074
|
|
4
|
-
daplapath-2.0.9.dist-info/METADATA,sha256=jM7z7Rgzfh2gAe6rgqA_WY0EVjr3KsDOYCDo0JcyvJY,14697
|
|
5
|
-
daplapath-2.0.9.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
6
|
-
daplapath-2.0.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|