megfile 3.0.6.post1__py3-none-any.whl → 3.1.0.post1__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.
Files changed (49) hide show
  1. docs/conf.py +67 -0
  2. megfile/cli.py +16 -16
  3. megfile/config.py +37 -6
  4. megfile/errors.py +26 -20
  5. megfile/fs.py +13 -8
  6. megfile/fs_path.py +69 -49
  7. megfile/hdfs.py +13 -8
  8. megfile/hdfs_path.py +49 -41
  9. megfile/http.py +1 -1
  10. megfile/http_path.py +35 -28
  11. megfile/interfaces.py +119 -48
  12. megfile/lib/base_prefetch_reader.py +9 -8
  13. megfile/lib/combine_reader.py +7 -7
  14. megfile/lib/fnmatch.py +2 -2
  15. megfile/lib/glob.py +3 -3
  16. megfile/lib/hdfs_prefetch_reader.py +2 -1
  17. megfile/lib/http_prefetch_reader.py +3 -2
  18. megfile/lib/lazy_handler.py +6 -5
  19. megfile/lib/s3_buffered_writer.py +8 -7
  20. megfile/lib/s3_cached_handler.py +3 -4
  21. megfile/lib/s3_limited_seekable_writer.py +5 -3
  22. megfile/lib/s3_memory_handler.py +10 -6
  23. megfile/lib/s3_pipe_handler.py +1 -1
  24. megfile/lib/s3_prefetch_reader.py +7 -5
  25. megfile/lib/s3_share_cache_reader.py +2 -2
  26. megfile/lib/shadow_handler.py +5 -5
  27. megfile/lib/stdio_handler.py +3 -3
  28. megfile/pathlike.py +156 -170
  29. megfile/s3.py +19 -13
  30. megfile/s3_path.py +98 -83
  31. megfile/sftp.py +25 -16
  32. megfile/sftp_path.py +109 -94
  33. megfile/smart.py +38 -28
  34. megfile/smart_path.py +6 -6
  35. megfile/stdio.py +3 -3
  36. megfile/stdio_path.py +5 -5
  37. megfile/utils/__init__.py +8 -27
  38. megfile/version.py +1 -1
  39. {megfile-3.0.6.post1.dist-info → megfile-3.1.0.post1.dist-info}/METADATA +4 -5
  40. megfile-3.1.0.post1.dist-info/RECORD +55 -0
  41. {megfile-3.0.6.post1.dist-info → megfile-3.1.0.post1.dist-info}/WHEEL +1 -1
  42. megfile-3.1.0.post1.dist-info/top_level.txt +7 -0
  43. scripts/convert_results_to_sarif.py +124 -0
  44. scripts/generate_file.py +268 -0
  45. megfile-3.0.6.post1.dist-info/RECORD +0 -52
  46. megfile-3.0.6.post1.dist-info/top_level.txt +0 -1
  47. {megfile-3.0.6.post1.dist-info → megfile-3.1.0.post1.dist-info}/LICENSE +0 -0
  48. {megfile-3.0.6.post1.dist-info → megfile-3.1.0.post1.dist-info}/LICENSE.pyre +0 -0
  49. {megfile-3.0.6.post1.dist-info → megfile-3.1.0.post1.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,268 @@
1
+ import importlib
2
+ import re
3
+
4
+ ALL_IGNORE_FUNC_LIST = dict(
5
+ s3=[
6
+ "open", "readlink", "iterdir", "is_mount", "is_socket", "is_fifo",
7
+ "is_block_device", "is_char_device", "owner", "absolute", "rmdir",
8
+ "glob", "iglob", "glob_stat", "rename", "cwd", "mkdir", "parts",
9
+ "path_without_protocol", "path_with_protocol"
10
+ ],
11
+ fs=[
12
+ "open", "from_uri", "path_with_protocol", "joinpath", "readlink",
13
+ "iterdir", "chmod", "group", "is_socket", "is_fifo", "is_block_device",
14
+ "is_char_device", "rmdir", "owner", "absolute", "resolve", "cwd",
15
+ "home", "glob", "iglob", "glob_stat", "rename", "parts", "root",
16
+ "anchor", "drive", "replace", "hardlink_to", "mkdir", "utime"
17
+ ],
18
+ http=["open"],
19
+ sftp=[
20
+ "path_without_protocol", "expanduser", "iterdir", "readlink", "cwd",
21
+ "glob", "iglob", "glob_stat", "resolve", "relpath", "utime", "parts"
22
+ ],
23
+ hdfs=[
24
+ "iterdir", "absolute", "rmdir", "glob", "iglob", "glob_stat", "rename",
25
+ "mkdir", "path_without_protocol", "path_with_protocol", "parts"
26
+ ],
27
+ )
28
+
29
+ ALL_IMPORT_LINES = dict(
30
+ s3=[
31
+ "from typing import BinaryIO, Callable, Iterator, List, Optional, Tuple",
32
+ "from megfile.interfaces import Access, FileEntry, PathLike, StatResult",
33
+ ],
34
+ fs=[
35
+ "from typing import BinaryIO, Callable, Iterator, List, Optional, Tuple",
36
+ "from megfile.interfaces import Access, FileEntry, PathLike, StatResult",
37
+ ],
38
+ http=[
39
+ "from megfile.interfaces import PathLike, StatResult",
40
+ ],
41
+ stdio=[
42
+ "from typing import IO, AnyStr, Optional",
43
+ "from megfile.interfaces import PathLike",
44
+ ],
45
+ sftp=[
46
+ "from typing import IO, AnyStr, BinaryIO, Iterator, List, Tuple, Callable, Optional",
47
+ "from megfile.interfaces import FileEntry, PathLike, StatResult",
48
+ ],
49
+ hdfs=[
50
+ "from typing import IO, AnyStr, BinaryIO, Iterator, List, Optional, Tuple",
51
+ "from megfile.interfaces import FileEntry, PathLike, StatResult",
52
+ ],
53
+ )
54
+
55
+ ALL_FUNC_NAME_MAPPING = dict(
56
+ s3=dict(
57
+ is_dir="isdir",
58
+ is_file="isfile",
59
+ load="load_from",
60
+ mkdir="makedirs",
61
+ md5="getmd5",
62
+ symlink_to="symlink",
63
+ is_symlink="islink",
64
+ save="save_as",
65
+ ),
66
+ fs=dict(
67
+ is_dir="isdir",
68
+ is_file="isfile",
69
+ md5="getmd5",
70
+ load="load_from",
71
+ mkdir="makedirs",
72
+ symlink_to="symlink",
73
+ is_symlink="islink",
74
+ is_mount="ismount",
75
+ save="save_as",
76
+ joinpath="path_join",
77
+ is_absolute="isabs",
78
+ replace="move",
79
+ ),
80
+ http=dict(),
81
+ sftp=dict(
82
+ is_dir="isdir",
83
+ is_file="isfile",
84
+ md5="getmd5",
85
+ load="load_from",
86
+ mkdir="makedirs",
87
+ symlink_to="symlink",
88
+ is_symlink="islink",
89
+ save="save_as",
90
+ is_absolute="isabs",
91
+ replace="move",
92
+ ),
93
+ hdfs=dict(
94
+ is_dir="isdir",
95
+ is_file="isfile",
96
+ load="load_from",
97
+ mkdir="makedirs",
98
+ md5="getmd5",
99
+ symlink_to="symlink",
100
+ is_symlink="islink",
101
+ save="save_as",
102
+ ),
103
+ )
104
+ PARAMETER_PATTERN = re.compile(r'\[[^:]*\]')
105
+
106
+
107
+ def get_class_name(current_file_type: str):
108
+ if current_file_type == 'fs':
109
+ return 'FSPath'
110
+ return f'{current_file_type.capitalize()}Path'
111
+
112
+
113
+ def insert_class_method_lines(
114
+ func_params: list, annotation_lines: list, current_file_type: str):
115
+ ignore_func_list = ALL_IGNORE_FUNC_LIST.get(current_file_type, [])
116
+ func_name_mapping = ALL_FUNC_NAME_MAPPING.get(current_file_type, {})
117
+
118
+ real_func_name, func_content_lines = None, []
119
+ if func_params:
120
+ func_first_line = "".join(func_params)
121
+ path_param_name = "path"
122
+ current_params_line = PARAMETER_PATTERN.sub(
123
+ "",
124
+ func_first_line.split("(", maxsplit=1)[1].split(")", maxsplit=1)[0])
125
+ current_params = []
126
+ kwargs_mode = False
127
+ for params_words in current_params_line.split(","):
128
+ if ":" in params_words:
129
+ param = params_words.split(":", maxsplit=1)[0].strip()
130
+ elif "=" in params_words:
131
+ param = params_words.split("=", maxsplit=1)[0].strip()
132
+ else:
133
+ param = params_words.strip()
134
+ if param == '*':
135
+ kwargs_mode = True
136
+ continue
137
+
138
+ if param and param != '**kwargs':
139
+ if 'dst' in param:
140
+ path_param_name = param.replace("dst", "src")
141
+ if kwargs_mode:
142
+ param = f"{param}={param}"
143
+ current_params.append(param)
144
+ func_name = func_first_line.strip().split(
145
+ "def ", maxsplit=1)[1].split(
146
+ "(", maxsplit=1)[0]
147
+ if func_name == 'save':
148
+ func_first_line = func_first_line.replace(
149
+ "self", f"{path_param_name}: PathLike")
150
+ special_order_params = [
151
+ param.strip() for param in func_first_line.split('(', 1)
152
+ [1].split(')', 1)[0].split(',')
153
+ ]
154
+ special_order_params[0], special_order_params[
155
+ 1] = special_order_params[1], special_order_params[0]
156
+ func_first_line = "".join(
157
+ [
158
+ func_first_line.split('(', 1)[0], "(",
159
+ ", ".join(special_order_params), ")",
160
+ func_first_line.split(')', 1)[1]
161
+ ])
162
+ else:
163
+ func_first_line = func_first_line.replace(
164
+ "self", f"{path_param_name}: PathLike")
165
+
166
+ if not func_name.startswith("_") and func_name not in ignore_func_list:
167
+ real_func_name = f"{current_file_type}_{func_name_mapping.get(func_name, func_name)}"
168
+ func_content_lines.append(
169
+ func_first_line.replace(func_name, real_func_name).replace(
170
+ ', **kwargs', ''))
171
+
172
+ insert_log = False
173
+ for annotation_line in annotation_lines:
174
+ if insert_log is False and annotation_line.strip().startswith(
175
+ ":"):
176
+ func_content_lines.append(
177
+ f" :param {path_param_name}: Given path")
178
+ insert_log = True
179
+ func_content_lines.append(annotation_line)
180
+
181
+ class_name = get_class_name(current_file_type)
182
+ if class_name == 'StdioPath':
183
+ func_content_lines.append(
184
+ f" return {class_name}({path_param_name}).{func_name}({', '.join(current_params[1:])}) # pyre-ignore[6]\n\n"
185
+ )
186
+ else:
187
+ func_content_lines.append(
188
+ f" return {class_name}({path_param_name}).{func_name}({', '.join(current_params[1:])})\n\n"
189
+ )
190
+ return real_func_name, func_content_lines
191
+
192
+
193
+ def get_methods_from_path_file(current_file_type: str):
194
+ all_func_list = importlib.import_module(
195
+ f'megfile.{current_file_type}_path').__all__
196
+ methods_content = []
197
+ import_lines = ALL_IMPORT_LINES.get(current_file_type, [])
198
+ import_lines.append(
199
+ f"from megfile.{current_file_type}_path import {', '.join(all_func_list)}"
200
+ )
201
+ with open(f'megfile/{current_file_type}_path.py', 'r') as f:
202
+ class_start = False
203
+ func_start = False
204
+ func_params = []
205
+ annotation_lines = []
206
+ annotation_start = False
207
+ for line in f.readlines():
208
+ if line.strip().startswith(
209
+ f'class {get_class_name(current_file_type)}('):
210
+ class_start = True
211
+ elif class_start is True:
212
+ if line.strip() and not line.startswith(" " * 4):
213
+ break
214
+ elif func_start is True:
215
+ if line.rsplit('#', maxsplit=1)[0].strip().endswith(":"):
216
+ func_start = False
217
+ func_params.append(line.strip())
218
+ elif "'''" in line or '"""' in line:
219
+ if line.count("'''") <= 1 and line.count('"""') <= 1:
220
+ annotation_start = not annotation_start
221
+ annotation_lines.append(line[4:].rstrip())
222
+ elif annotation_start is True:
223
+ annotation_lines.append(line[4:].rstrip())
224
+ elif line.startswith(" def"):
225
+ if line.rsplit('#', maxsplit=1)[0].strip().endswith(":"):
226
+ func_start = False
227
+ else:
228
+ func_start = True
229
+ func_name, func_content_lines = insert_class_method_lines(
230
+ func_params, annotation_lines, current_file_type)
231
+ if func_name:
232
+ all_func_list.append(func_name)
233
+ if func_content_lines:
234
+ methods_content.extend(func_content_lines)
235
+ func_params = [line.strip()]
236
+ annotation_lines = []
237
+ func_name, func_content_lines = insert_class_method_lines(
238
+ func_params, annotation_lines, current_file_type)
239
+ if func_name:
240
+ all_func_list.append(func_name)
241
+ if func_content_lines:
242
+ methods_content.extend(func_content_lines)
243
+ return import_lines, all_func_list, methods_content
244
+
245
+
246
+ def generate_file(current_file_type: str):
247
+ current_class_name = get_class_name(current_file_type)
248
+ import_lines, all_func_list, methods_content = get_methods_from_path_file(
249
+ current_file_type)
250
+ with open(f"megfile/{current_file_type}.py", 'w') as f:
251
+ for line in import_lines:
252
+ f.write('\n')
253
+ f.write(line)
254
+
255
+ f.write("\n\n__all__ = [\n")
256
+ for func_name in all_func_list:
257
+ if func_name != current_class_name and func_name != 'HttpsPath':
258
+ f.write(f" '{func_name}',\n")
259
+ f.write("]\n\n")
260
+
261
+ for line in methods_content:
262
+ f.write('\n')
263
+ f.write(line)
264
+
265
+
266
+ if __name__ == "__main__":
267
+ for t in ['s3', 'fs', 'http', 'stdio', 'sftp', 'hdfs']:
268
+ generate_file(t)
@@ -1,52 +0,0 @@
1
- megfile/__init__.py,sha256=MT8SIXsmEUvtSpd1GHv6e3fFfR1gRnlEdkNNqv3gngo,6534
2
- megfile/cli.py,sha256=vPrFVWVx1iQOzv6QE1BChix5pCpbzkiGlB2S4eBW8gM,22445
3
- megfile/config.py,sha256=YeLuxsFoJz6ZmZq7Pufe_021PeRWs4H6GN-v0MvsV6E,1136
4
- megfile/errors.py,sha256=jVkQAv3XAmAxh2l2gGc5wptNsx61uGCHwX02ugQynns,13733
5
- megfile/fs.py,sha256=xLVSS4VWp2xcA7-vlVPbgJBG6s0zxH3JGaINwd9x57U,11850
6
- megfile/fs_path.py,sha256=2GbJYB4qbRhThWedM7VgbhjaNTKCENYUfsPBFp9JGfU,40651
7
- megfile/hdfs.py,sha256=9kEf6b-TVy6I3B_j5jufODzjNA5ngdTqW_mEForGFas,9200
8
- megfile/hdfs_path.py,sha256=iQGIS81PhV7bl9xAZkV14WjCp7O9Fb9yz12RfL2Z41w,27402
9
- megfile/http.py,sha256=a3oAuARSSaIU8VMx86Mui0N5Vh-EI0AoHnwxRU5DSMU,2032
10
- megfile/http_path.py,sha256=nCMx_8ETZynfDbNOnNkwY8vzHzCnFCx_H33PHVJQlug,16261
11
- megfile/interfaces.py,sha256=h3tWE8hVt5S-HopaMAX6lunPJ97vzhv6jH_2HubcDNc,6219
12
- megfile/pathlike.py,sha256=JhSP_bxRI7bwVGkubVvIkAqSYDcxdJr9h1DfZXEgc-g,29785
13
- megfile/s3.py,sha256=RmfUsmMVUD9-7A_O2d55dHBZ8_QX2FiFV4QAd_a1DZs,12830
14
- megfile/s3_path.py,sha256=S0rsYibPxcLOTOnz3nBS4OmsPcbL23570UsrN4NrJrM,92664
15
- megfile/sftp.py,sha256=dp0x84RYnxEX43NNIHqNZBCd69HgPqVg0EZPKT6vsCg,12978
16
- megfile/sftp_path.py,sha256=B_uOcKBdhZaYKh7mTieY1v-cvAheixrE3UFhA_JF6Z0,53253
17
- megfile/smart.py,sha256=vnm1sgxYShPSMVUl0qbVFnXu7I8NgCLHcxAXyPxXRr8,35967
18
- megfile/smart_path.py,sha256=Y0UFh4J2ccydRY2W-wX2ubaf9zzJx1M2nf-VLBGe4mk,6749
19
- megfile/stdio.py,sha256=yRhlfUA2DHi3bq-9cXsSlbLCnHvS_zvglO2IYYyPsGc,707
20
- megfile/stdio_path.py,sha256=eQulTXUwHvUKA-5PKCGfVNiEPkJhG9YtVhtU58OcmoM,2873
21
- megfile/version.py,sha256=r4nKj4bMHJNHtUJ8_7SBr2SUSvpgIaweKjVUnOyADzg,25
22
- megfile/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
- megfile/lib/base_prefetch_reader.py,sha256=rrHB9FdVX_MKOJD2lGZ00LruTjRY9u0Hj4UdI-CxNO0,13231
24
- megfile/lib/combine_reader.py,sha256=XFSqEY5A5X5Uf7eQ6AXAzrvNteESSXvKNVPktGjo3KY,4546
25
- megfile/lib/compare.py,sha256=yG2fZve_gMg32rQVCdwixBdqgYRsjn-24TqhALQaOrA,2233
26
- megfile/lib/compat.py,sha256=0wt3_atcYhSLCxUj_WuDlQa3E1atjZfwJQ12thiFh5Q,234
27
- megfile/lib/fnmatch.py,sha256=HgdlnEWBsdFUOZqnW_v1kj1jeH_9lMcCqW85pyMu4vM,4054
28
- megfile/lib/glob.py,sha256=7i9dIput9rI9JIPyTZX-JDmFS7IP_THlX1k-35foAfw,9732
29
- megfile/lib/hdfs_prefetch_reader.py,sha256=50oVBNmEB8KRNwHnyDzxpxvwNABWxbOaIjyiTkmcemU,2080
30
- megfile/lib/hdfs_tools.py,sha256=t4GeoBxO0HPahIQDrsK17WBsLZtcfAaNwWfappzZ5q8,442
31
- megfile/lib/http_prefetch_reader.py,sha256=1F94fFY7ZtyP7Bm9Wphu0iLtvOt771rehhouflqVojk,4328
32
- megfile/lib/joinpath.py,sha256=D4Px6-lnDDpYs1LMUHkTIGqMPJQ0oCBGfTzREs373iU,929
33
- megfile/lib/lazy_handler.py,sha256=f1rip2_T57vVo0WRNXve2bAa4LArvVheMfQg1S0vFzg,1915
34
- megfile/lib/s3_buffered_writer.py,sha256=ZvCtaJsGZdFy-8K6EMHFakzu3oIKXnKof-a6nBa6AY4,7017
35
- megfile/lib/s3_cached_handler.py,sha256=xuWiThi6pJtGL_ErSBmcu8rDv1XyXNmEhiFBnRF4NWU,1412
36
- megfile/lib/s3_limited_seekable_writer.py,sha256=14gySEdbS349hpSdUcX5uvRr93HACv7BRZbgIki4b34,6150
37
- megfile/lib/s3_memory_handler.py,sha256=6Tj89xzc8z-FycVggGpjF_8lEbPsqRVB6undZwWsugo,3971
38
- megfile/lib/s3_pipe_handler.py,sha256=hG8sEajO9dv9bLTeXsERxDioHHhzi4t8NC61lSbYk94,3557
39
- megfile/lib/s3_prefetch_reader.py,sha256=iLvPaJGlJHaZ6jcyNPf-8A8URJgoJ0RN0C1YD--6wZ4,4285
40
- megfile/lib/s3_share_cache_reader.py,sha256=jyx6f3LAR05qtf-qq_RTu8wE6wqTrqg4qkwWRSdPGQ4,3600
41
- megfile/lib/shadow_handler.py,sha256=IbFyTw107t-yWH0cGrDjAJX-CS3xeEr77_PTGsnSgk4,2683
42
- megfile/lib/stdio_handler.py,sha256=QDWtcZxz-hzi-rqQUiSlR3NrihX1fjK_Rj9T2mdTFEg,2044
43
- megfile/lib/url.py,sha256=VbQLjo0s4AaV0iSk66BcjI68aUTcN9zBZ5x6-cM4Qvs,103
44
- megfile/utils/__init__.py,sha256=xrBIJcVJTb_yR68ekAyd9u4HQ46s3xgIjUZoH_Lx7hU,9531
45
- megfile/utils/mutex.py,sha256=-2KH3bNovKRd9zvsXq9n3bWM7rQdoG9hO7tUPxVG_Po,2538
46
- megfile-3.0.6.post1.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
47
- megfile-3.0.6.post1.dist-info/LICENSE.pyre,sha256=9lf5nT-5ZH25JijpYAequ0bl8E8z5JmZB1qrjiUMp84,1080
48
- megfile-3.0.6.post1.dist-info/METADATA,sha256=AijH38cyPATFlFh284KHA-c6PWGUF1y3mterInTjark,9093
49
- megfile-3.0.6.post1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
50
- megfile-3.0.6.post1.dist-info/entry_points.txt,sha256=M6ZWSSv5_5_QtIpZafy3vq7WuOJ_5dSGQQnEZbByt2Q,49
51
- megfile-3.0.6.post1.dist-info/top_level.txt,sha256=i3rMgdU1ZAJekAceojhA-bkm3749PzshtRmLTbeLUPQ,8
52
- megfile-3.0.6.post1.dist-info/RECORD,,
@@ -1 +0,0 @@
1
- megfile