megfile 4.1.6__py3-none-any.whl → 4.1.8__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/lib/glob.py CHANGED
@@ -247,19 +247,8 @@ def globlize(path_list: List[str]) -> str:
247
247
  path_list = sorted(path_list)
248
248
  if path_list[0] == path_list[-1]:
249
249
  return path_list[0]
250
- first_path = path_list[0].split("/")
251
- last_path = path_list[-1].split("/")
252
- prefix = []
253
250
 
254
- for i in range(0, min(len(first_path), len(last_path))):
255
- if first_path[i] == last_path[i]:
256
- prefix.append(first_path[i])
257
- else:
258
- break
259
- if len(prefix) == 0:
260
- prefix = ""
261
- else:
262
- prefix = "/".join(prefix) + "/"
251
+ prefix = os.path.commonprefix(path_list)
263
252
  suffix = _find_suffix(path_list, prefix, "/")
264
253
 
265
254
  if len(suffix) == 0:
megfile/s3_path.py CHANGED
@@ -215,10 +215,12 @@ def get_endpoint_url(profile_name: Optional[str] = None) -> str:
215
215
 
216
216
  :returns: S3 endpoint url
217
217
  """
218
+ profile_name = profile_name or os.environ.get("AWS_PROFILE")
219
+ environ_keys = ("OSS_ENDPOINT", "AWS_ENDPOINT_URL_S3", "AWS_ENDPOINT_URL")
218
220
  if profile_name:
219
- environ_keys = (f"{profile_name}__OSS_ENDPOINT".upper(),)
220
- else:
221
- environ_keys = ("OSS_ENDPOINT", "AWS_ENDPOINT_URL_S3", "AWS_ENDPOINT_URL")
221
+ environ_keys = tuple(
222
+ f"{profile_name}__{environ_key}".upper() for environ_key in environ_keys
223
+ )
222
224
  for environ_key in environ_keys:
223
225
  environ_endpoint_url = os.environ.get(environ_key)
224
226
  if environ_endpoint_url:
@@ -244,6 +246,7 @@ def get_s3_session(profile_name=None) -> boto3.Session:
244
246
 
245
247
 
246
248
  def get_env_var(env_name: str, profile_name=None):
249
+ profile_name = profile_name or os.environ.get("AWS_PROFILE")
247
250
  if profile_name:
248
251
  return os.getenv(f"{profile_name}__{env_name}".upper())
249
252
  return os.getenv(env_name.upper())
@@ -257,16 +260,15 @@ def get_access_token(profile_name=None):
257
260
  return access_key, secret_key, session_token
258
261
 
259
262
  try:
260
- credentials = get_s3_session(profile_name=profile_name).get_credentials()
261
- except botocore.exceptions.ProfileNotFound:
262
- credentials = None
263
- if credentials:
263
+ config = get_scoped_config(profile_name=profile_name)
264
264
  if not access_key:
265
- access_key = credentials.access_key
265
+ access_key = config.get("aws_access_key_id")
266
266
  if not secret_key:
267
- secret_key = credentials.secret_key
267
+ secret_key = config.get("aws_secret_access_key")
268
268
  if not session_token:
269
- session_token = credentials.token
269
+ session_token = config.get("aws_session_token")
270
+ except botocore.exceptions.ProfileNotFound:
271
+ pass
270
272
  return access_key, secret_key, session_token
271
273
 
272
274
 
@@ -485,17 +487,10 @@ def _become_prefix(prefix: str) -> str:
485
487
 
486
488
 
487
489
  def _s3_split_magic(s3_pathname: str) -> Tuple[str, str]:
488
- if not has_magic(s3_pathname):
489
- return s3_pathname, ""
490
- normal_parts = []
491
- magic_parts = []
492
- all_parts = s3_pathname.split("/")
493
- for i, part in enumerate(all_parts):
494
- if has_magic(part):
495
- magic_parts = all_parts[i:]
496
- break
497
- normal_parts.append(part)
498
- return "/".join(normal_parts), "/".join(magic_parts)
490
+ for i in range(len(s3_pathname) - 1, 0, -1):
491
+ if not has_magic(s3_pathname[:i]):
492
+ return s3_pathname[:i], s3_pathname[i:]
493
+ return s3_pathname, ""
499
494
 
500
495
 
501
496
  def _list_objects_recursive(s3_client, bucket: str, prefix: str, delimiter: str = ""):
@@ -572,7 +567,8 @@ def _s3_glob_stat_single_path(
572
567
  # If not recursive, replace ** with *
573
568
  s3_pathname = re.sub(r"\*{2,}", "*", s3_pathname)
574
569
  protocol, profile_name = _parse_s3_url_profile(s3_pathname)
575
- top_dir, wildcard_part = _s3_split_magic(s3_pathname)
570
+ top_prefix, wildcard_part = _s3_split_magic(s3_pathname)
571
+ top_dir = os.path.dirname(top_prefix) if wildcard_part else top_prefix
576
572
  search_dir = wildcard_part.endswith("/")
577
573
 
578
574
  def should_recursive(wildcard_part: str) -> bool:
@@ -602,8 +598,7 @@ def _s3_glob_stat_single_path(
602
598
 
603
599
  dirnames = set()
604
600
  pattern = re.compile(translate(_s3_pathname))
605
- bucket, key = parse_s3_url(top_dir)
606
- prefix = _become_prefix(key)
601
+ bucket, prefix = parse_s3_url(top_prefix)
607
602
  client = get_s3_client_with_cache(profile_name=profile_name)
608
603
  with raise_s3_error(_s3_pathname, S3BucketNotFoundError):
609
604
  for resp in _list_objects_recursive(client, bucket, prefix, delimiter):
megfile/smart.py CHANGED
@@ -307,6 +307,16 @@ def _default_copy_func(
307
307
  pass
308
308
 
309
309
 
310
+ def _get_copy_func(src_protocol, dst_protocol):
311
+ if src_protocol.startswith("s3+") and src_protocol == dst_protocol:
312
+ src_protocol = dst_protocol = "s3"
313
+
314
+ try:
315
+ return _copy_funcs[src_protocol][dst_protocol]
316
+ except KeyError:
317
+ return _default_copy_func
318
+
319
+
310
320
  def smart_copy(
311
321
  src_path: PathLike,
312
322
  dst_path: PathLike,
@@ -351,10 +361,8 @@ def smart_copy(
351
361
  src_protocol, _ = SmartPath._extract_protocol(src_path)
352
362
  dst_protocol, _ = SmartPath._extract_protocol(dst_path)
353
363
 
354
- try:
355
- copy_func = _copy_funcs[src_protocol][dst_protocol]
356
- except KeyError:
357
- copy_func = _default_copy_func
364
+ copy_func = _get_copy_func(src_protocol, dst_protocol)
365
+
358
366
  try:
359
367
  copy_func(
360
368
  src_path,
megfile/version.py CHANGED
@@ -1 +1 @@
1
- VERSION = "4.1.6"
1
+ VERSION = "4.1.8"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: megfile
3
- Version: 4.1.6
3
+ Version: 4.1.8
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
@@ -11,21 +11,21 @@ megfile/http_path.py,sha256=ZGug-bTWq8GqEA-R6zIXQmbcOVYvILxEweTXzHGnBuk,13829
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=S8iulho1btVLLvNU-OtcskkbaAC8yNXnBrFNnF3fwS8,93510
14
+ megfile/s3_path.py,sha256=4vKdn5RupvSMYelYznCMDpE1t-87H3iwgzY4iZHWmIE,93519
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=Sae2KJzaU0k_qV_Bk0YifOMq8WsV5qQ2pGInDRF546I,36411
17
+ megfile/smart.py,sha256=Miz3jyLKmwWBja-8GrSzrumpTarPrFPqXaFQJKwrK1Y,36627
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=IhKvX1UU6Hj5y2NPRPLmOC6AwOxQcN87pBebR6XrP7I,19
21
+ megfile/version.py,sha256=Q7vzX4XpnfI8xIxWcYQYkZJUE1GiBtK_NmvaAfIJfC8,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
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=-N75Phx1c8IpZ2hNIMwsHIx6BxMKVVr7N82cpWhs4lQ,9987
28
+ megfile/lib/glob.py,sha256=anr7JjCJz1T0G5hYQkJwV5mCWzlt5YaxGTyyyQB28zA,9663
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.1.6.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
47
- megfile-4.1.6.dist-info/licenses/LICENSE.pyre,sha256=9lf5nT-5ZH25JijpYAequ0bl8E8z5JmZB1qrjiUMp84,1080
48
- megfile-4.1.6.dist-info/METADATA,sha256=_YzyQHnfYQYQRtbqc5__xrF5AtBBdIBDMs0WujErjBk,9595
49
- megfile-4.1.6.dist-info/WHEEL,sha256=ooBFpIzZCPdw3uqIQsOo4qqbA4ZRPxHnOH7peeONza0,91
50
- megfile-4.1.6.dist-info/entry_points.txt,sha256=M6ZWSSv5_5_QtIpZafy3vq7WuOJ_5dSGQQnEZbByt2Q,49
51
- megfile-4.1.6.dist-info/top_level.txt,sha256=i3rMgdU1ZAJekAceojhA-bkm3749PzshtRmLTbeLUPQ,8
52
- megfile-4.1.6.dist-info/RECORD,,
46
+ megfile-4.1.8.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
47
+ megfile-4.1.8.dist-info/licenses/LICENSE.pyre,sha256=9lf5nT-5ZH25JijpYAequ0bl8E8z5JmZB1qrjiUMp84,1080
48
+ megfile-4.1.8.dist-info/METADATA,sha256=tuE4RMIMSYdGykVRvC0SoEGNl6N0xvv5KsNWXk7xhG4,9595
49
+ megfile-4.1.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
50
+ megfile-4.1.8.dist-info/entry_points.txt,sha256=M6ZWSSv5_5_QtIpZafy3vq7WuOJ_5dSGQQnEZbByt2Q,49
51
+ megfile-4.1.8.dist-info/top_level.txt,sha256=i3rMgdU1ZAJekAceojhA-bkm3749PzshtRmLTbeLUPQ,8
52
+ megfile-4.1.8.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.0.1)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5