megfile 4.1.0.post1__py3-none-any.whl → 4.1.0.post3__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.
megfile/cli.py CHANGED
@@ -246,7 +246,6 @@ def cp(
246
246
  dst_path,
247
247
  followlinks=True,
248
248
  map_func=executor.map,
249
- force=True,
250
249
  overwrite=not skip,
251
250
  )
252
251
  else:
@@ -255,7 +254,6 @@ def cp(
255
254
  dst_path,
256
255
  followlinks=True,
257
256
  map_func=executor.map,
258
- force=True,
259
257
  overwrite=not skip,
260
258
  )
261
259
  else:
@@ -38,6 +38,18 @@ class BasePrefetchReader(Readable[bytes], Seekable, ABC):
38
38
  max_workers: Optional[int] = None,
39
39
  **kwargs,
40
40
  ):
41
+ self._is_global_executor = False
42
+ if max_workers is None:
43
+ self._executor = process_local(
44
+ f"{self.__class__.__name__}.executor",
45
+ ThreadPoolExecutor,
46
+ max_workers=GLOBAL_MAX_WORKERS,
47
+ )
48
+ self._is_global_executor = True
49
+ else:
50
+ self._executor = ThreadPoolExecutor(max_workers=max_workers)
51
+ self._process_local = ProcessLocal()
52
+
41
53
  if max_buffer_size == 0:
42
54
  block_capacity = block_forward = 0
43
55
  else:
@@ -65,8 +77,6 @@ class BasePrefetchReader(Readable[bytes], Seekable, ABC):
65
77
  # Number of blocks every prefetch, which should be smaller than block_capacity
66
78
  self._block_forward = block_forward
67
79
 
68
- self._process_local = ProcessLocal()
69
-
70
80
  self._content_size = self._get_content_size()
71
81
  self._block_stop = ceil(self._content_size / block_size)
72
82
 
@@ -75,16 +85,6 @@ class BasePrefetchReader(Readable[bytes], Seekable, ABC):
75
85
  self._block_index = None # Current block index
76
86
  self._seek_history = []
77
87
 
78
- self._is_global_executor = False
79
- if max_workers is None:
80
- self._executor = process_local(
81
- f"{self.__class__.__name__}.executor",
82
- ThreadPoolExecutor,
83
- max_workers=GLOBAL_MAX_WORKERS,
84
- )
85
- self._is_global_executor = True
86
- else:
87
- self._executor = ThreadPoolExecutor(max_workers=max_workers)
88
88
  self._seek_buffer(0)
89
89
 
90
90
  _logger.debug("open file: %r, mode: %s" % (self.name, self.mode))
megfile/lib/glob.py CHANGED
@@ -176,6 +176,7 @@ def _rlistdir(dirname: str, dironly: bool, fs: FSFunc) -> Iterator[str]:
176
176
 
177
177
 
178
178
  magic_check = re.compile(r"([*?[{])")
179
+ magic_check_only_brace = re.compile(r"([{])")
179
180
  magic_decheck = re.compile(r"\[(.)\]")
180
181
  brace_check = re.compile(r"(\{.*\})")
181
182
  unbrace_check = re.compile(r"([*?[])")
@@ -215,6 +216,13 @@ def unescape(pathname):
215
216
  return drive + pathname
216
217
 
217
218
 
219
+ def escape_brace(pathname):
220
+ """Escape brace."""
221
+ drive, pathname = os.path.splitdrive(pathname)
222
+ pathname = magic_check_only_brace.sub(r"[\1]", pathname)
223
+ return drive + pathname
224
+
225
+
218
226
  def _find_suffix(path_list: List[str], prefix: str, split_sign: str) -> List[str]:
219
227
  suffix = []
220
228
  temp_path_list = []
@@ -275,13 +283,15 @@ def ungloblize(glob: str) -> List[str]:
275
283
  while True:
276
284
  temp_path = path_list[0]
277
285
  begin = temp_path.find("{")
286
+ while temp_path[begin - 1 : begin + 2] == "[{]":
287
+ begin = temp_path.find("{", begin + 1)
278
288
  end = temp_path.find("}", begin)
279
289
  if end == -1:
280
290
  break
281
291
  path_list.pop(0)
282
292
  subpath_list = temp_path[begin + 1 : end].split(",")
283
293
  for subpath in subpath_list:
284
- path = temp_path[:begin] + escape(subpath) + temp_path[end + 1 :]
294
+ path = temp_path[:begin] + escape_brace(subpath) + temp_path[end + 1 :]
285
295
  path_list.append(path)
286
296
  return path_list
287
297
 
@@ -130,6 +130,7 @@ class S3MemoryHandler(Readable[bytes], Seekable, Writable[bytes]):
130
130
  self._client.upload_fileobj(self._fileobj, self._bucket, self._key)
