megfile 4.1.8__py3-none-any.whl → 4.2.0__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
@@ -70,17 +70,16 @@ def cli(debug, log_level):
70
70
  """
71
71
  options["debug"] = debug
72
72
  options["log_level"] = log_level or ("DEBUG" if debug else "INFO")
73
+ if not debug:
74
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
73
75
  set_log_level(options["log_level"])
74
76
 
75
77
 
76
78
  def safe_cli(): # pragma: no cover
77
- debug = options.get("debug", False)
78
- if not debug:
79
- signal.signal(signal.SIGINT, signal.SIG_DFL)
80
79
  try:
81
80
  cli()
82
81
  except Exception as e:
83
- if debug:
82
+ if options.get("debug", False):
84
83
  raise
85
84
  else:
86
85
  click.echo(f"\n[{type(e).__name__}] {e}", err=True)
megfile/http_path.py CHANGED
@@ -187,11 +187,12 @@ class HttpPath(URIPath):
187
187
  response.close()
188
188
  raise translate_http_error(error, self.path_with_protocol)
189
189
 
190
- content_size = int(response.headers["Content-Length"])
190
+ headers = response.headers
191
+ content_size = int(headers.get("Content-Length", 0))
191
192
  if (
192
- response.headers.get("Accept-Ranges") == "bytes"
193
+ headers.get("Accept-Ranges") == "bytes"
193
194
  and content_size >= block_size * 2
194
- and not response.headers.get("Content-Encoding")
195
+ and not headers.get("Content-Encoding")
195
196
  ):
196
197
  response.close()
197
198
 
megfile/s3_path.py CHANGED
@@ -605,6 +605,8 @@ def _s3_glob_stat_single_path(
605
605
  for content in resp.get("Contents", []):
606
606
  path = s3_path_join(f"{protocol}://", bucket, content["Key"])
607
607
  if not search_dir and pattern.match(path):
608
+ if path.endswith("/"):
609
+ continue
608
610
  yield FileEntry(S3Path(path).name, path, _make_stat(content))
609
611
  dirname = os.path.dirname(path)
610
612
  while dirname not in dirnames and dirname != top_dir:
@@ -1960,6 +1962,7 @@ class S3Path(URIPath):
1960
1962
  )
1961
1963
 
1962
1964
  prefix = _become_prefix(key)
1965
+ protocol = self._protocol_with_profile
1963
1966
  client = self._client
1964
1967
 
1965
1968
  def suppress_error_callback(e):
@@ -1970,13 +1973,13 @@ class S3Path(URIPath):
1970
1973
  with raise_s3_error(self.path_with_protocol, suppress_error_callback):
1971
1974
  for resp in _list_objects_recursive(client, bucket, prefix):
1972
1975
  for content in resp.get("Contents", []):
1973
- full_path = s3_path_join(
1974
- f"{self._protocol_with_profile}://", bucket, content["Key"]
1975
- )
1976
+ if content["Key"].endswith("/"):
1977
+ continue
1978
+ path = s3_path_join(f"{protocol}://", bucket, content["Key"])
1976
1979
 
1977
1980
  if followlinks:
1978
1981
  try:
1979
- origin_path = self.from_path(full_path).readlink()
1982
+ origin_path = self.from_path(path).readlink()
1980
1983
  yield FileEntry(
1981
1984
  origin_path.name,
1982
1985
  origin_path.path_with_protocol,
@@ -1986,9 +1989,7 @@ class S3Path(URIPath):
1986
1989
  except S3NotALinkError:
1987
1990
  pass
1988
1991
 
1989
- yield FileEntry(
1990
- S3Path(full_path).name, full_path, _make_stat(content)
1991
- )
1992
+ yield FileEntry(S3Path(path).name, path, _make_stat(content))
1992
1993
 
1993
1994
  return _create_missing_ok_generator(
1994
1995
  create_generator(),
@@ -2016,17 +2017,15 @@ class S3Path(URIPath):
2016
2017
  # we need to wrap the iterator in another function
2017
2018
  def create_generator() -> Iterator[FileEntry]:
2018
2019
  prefix = _become_prefix(key)
2020
+ protocol = self._protocol_with_profile
2019
2021
  client = self._client
2020
2022
 
2021
- def generate_s3_path(protocol: str, bucket: str, key: str) -> str:
2022
- return "%s://%s/%s" % (protocol, bucket, key)
2023
-
2024
2023
  if not bucket and not key: # list buckets
2025
2024
  response = client.list_buckets()
2026
2025
  for content in response["Buckets"]:
2027
2026
  yield FileEntry(
2028
2027
  content["Name"],
2029
- f"{self._protocol_with_profile}://{content['Name']}",
2028
+ f"{protocol}://{content['Name']}",
2030
2029
  StatResult(
2031
2030
  ctime=content["CreationDate"].timestamp(),
2032
2031
  isdir=True,
@@ -2039,21 +2038,17 @@ class S3Path(URIPath):
2039
2038
  for common_prefix in resp.get("CommonPrefixes", []):
2040
2039
  yield FileEntry(
2041
2040
  common_prefix["Prefix"][len(prefix) : -1],
2042
- generate_s3_path(
2043
- self._protocol_with_profile,
2044
- bucket,
2045
- common_prefix["Prefix"],
2046
- ),
2041
+ f"{protocol}://{bucket}/{common_prefix['Prefix']}",
2047
2042
  StatResult(isdir=True, extra=common_prefix),
2048
2043
  )
2049
2044
  for content in resp.get("Contents", []):
2050
- src_url = generate_s3_path(
2051
- self._protocol_with_profile, bucket, content["Key"]
2052
- )
2045
+ if content["Key"].endswith("/"):
2046
+ continue
2047
+ path = f"{protocol}://{bucket}/{content['Key']}"
2053
2048
  yield FileEntry( # pytype: disable=wrong-arg-types
2054
2049
  content["Key"][len(prefix) :],
2055
- src_url,
2056
- _make_stat_without_metadata(content, self.from_path(src_url)),
2050
+ path,
2051
+ _make_stat_without_metadata(content, self.from_path(path)),
2057
2052
  )
2058
2053
 
2059
2054
  def missing_ok_generator():
@@ -2220,6 +2215,8 @@ class S3Path(URIPath):
2220
2215
  for common_prefix in resp.get("CommonPrefixes", []):
2221
2216
  dirs.append(common_prefix["Prefix"][:-1])
2222
2217
  for content in resp.get("Contents", []):
2218
+ if content["Key"].endswith("/"):
2219
+ continue
2223
2220
  files.append(content["Key"])
2224
2221
 
2225
2222
  dirs = sorted(dirs)
megfile/version.py CHANGED
@@ -1 +1 @@
1
- VERSION = "4.1.8"
1
+ VERSION = "4.2.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: megfile
3
- Version: 4.1.8
3
+ Version: 4.2.0
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=iwwlwVNu_yXgqnaURPHqGPrx1WeReqN0zi9C4rqK5Ag,29178
2
+ megfile/cli.py,sha256=VxY0__M19Ti_S7ZIozp9l0FxvdLwdd6eQL-wfpYOi_0,29160
3
3
  megfile/config.py,sha256=2MMj5QkhlDJQFZRbCQL2c9iDdeMAVctiaPszRBkg5vM,3988
4
4
  megfile/errors.py,sha256=aw4BX-pU1uj0-dNc6Tq-IeSwK_PWJNi2ZL5ZcRSo7aQ,14739
5
5
  megfile/fs.py,sha256=KMEqAE35alpcxiy6du5nPFYcaorhUM_kPJMah3q76ng,19160
@@ -7,18 +7,18 @@ megfile/fs_path.py,sha256=Hozl9LAJ8EMuSWBSZXGj2GNmPZ1sJp9PZs-7hPrLgm8,39341
7
7
  megfile/hdfs.py,sha256=owXr4d3j1frCvlbhmhENcSBnKKDky5cJZzWLOF4ZJMo,13251
8
8
  megfile/hdfs_path.py,sha256=OmUe3vA3Qoxnqtcq0Rs3ygBvzAtqUz3fGo8iP5sWneE,26058
9
9
  megfile/http.py,sha256=1nuGe-JbnwMFyV3s35CJxByED3uoRoS9y8Y8cSGP9Kw,3865
10
- megfile/http_path.py,sha256=ZGug-bTWq8GqEA-R6zIXQmbcOVYvILxEweTXzHGnBuk,13829
10
+ 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=4vKdn5RupvSMYelYznCMDpE1t-87H3iwgzY4iZHWmIE,93519
14
+ megfile/s3_path.py,sha256=nA1FXFwfhSvZN8W0mF2PKGbnaTDouZfp6anUZkxvOBc,93449
15
15
  megfile/sftp.py,sha256=uBcLQs-j6Q-q-sWAdd-pgi5Qmb_kq7boJM-0sCfcNO0,26540
16
16
  megfile/sftp_path.py,sha256=CgirHWmNdXdqyIL9ufmlaMpwFhlkQVZhqmfvjUaj7qU,43845
17
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=Q7vzX4XpnfI8xIxWcYQYkZJUE1GiBtK_NmvaAfIJfC8,19
21
+ megfile/version.py,sha256=nmN7kc0bNHgtVq4jv4MJKEo-L3X7QgGHAv_z6zkMVSQ,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
@@ -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.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,,
46
+ megfile-4.2.0.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
47
+ megfile-4.2.0.dist-info/licenses/LICENSE.pyre,sha256=9lf5nT-5ZH25JijpYAequ0bl8E8z5JmZB1qrjiUMp84,1080
48
+ megfile-4.2.0.dist-info/METADATA,sha256=0IuIzy3B0sO0YhPrMdEK5kCkK16K1ZCX6w3vZO-SlB4,9595
49
+ megfile-4.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
50
+ megfile-4.2.0.dist-info/entry_points.txt,sha256=M6ZWSSv5_5_QtIpZafy3vq7WuOJ_5dSGQQnEZbByt2Q,49
51
+ megfile-4.2.0.dist-info/top_level.txt,sha256=i3rMgdU1ZAJekAceojhA-bkm3749PzshtRmLTbeLUPQ,8
52
+ megfile-4.2.0.dist-info/RECORD,,