megfile 4.2.1__py3-none-any.whl → 4.2.3__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/errors.py CHANGED
@@ -9,6 +9,10 @@ from typing import Callable, Optional
9
9
  import botocore.exceptions
10
10
  import requests.exceptions
11
11
  import urllib3.exceptions
12
+ from boto3.exceptions import ( # TODO: test different boto3 version
13
+ S3TransferFailedError,
14
+ S3UploadFailedError,
15
+ )
12
16
  from botocore.exceptions import ClientError, NoCredentialsError, ParamValidationError
13
17
  from requests.exceptions import HTTPError
14
18
 
@@ -402,6 +406,19 @@ def translate_s3_error(s3_error: Exception, s3_url: PathLike) -> Exception:
402
406
  return S3UnknownError(s3_error, s3_url)
403
407
  elif isinstance(s3_error, NoCredentialsError):
404
408
  return S3ConfigError(str(s3_error))
409
+ elif isinstance(s3_error, (S3UploadFailedError, S3TransferFailedError)):
410
+ if "NoSuchBucket" in str(s3_error):
411
+ return S3BucketNotFoundError("No such bucket: %r" % s3_url)
412
+ elif "NoSuchKey" in str(s3_error):
413
+ return S3FileNotFoundError("No such file: %r" % s3_url)
414
+ elif "InvalidAccessKeyId" in str(s3_error) or "SignatureDoesNotMatch" in str(
415
+ s3_error
416
+ ):
417
+ return S3ConfigError("Invalid access key id: %r" % s3_url)
418
+ elif "InvalidRange" in str(s3_error):
419
+ return S3InvalidRangeError("Invalid range: %r" % s3_url)
420
+ elif "AccessDenied" in str(s3_error):
421
+ return S3PermissionError("Access denied: %r" % s3_url)
405
422
  return S3UnknownError(s3_error, s3_url)
406
423
 
407
424
 
megfile/lib/compare.py CHANGED
@@ -5,10 +5,10 @@ from megfile.pathlike import StatResult
5
5
 
6
6
 
7
7
  def get_sync_type(src_protocol, dst_protocol):
8
- if src_protocol == "s3" and dst_protocol != "s3":
9
- return "download"
10
- elif src_protocol != "s3" and dst_protocol == "s3":
8
+ if dst_protocol == "s3" or dst_protocol.startswith("s3+"):
11
9
  return "upload"
10
+ elif src_protocol == "s3" or src_protocol.startswith("s3+"):
11
+ return "download"
12
12
  else:
13
13
  return "copy"
14
14
 
megfile/lib/glob.py CHANGED
@@ -289,6 +289,9 @@ def get_non_glob_dir(glob: str):
289
289
  root_dir = []
290
290
  if glob.startswith("/"):
291
291
  root_dir.append("/")
292
+ elif "://" in glob:
293
+ protocol, glob = glob.split("://", 1)
294
+ root_dir.append(f"{protocol}://")
292
295
  for name in glob.split("/"):
293
296
  if has_magic(name):
294
297
  break