131
131
 
132
132
  def _close(self, need_upload: bool = True):
133
- if need_upload:
134
- self._upload_fileobj()
135
- self._fileobj.close()
133
+ if hasattr(self, "_fileobj"):
134
+ if need_upload:
135
+ self._upload_fileobj()
136
+ self._fileobj.close()
@@ -91,7 +91,7 @@ class S3PipeHandler(Readable[bytes], Writable[bytes]):
91
91
  self._exc = error
92
92
 
93
93
  def _raise_exception(self):
94
- if self._exc is not None:
94
+ if getattr(self, "_exc", None) is not None:
95
95
  raise translate_s3_error(self._exc, self.name)
96
96
 
97
97
  def readable(self) -> bool:
@@ -121,8 +121,10 @@ class S3PipeHandler(Readable[bytes], Writable[bytes]):
121
121
  return self._fileobj.write(data)
122
122
 
123
123
  def _close(self):
124
- self._fileobj.close()
125
- if self._join_thread:
124
+ if hasattr(self, "_fileobj"):
125
+ self._fileobj.close()
126
+ if self._join_thread and hasattr(self, "_async_task"):
126
127
  self._async_task.join()
127
- _s3_opened_pipes.remove(self._pipe)
128
+ if hasattr(self, "_pipe") and self._pipe in _s3_opened_pipes:
129
+ _s3_opened_pipes.remove(self._pipe)
128
130
  self._raise_exception()