megfile/s3_path.py CHANGED
@@ -610,6 +610,7 @@ def _s3_glob_stat_single_path(
610
610
  yield FileEntry(S3Path(path).name, path, _make_stat(content))
611
611
  dirname = os.path.dirname(path)
612
612
  while dirname not in dirnames and dirname != top_dir:
613
+ # TODO: optimize memory usage and file path order
613
614
  dirnames.add(dirname)
614
615
  path = dirname + "/" if search_dir else dirname
615
616
  if pattern.match(path):
@@ -1201,6 +1202,10 @@ def s3_upload(
1201
1202
  src_path = FSPath(src_url)
1202
1203
  if followlinks and src_path.is_symlink():
1203
1204
  src_path = src_path.readlink()
1205
+ if not src_path.exists():
1206
+ raise FileNotFoundError("No such file or directory: %r" % src_url)
1207
+ elif src_path.is_dir():
1208
+ raise IsADirectoryError("Is a directory: %r" % src_url)
1204
1209
 
1205
1210
  dst_bucket, dst_key = parse_s3_url(dst_url)
1206
1211
  if not dst_bucket:
@@ -1212,8 +1217,8 @@ def s3_upload(
1212
1217
  return
1213
1218
 
1214
1219
  client = get_s3_client_with_cache(profile_name=S3Path(dst_url)._profile_name)
1215
- upload_fileobj = patch_method(
1216
- client.upload_fileobj, max_retries=max_retries, should_retry=s3_should_retry
1220
+ upload_file = patch_method(
1221
+ client.upload_file, max_retries=max_retries, should_retry=s3_should_retry
1217
1222
  )
1218
1223
 
1219
1224
  transfer_config = TransferConfig(
@@ -1221,9 +1226,9 @@ def s3_upload(
1221
1226
  max_concurrency=GLOBAL_MAX_WORKERS,
1222
1227
  multipart_chunksize=WRITER_BLOCK_SIZE,
1223
1228
  )
1224
- with open(src_path.path_without_protocol, "rb") as src, raise_s3_error(dst_url):
1225
- upload_fileobj(
1226
- src,
1229
+ with raise_s3_error(dst_url):
1230
+ upload_file(
1231
+ src_path.path_without_protocol,
1227
1232
  Bucket=dst_bucket,
1228
1233
  Key=dst_key,
1229
1234
  Callback=callback,
megfile/smart.py CHANGED
@@ -308,8 +308,18 @@ def _default_copy_func(
308
308
 
309
309
 
310
310
  def _get_copy_func(src_protocol, dst_protocol):
311
- if src_protocol.startswith("s3+") and src_protocol == dst_protocol:
311
+ def _is_s3_plus(protocol: str):
312
+ return protocol.startswith("s3+")
313
+
314
+ def _is_s3_or_s3_plus(protocol: str):
315
+ return protocol.startswith("s3+") or protocol == "s3"
316
+
317
+ if _is_s3_plus(src_protocol) and src_protocol == dst_protocol:
312
318
  src_protocol = dst_protocol = "s3"
319
+ elif _is_s3_plus(src_protocol) and not _is_s3_or_s3_plus(dst_protocol):
320
+ src_protocol = "s3"
321
+ elif _is_s3_plus(dst_protocol) and not _is_s3_or_s3_plus(src_protocol):
322
+ dst_protocol = "s3"
313
323
 
314
324
  try:
315
325
  return _copy_funcs[src_protocol][dst_protocol]
megfile/version.py CHANGED
@@ -1 +1 @@
1
- VERSION = "4.2.1"
1
+ VERSION = "4.2.3"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: megfile
3
- Version: 4.2.1
3
+ Version: 4.2.3
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
@@ -24,7 +24,7 @@ License-File: LICENSE.pyre
24
24
  Requires-Dist: boto3
25
25
  Requires-Dist: botocore>=1.13.0
26
26
  Requires-Dist: requests
27
- Requires-Dist: paramiko
27
+ Requires-Dist: paramiko<4.0.0
28
28
  Requires-Dist: tqdm
29
29
  Requires-Dist: pyyaml
30
30
  Provides-Extra: hdfs
@@ -1,7 +1,7 @@
1
1
  megfile/__init__.py,sha256=7oEfu410CFKzDWZ9RjL5xEJ1gtkJkTfvPrL_7TWdJuY,7366
2
2
  megfile/cli.py,sha256=VxY0__M19Ti_S7ZIozp9l0FxvdLwdd6eQL-wfpYOi_0,29160
3
3
  megfile/config.py,sha256=2MMj5QkhlDJQFZRbCQL2c9iDdeMAVctiaPszRBkg5vM,3988
4
- megfile/errors.py,sha256=aw4BX-pU1uj0-dNc6Tq-IeSwK_PWJNi2ZL5ZcRSo7aQ,14739
4
+ megfile/errors.py,sha256=cGSYyB7VBRKi1Gehgt9IO-wDvtzICV4XgKOkoMvLU5w,15583
5
5
  megfile/fs.py,sha256=KMEqAE35alpcxiy6du5nPFYcaorhUM_kPJMah3q76ng,19160
6
6
  megfile/fs_path.py,sha256=Hozl9LAJ8EMuSWBSZXGj2GNmPZ1sJp9PZs-7hPrLgm8,39341
7
7
  megfile/hdfs.py,sha256=owXr4d3j1frCvlbhmhENcSBnKKDky5cJZzWLOF4ZJMo,13251
@@ -11,21 +11,21 @@ megfile/http_path.py,sha256=08OmzmRMyLSyq1Yr1K2HbzexesURJrIoA6AibwYzUiA,13844
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=NKOJLxy1gxdOc-jdEvxNl45tham5un8YWmZC-CZXHuU,93663
14
+ megfile/s3_path.py,sha256=yulypUpJ2k0WzOPbeXyx8Q75YGJa3R5qXBt2QmMt9H0,93901
15
15
  megfile/sftp.py,sha256=uBcLQs-j6Q-q-sWAdd-pgi5Qmb_kq7boJM-0sCfcNO0,26540
16
16
  megfile/sftp_path.py,sha256=CgirHWmNdXdqyIL9ufmlaMpwFhlkQVZhqmfvjUaj7qU,43845
17
- megfile/smart.py,sha256=Miz3jyLKmwWBja-8GrSzrumpTarPrFPqXaFQJKwrK1Y,36627
17
+ megfile/smart.py,sha256=GnabQVb_NU7a-etKfF-NgpJ9JM2rT0uZBeA9UoNz_wM,37014
18
18
  megfile/smart_path.py,sha256=Up_6xNZ2019iSzMn_JAU_1H--z-AP6O7SxdXGdeTG0c,7659
19
19
  megfile/stdio.py,sha256=ZwxsnJNJYIT7Iyg5pIw4qiyH8bszG6oAhEJuR-hXGG4,658
20
20
  megfile/stdio_path.py,sha256=cxaDr8rtisTPnN-rjtaEpqQnshwiqwXFUJBM9xWY7Cg,2711
21
- megfile/version.py,sha256=e0k-2Nn8dpoGmVJ3Wg03fcRMzM9q9jfKeY7f3OkI7LE,19
21
+ megfile/version.py,sha256=DjJW-M4YIrKI_sFscLAPh7I9pVVFC24RH3yBxS8RkNI,19
22
22
  megfile/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  megfile/lib/base_prefetch_reader.py,sha256=uxVwYknOjc8hLF7q_T2QKMsBqFcrf411ZsuK25CN1eQ,12848
24
24
  megfile/lib/combine_reader.py,sha256=Kp2wEloOUpTlIU7dve87MBpSzmIM-F9OtpTawAjFkiU,4828
25
- megfile/lib/compare.py,sha256=n_dtLxgoskYnsIZMKdKmVhQoVn8qYUrUhkS1JH2_X3o,2170
25
+ megfile/lib/compare.py,sha256=CPSbyqsQ396oSfxa7h0NdUUqBw5A3WOn6fHrNKkuinw,2188
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=anr7JjCJz1T0G5hYQkJwV5mCWzlt5YaxGTyyyQB28zA,9663
28
+ megfile/lib/glob.py,sha256=BSpYm6w16rVuIBCI9hNOCxn83BN7UuKGBp2wFRFdwp4,9775
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=OQPZ7kWFImqpynjaiTtmadtgtab5fCeQmu51UYHZfgs,4135
@@ -43,10 +43,10 @@ megfile/lib/stdio_handler.py,sha256=IDdgENLQlhigEwkLL4zStueVSzdWg7xVcTF_koof_Ek,
43
43
  megfile/lib/url.py,sha256=ER32pWy9Q2MAk3TraAaNEBWIqUeBmLuM57ol2cs7-Ks,103
44
44
  megfile/utils/__init__.py,sha256=pawmXnCNokWLj338a60b_hK21koYavpEiEohZhsOaGQ,10156
45
45
  megfile/utils/mutex.py,sha256=asb8opGLgK22RiuBJUnfsvB8LnMmodP8KzCVHKmQBWA,2561
46
- megfile-4.2.1.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
47
- megfile-4.2.1.dist-info/licenses/LICENSE.pyre,sha256=9lf5nT-5ZH25JijpYAequ0bl8E8z5JmZB1qrjiUMp84,1080
48
- megfile-4.2.1.dist-info/METADATA,sha256=8-Gzye2STZTocHieLky8XR0nAae8sHEmanRVeTWKWYM,9595
49
- megfile-4.2.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
50
- megfile-4.2.1.dist-info/entry_points.txt,sha256=M6ZWSSv5_5_QtIpZafy3vq7WuOJ_5dSGQQnEZbByt2Q,49
51
- megfile-4.2.1.dist-info/top_level.txt,sha256=i3rMgdU1ZAJekAceojhA-bkm3749PzshtRmLTbeLUPQ,8
52
- megfile-4.2.1.dist-info/RECORD,,
46
+ megfile-4.2.3.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
47
+ megfile-4.2.3.dist-info/licenses/LICENSE.pyre,sha256=9lf5nT-5ZH25JijpYAequ0bl8E8z5JmZB1qrjiUMp84,1080
48
+ megfile-4.2.3.dist-info/METADATA,sha256=EKObM2zjGcOsvRyMILjA4qgEvJg72mPB8icyZhBbZ9o,9601
49
+ megfile-4.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
50
+ megfile-4.2.3.dist-info/entry_points.txt,sha256=M6ZWSSv5_5_QtIpZafy3vq7WuOJ_5dSGQQnEZbByt2Q,49
51
+ megfile-4.2.3.dist-info/top_level.txt,sha256=i3rMgdU1ZAJekAceojhA-bkm3749PzshtRmLTbeLUPQ,8
52
+ megfile-4.2.3.dist-info/RECORD,,