megfile/s3_path.py CHANGED
@@ -406,12 +406,11 @@ def _group_s3path_by_bucket(
406
406
  if len(split_bucket_name) == 2:
407
407
  bucket_name, path_part = split_bucket_name
408
408
  pattern = re.compile(translate(re.sub(r"\*{2,}", "*", bucket_name)))
409
-
410
- for bucket in all_bucket(profile_name):
411
- if pattern.fullmatch(bucket) is not None:
409
+ for current_bucket in all_bucket(profile_name):
410
+ if pattern.fullmatch(current_bucket) is not None:
412
411
  if path_part is not None:
413
- bucket = "%s/%s" % (bucket, path_part)
414
- grouped_path.append(generate_s3_path(bucket, key))
412
+ current_bucket = "%s/%s" % (current_bucket, path_part)
413
+ grouped_path.append(generate_s3_path(current_bucket, key))
415
414
  else:
416
415
  grouped_path.append(generate_s3_path(bucket_name, key))
417
416
 
@@ -1293,7 +1292,9 @@ class S3Cacher(FileCacher):
1293
1292
  self.cache_path = cache_path
1294
1293
 
1295
1294
  def _close(self):
1296
- if self.cache_path is not None and os.path.exists(self.cache_path):
1295
+ if getattr(self, "cache_path", None) is not None and os.path.exists(
1296
+ self.cache_path
1297
+ ):
1297
1298
  if self.mode in ("w", "a"):
1298
1299
  s3_upload(self.cache_path, self.name)
1299
1300
  os.unlink(self.cache_path)
megfile/smart.py CHANGED
@@ -1052,7 +1052,9 @@ class SmartCacher(FileCacher):
1052
1052
  self.cache_path = cache_path
1053
1053
 
1054
1054
  def _close(self):
1055
- if self.cache_path is not None and os.path.exists(self.cache_path):
1055
+ if getattr(self, "cache_path", None) is not None and os.path.exists(
1056
+ self.cache_path
1057
+ ):
1056
1058
  if self.mode in ("w", "a"):
1057
1059
  smart_copy(self.cache_path, self.name)
1058
1060
  os.unlink(self.cache_path)
megfile/version.py CHANGED
@@ -1 +1 @@
1
- VERSION = "4.1.0.post1"
1
+ VERSION = "4.1.0.post3"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: megfile
3
- Version: 4.1.0.post1
3
+ Version: 4.1.0.post3
4
4
  Summary: Megvii file operation library
5
5
  Author-email: megvii <megfile@megvii.com>
6
6
  Project-URL: Homepage, https://github.com/megvii-research/megfile
@@ -1,5 +1,5 @@
1
1
  megfile/__init__.py,sha256=7oEfu410CFKzDWZ9RjL5xEJ1gtkJkTfvPrL_7TWdJuY,7366
2
- megfile/cli.py,sha256=Y7ZyWsYmzMUjUrJ1Vz-WMWJQcpK-4og_5xyRzfKI91U,24957
2
+ megfile/cli.py,sha256=5VF4m7ZcfYgsDdszUYsOytUdJFvoEAkafsqK-HwpTww,24893
3
3
  megfile/config.py,sha256=2MMj5QkhlDJQFZRbCQL2c9iDdeMAVctiaPszRBkg5vM,3988
4
4
  megfile/errors.py,sha256=qSIiqiJmDLb2k1qKiTLdNQzj4VNgfM9bHkSClyCp1Kg,14385
5
5
  megfile/fs.py,sha256=TJ0ifJ57IEL-gFgQhJD_WVEqmf28zC5kAvmH6c1QzbU,18240
@@ -11,21 +11,21 @@ megfile/http_path.py,sha256=yRIk-fNbrsY8rUS5KVOfocS_PS520dX5KOs8lImpLaY,14173
11
11
  megfile/interfaces.py,sha256=p4UvVZpeLx5djd6bqqDaygIx_s-_AxIVj-gudTch4JE,8467
12
12
  megfile/pathlike.py,sha256=3Hnw-fn6RcIe9iPrJt00QdHSA--UfDyxnVBuZ_ymYYQ,31278
13
13
  megfile/s3.py,sha256=abBxnI7RIyn7n7qjGszP1VruYd6Gi9I8QnUOvsHkx1Y,16325
14
- megfile/s3_path.py,sha256=w9_I3BMbLTmu4WCa0W0O0NnFkOHS0CQ-9fvtViL-2iU,93565
14
+ megfile/s3_path.py,sha256=zelXhlRVOVSWBE6HJz0vXrrcRzSuj6Cnjd9HLGwPbCM,93644
15
15
  megfile/sftp.py,sha256=uBcLQs-j6Q-q-sWAdd-pgi5Qmb_kq7boJM-0sCfcNO0,26540
16
16
  megfile/sftp_path.py,sha256=Wz4VcQ0pBUuWDGMSxPpPbutrT09mnY6jZNiAqTi5tO4,43840
17
- megfile/smart.py,sha256=xkNVEa3DAThM4zJf3aoHJg_t8PQeVv9yz66GhGIdhpA,36974
17
+ megfile/smart.py,sha256=YXjCWp000wimSFXE8oqI6dIE8y0RZJo9I046zIkh0ag,37014
18
18
  megfile/smart_path.py,sha256=Bqg95T2-XZrRXWhH7GT-jMCYzD7i1SIXdczQxtOxiPs,7583
19
19
  megfile/stdio.py,sha256=ZwxsnJNJYIT7Iyg5pIw4qiyH8bszG6oAhEJuR-hXGG4,658
20
20
  megfile/stdio_path.py,sha256=cxaDr8rtisTPnN-rjtaEpqQnshwiqwXFUJBM9xWY7Cg,2711
21
- megfile/version.py,sha256=0T8ZzQ_dcDIRsR27VgeThkcTcJi4fE4WvZ8Me4aXAwc,25
21
+ megfile/version.py,sha256=wNRjMrkurG2-lYRZx4EZUY9SjbBWGLHy8zGyNvzRmuA,25
22
22
  megfile/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
- megfile/lib/base_prefetch_reader.py,sha256=oSiQq6wlV9DADQapkf3Up3-86zl6QrtusVu93MAt1KE,12848
23
+ megfile/lib/base_prefetch_reader.py,sha256=uxVwYknOjc8hLF7q_T2QKMsBqFcrf411ZsuK25CN1eQ,12848
24
24
  megfile/lib/combine_reader.py,sha256=Kp2wEloOUpTlIU7dve87MBpSzmIM-F9OtpTawAjFkiU,4828
25
25
  megfile/lib/compare.py,sha256=n_dtLxgoskYnsIZMKdKmVhQoVn8qYUrUhkS1JH2_X3o,2170
26
26
  megfile/lib/compat.py,sha256=SynEeHluys3tCK-lb_1oV3o_ft83yZvunqM_AjibLgE,207
27
27
  megfile/lib/fnmatch.py,sha256=4MvGzEahMRA-u8Z7mxaD-Yw1idOwBoJJpVywQy29jwY,4162
28
- megfile/lib/glob.py,sha256=1u0j_DoqT7VmTUsDAdcKhPbr4XOwIBpOkCnyAFEGw1I,9633
28
+ megfile/lib/glob.py,sha256=-N75Phx1c8IpZ2hNIMwsHIx6BxMKVVr7N82cpWhs4lQ,9987
29
29
  megfile/lib/hdfs_prefetch_reader.py,sha256=yCNpcXcTiC2SHKHC-Qp50KQx1ObSLmOgwNUKlG-4ADg,2131
30
30
  megfile/lib/hdfs_tools.py,sha256=4K-OdMYFFSLBGmDzjatioHvuZuUbKVy7ACeJl-l0HLQ,435
31
31
  megfile/lib/http_prefetch_reader.py,sha256=OjP5pdWK_e1QiFIt2xmflceLnrz3S7B7ePBZFK-OwQE,4558
@@ -34,8 +34,8 @@ megfile/lib/lazy_handler.py,sha256=bE7RGt1x_xYWMgGAvHr7dwEt52qy-D3z90X3oyCvE6g,1
34
34
  megfile/lib/s3_buffered_writer.py,sha256=kXvz1bdoaVIxjnEQeg4dxEzAXMYNrk-5uIMww86ty00,7860
35
35
  megfile/lib/s3_cached_handler.py,sha256=MkNt6AAapd5x8BH2gnW5_S0cLofN-mshEdb0qSoLho8,1426
36
36
  megfile/lib/s3_limited_seekable_writer.py,sha256=joVcjoTx48jataXAwEqOI3toRxxO3-XQRvyWHtJ23lQ,6232
37
- megfile/lib/s3_memory_handler.py,sha256=_2JCLbbPUuIGGCeUEuSRZ-mdDRtGow2ofgtAQwzru4s,4136
38
- megfile/lib/s3_pipe_handler.py,sha256=QKhcjXWkedM4-eX0BhZVmkmCjawfyBJfYzmGFUclO8w,3642
37
+ megfile/lib/s3_memory_handler.py,sha256=epIzQgTlE_deuVlP4LTmsh1T3cmAgK8ATEwrit9j7X8,4186
38
+ megfile/lib/s3_pipe_handler.py,sha256=g3iAN1P9pCdvSNsGeJBGcBa10S62oqIg_9W3b3wc7os,3809
39
39
  megfile/lib/s3_prefetch_reader.py,sha256=R37-y_L9l8IKJhpT8HwBrZEbo2X72vCqEV6fvqPCBug,4437
40
40
  megfile/lib/s3_share_cache_reader.py,sha256=LVWKxHdHo0_zUIW4o8yqNvplqqwezUPeYEt02Vj-WNM,3754
41
41
  megfile/lib/shadow_handler.py,sha256=TntewlvIW9ZxCfmqASDQREHoiZ8v42faOe9sovQYQz0,2779
@@ -53,10 +53,10 @@ scripts/benchmark/code/s3fs_read.py,sha256=XiTA-qrYblUs-jQWXSnvNg5Wo722C_g47aMMf
53
53
  scripts/benchmark/code/s3fs_write.py,sha256=gdXKkWXYGjLJlRT_J64pJN85XvRg3bZexcAJQEMXwtw,402
54
54
  scripts/benchmark/code/smart_open_read.py,sha256=SA02jHwS9Y31yFtV9CoJcfND5dR0eA_HsGmGNUrpQls,515
55
55
  scripts/benchmark/code/smart_open_write.py,sha256=jDxFJdY97yNH889jz3pawBoei3yaqy8pEMvC_ymHFtM,537
56
- megfile-4.1.0.post1.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
57
- megfile-4.1.0.post1.dist-info/LICENSE.pyre,sha256=9lf5nT-5ZH25JijpYAequ0bl8E8z5JmZB1qrjiUMp84,1080
58
- megfile-4.1.0.post1.dist-info/METADATA,sha256=McvjueS05XMnfNKJMjzNz6w5Oj5KK27DgJkYRm8q6hE,9579
59
- megfile-4.1.0.post1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
60
- megfile-4.1.0.post1.dist-info/entry_points.txt,sha256=M6ZWSSv5_5_QtIpZafy3vq7WuOJ_5dSGQQnEZbByt2Q,49
61
- megfile-4.1.0.post1.dist-info/top_level.txt,sha256=fVg49lk5B9L7jyfWUXWxb0DDSuw5pbr0OU62Tvx8J8M,44
62
- megfile-4.1.0.post1.dist-info/RECORD,,
56
+ megfile-4.1.0.post3.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
57
+ megfile-4.1.0.post3.dist-info/LICENSE.pyre,sha256=9lf5nT-5ZH25JijpYAequ0bl8E8z5JmZB1qrjiUMp84,1080
58
+ megfile-4.1.0.post3.dist-info/METADATA,sha256=Y1lKXJkvmVgl-O_VwFqMYtumMDM7LiJA7xR9i6sRrY8,9579
59
+ megfile-4.1.0.post3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
60
+ megfile-4.1.0.post3.dist-info/entry_points.txt,sha256=M6ZWSSv5_5_QtIpZafy3vq7WuOJ_5dSGQQnEZbByt2Q,49
61
+ megfile-4.1.0.post3.dist-info/top_level.txt,sha256=fVg49lk5B9L7jyfWUXWxb0DDSuw5pbr0OU62Tvx8J8M,44
62
+ megfile-4.1.0.post3.dist-info/RECORD,,