micropython-stubber 1.23.2__py3-none-any.whl → 1.23.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.
- {micropython_stubber-1.23.2.dist-info → micropython_stubber-1.23.3.dist-info}/METADATA +3 -3
- {micropython_stubber-1.23.2.dist-info → micropython_stubber-1.23.3.dist-info}/RECORD +25 -25
- mpflash/mpflash/basicgit.py +27 -7
- mpflash/mpflash/common.py +2 -5
- mpflash/mpflash/mpboard_id/store.py +8 -3
- mpflash/mpflash/mpremoteboard/mpy_fw_info.py +27 -16
- mpflash/poetry.lock +576 -488
- mpflash/pyproject.toml +1 -1
- stubber/__init__.py +1 -1
- stubber/board/createstubs.py +17 -35
- stubber/board/createstubs_db.py +7 -8
- stubber/board/createstubs_db_min.py +116 -117
- stubber/board/createstubs_db_mpy.mpy +0 -0
- stubber/board/createstubs_mem.py +7 -8
- stubber/board/createstubs_mem_min.py +104 -105
- stubber/board/createstubs_mem_mpy.mpy +0 -0
- stubber/board/createstubs_min.py +116 -117
- stubber/board/createstubs_mpy.mpy +0 -0
- stubber/codemod/enrich.py +0 -6
- stubber/publish/merge_docstubs.py +4 -8
- stubber/publish/stubpackage.py +4 -8
- stubber/rst/lookup.py +0 -2
- {micropython_stubber-1.23.2.dist-info → micropython_stubber-1.23.3.dist-info}/LICENSE +0 -0
- {micropython_stubber-1.23.2.dist-info → micropython_stubber-1.23.3.dist-info}/WHEEL +0 -0
- {micropython_stubber-1.23.2.dist-info → micropython_stubber-1.23.3.dist-info}/entry_points.txt +0 -0
mpflash/pyproject.toml
CHANGED
stubber/__init__.py
CHANGED
stubber/board/createstubs.py
CHANGED
@@ -24,8 +24,7 @@ try:
|
|
24
24
|
except ImportError:
|
25
25
|
from ucollections import OrderedDict # type: ignore
|
26
26
|
|
27
|
-
__version__ = "v1.23.
|
28
|
-
version_str = __version__.rsplit(".", 1)[0]
|
27
|
+
__version__ = "v1.23.3"
|
29
28
|
ENOENT = 2
|
30
29
|
_MAX_CLASS_LEVEL = 2 # Max class nesting
|
31
30
|
LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
|
@@ -153,11 +152,7 @@ class Stubber:
|
|
153
152
|
order = 4
|
154
153
|
_result.append((name, repr(val), repr(type(val)), val, order))
|
155
154
|
except AttributeError as e:
|
156
|
-
_errors.append(
|
157
|
-
"Couldn't get attribute '{}' from object '{}', Err: {}".format(
|
158
|
-
name, item_instance, e
|
159
|
-
)
|
160
|
-
)
|
155
|
+
_errors.append("Couldn't get attribute '{}' from object '{}', Err: {}".format(name, item_instance, e))
|
161
156
|
except MemoryError as e:
|
162
157
|
print("MemoryError: {}".format(e))
|
163
158
|
sleep(1)
|
@@ -223,9 +218,7 @@ class Stubber:
|
|
223
218
|
try:
|
224
219
|
new_module = __import__(module_name, None, None, ("*"))
|
225
220
|
m1 = gc.mem_free() # type: ignore
|
226
|
-
log.info(
|
227
|
-
"Stub module: {:<25} to file: {:<70} mem:{:>5}".format(module_name, fname, m1)
|
228
|
-
)
|
221
|
+
log.info("Stub module: {:<25} to file: {:<70} mem:{:>5}".format(module_name, fname, m1))
|
229
222
|
|
230
223
|
except ImportError:
|
231
224
|
# log.debug("Skip module: {:<25} {:<79}".format(module_name, "Module not found."))
|
@@ -236,7 +229,7 @@ class Stubber:
|
|
236
229
|
with open(file_name, "w") as fp:
|
237
230
|
info_ = str(self.info).replace("OrderedDict(", "").replace("})", "}")
|
238
231
|
s = '"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(
|
239
|
-
module_name, self._fwid, info_,
|
232
|
+
module_name, self._fwid, info_, __version__
|
240
233
|
)
|
241
234
|
fp.write(s)
|
242
235
|
fp.write(
|
@@ -256,9 +249,7 @@ class Stubber:
|
|
256
249
|
gc.collect()
|
257
250
|
return True
|
258
251
|
|
259
|
-
def write_object_stub(
|
260
|
-
self, fp, object_expr: object, obj_name: str, indent: str, in_class: int = 0
|
261
|
-
):
|
252
|
+
def write_object_stub(self, fp, object_expr: object, obj_name: str, indent: str, in_class: int = 0):
|
262
253
|
"Write a module/object stub to an open file. Can be called recursive."
|
263
254
|
gc.collect()
|
264
255
|
if object_expr in self.problematic:
|
@@ -334,13 +325,11 @@ class Stubber:
|
|
334
325
|
first = "self, "
|
335
326
|
# class method - add function decoration
|
336
327
|
if "bound_method" in item_type_txt or "bound_method" in item_repr:
|
337
|
-
s = "{}@classmethod\n".format(
|
338
|
-
indent
|
339
|
-
) + "{}def {}(cls, *args, **kwargs) -> {}:\n".format(indent, item_name, ret)
|
340
|
-
else:
|
341
|
-
s = "{}def {}({}*args, **kwargs) -> {}:\n".format(
|
342
|
-
indent, item_name, first, ret
|
328
|
+
s = "{}@classmethod\n".format(indent) + "{}def {}(cls, *args, **kwargs) -> {}:\n".format(
|
329
|
+
indent, item_name, ret
|
343
330
|
)
|
331
|
+
else:
|
332
|
+
s = "{}def {}({}*args, **kwargs) -> {}:\n".format(indent, item_name, first, ret)
|
344
333
|
s += indent + " ...\n\n"
|
345
334
|
fp.write(s)
|
346
335
|
# log.debug("\n" + s)
|
@@ -369,9 +358,7 @@ class Stubber:
|
|
369
358
|
# use these types for the attribute
|
370
359
|
if t == "generator":
|
371
360
|
t = "Generator"
|
372
|
-
s = "{0}{1}: {2} ## = {4}\n".format(
|
373
|
-
indent, item_name, t, item_type_txt, item_repr
|
374
|
-
)
|
361
|
+
s = "{0}{1}: {2} ## = {4}\n".format(indent, item_name, t, item_type_txt, item_repr)
|
375
362
|
else:
|
376
363
|
# Requires Python 3.6 syntax, which is OK for the stubs/pyi
|
377
364
|
t = "Incomplete"
|
@@ -379,9 +366,7 @@ class Stubber:
|
|
379
366
|
item_repr = item_repr.split(" at ")[0] + " at ...>"
|
380
367
|
if " at " in item_repr:
|
381
368
|
item_repr = item_repr.split(" at ")[0] + " at ...>"
|
382
|
-
s = "{0}{1}: {2} ## {3} = {4}\n".format(
|
383
|
-
indent, item_name, t, item_type_txt, item_repr
|
384
|
-
)
|
369
|
+
s = "{0}{1}: {2} ## {3} = {4}\n".format(indent, item_name, t, item_type_txt, item_repr)
|
385
370
|
fp.write(s)
|
386
371
|
# log.debug("\n" + s)
|
387
372
|
else:
|
@@ -444,7 +429,7 @@ class Stubber:
|
|
444
429
|
f.write("{")
|
445
430
|
f.write(dumps({"firmware": self.info})[1:-1])
|
446
431
|
f.write(",\n")
|
447
|
-
f.write(dumps({"stubber": {"version":
|
432
|
+
f.write(dumps({"stubber": {"version": __version__}, "stubtype": "firmware"})[1:-1])
|
448
433
|
f.write(",\n")
|
449
434
|
f.write('"modules" :[\n')
|
450
435
|
|
@@ -464,9 +449,7 @@ class Stubber:
|
|
464
449
|
f.write(",\n")
|
465
450
|
else:
|
466
451
|
self._json_first = False
|
467
|
-
line = '{{"module": "{}", "file": "{}"}}'.format(
|
468
|
-
module_name, stub_file.replace("\\", "/")
|
469
|
-
)
|
452
|
+
line = '{{"module": "{}", "file": "{}"}}'.format(module_name, stub_file.replace("\\", "/"))
|
470
453
|
f.write(line)
|
471
454
|
|
472
455
|
except OSError:
|
@@ -505,7 +488,7 @@ def ensure_folder(path: str):
|
|
505
488
|
|
506
489
|
def _build(s):
|
507
490
|
# extract build from sys.version or os.uname().version if available
|
508
|
-
# sys.version: 'MicroPython v1.23.
|
491
|
+
# sys.version: 'MicroPython v1.23.3-preview.6.g3d0b6276f'
|
509
492
|
# sys.implementation.version: 'v1.13-103-gb137d064e'
|
510
493
|
if not s:
|
511
494
|
return ""
|
@@ -612,11 +595,10 @@ def _info(): # type:() -> dict[str, str]
|
|
612
595
|
if (
|
613
596
|
info["version"]
|
614
597
|
and info["version"].endswith(".0")
|
615
|
-
and info["version"]
|
616
|
-
>= "1.10.0" # versions from 1.10.0 to 1.23.2 do not have a micro .0
|
598
|
+
and info["version"] >= "1.10.0" # versions from 1.10.0 to 1.23.3 do not have a micro .0
|
617
599
|
and info["version"] <= "1.19.9"
|
618
600
|
):
|
619
|
-
# versions from 1.10.0 to 1.23.
|
601
|
+
# versions from 1.10.0 to 1.23.3 do not have a micro .0
|
620
602
|
info["version"] = info["version"][:-2]
|
621
603
|
|
622
604
|
# spell-checker: disable
|
@@ -675,7 +657,7 @@ def get_root() -> str: # sourcery skip: use-assigned-variable
|
|
675
657
|
# unix port
|
676
658
|
c = "."
|
677
659
|
r = c
|
678
|
-
for r in [
|
660
|
+
for r in ["/sd", "/flash", "/", c, "."]:
|
679
661
|
try:
|
680
662
|
_ = os.stat(r)
|
681
663
|
break
|
stubber/board/createstubs_db.py
CHANGED
@@ -18,7 +18,7 @@ Create stubs for (all) modules on a MicroPython board.
|
|
18
18
|
- cross compilation, using mpy-cross, to avoid the compilation step on the micropython device
|
19
19
|
|
20
20
|
|
21
|
-
This variant was generated from createstubs.py by micropython-stubber v1.23.
|
21
|
+
This variant was generated from createstubs.py by micropython-stubber v1.23.3
|
22
22
|
"""
|
23
23
|
|
24
24
|
# Copyright (c) 2019-2024 Jos Verlinde
|
@@ -43,8 +43,7 @@ try:
|
|
43
43
|
except ImportError:
|
44
44
|
from ucollections import OrderedDict # type: ignore
|
45
45
|
|
46
|
-
__version__ = "v1.23.
|
47
|
-
version_str = __version__.rsplit(".", 1)[0]
|
46
|
+
__version__ = "v1.23.3"
|
48
47
|
ENOENT = 2
|
49
48
|
_MAX_CLASS_LEVEL = 2 # Max class nesting
|
50
49
|
LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
|
@@ -248,7 +247,7 @@ class Stubber:
|
|
248
247
|
ensure_folder(file_name)
|
249
248
|
with open(file_name, "w") as fp:
|
250
249
|
info_ = str(self.info).replace("OrderedDict(", "").replace("})", "}")
|
251
|
-
s = '"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(module_name, self._fwid, info_,
|
250
|
+
s = '"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(module_name, self._fwid, info_, __version__)
|
252
251
|
fp.write(s)
|
253
252
|
fp.write("from __future__ import annotations\nfrom typing import Any, Generator\nfrom _typeshed import Incomplete\n\n")
|
254
253
|
self.write_object_stub(fp, new_module, module_name, "")
|
@@ -443,7 +442,7 @@ class Stubber:
|
|
443
442
|
f.write("{")
|
444
443
|
f.write(dumps({"firmware": self.info})[1:-1])
|
445
444
|
f.write(",\n")
|
446
|
-
f.write(dumps({"stubber": {"version":
|
445
|
+
f.write(dumps({"stubber": {"version": __version__}, "stubtype": "firmware"})[1:-1])
|
447
446
|
f.write(",\n")
|
448
447
|
f.write('"modules" :[\n')
|
449
448
|
|
@@ -502,7 +501,7 @@ def ensure_folder(path: str):
|
|
502
501
|
|
503
502
|
def _build(s):
|
504
503
|
# extract build from sys.version or os.uname().version if available
|
505
|
-
# sys.version: 'MicroPython v1.23.
|
504
|
+
# sys.version: 'MicroPython v1.23.3-preview.6.g3d0b6276f'
|
506
505
|
# sys.implementation.version: 'v1.13-103-gb137d064e'
|
507
506
|
if not s:
|
508
507
|
return ""
|
@@ -607,10 +606,10 @@ def _info(): # type:() -> dict[str, str]
|
|
607
606
|
if (
|
608
607
|
info["version"]
|
609
608
|
and info["version"].endswith(".0")
|
610
|
-
and info["version"] >= "1.10.0" # versions from 1.10.0 to 1.23.
|
609
|
+
and info["version"] >= "1.10.0" # versions from 1.10.0 to 1.23.3 do not have a micro .0
|
611
610
|
and info["version"] <= "1.19.9"
|
612
611
|
):
|
613
|
-
# versions from 1.10.0 to 1.23.
|
612
|
+
# versions from 1.10.0 to 1.23.3 do not have a micro .0
|
614
613
|
info["version"] = info["version"][:-2]
|
615
614
|
|
616
615
|
# spell-checker: disable
|
@@ -1,33 +1,33 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
1
|
+
A2='No report file'
|
2
|
+
A1='Failed to create the report.'
|
3
|
+
A0='method'
|
4
|
+
z='function'
|
5
|
+
y='bool'
|
6
|
+
x='str'
|
7
|
+
w='float'
|
8
|
+
v='int'
|
9
|
+
u='micropython'
|
10
|
+
t='stubber'
|
11
|
+
s=Exception
|
12
|
+
r=KeyError
|
13
|
+
q=sorted
|
14
|
+
p=MemoryError
|
15
|
+
o=NotImplementedError
|
16
|
+
k=',\n'
|
17
|
+
j='modules.json'
|
18
|
+
i='{}/{}'
|
19
|
+
h='w'
|
20
|
+
g='dict'
|
21
|
+
f='list'
|
22
|
+
e='tuple'
|
23
|
+
d=TypeError
|
24
|
+
c=str
|
25
|
+
b=repr
|
26
|
+
W='-preview'
|
27
|
+
V='-'
|
28
|
+
U='board'
|
29
|
+
T=IndexError
|
30
|
+
S=print
|
31
31
|
R=True
|
32
32
|
Q='family'
|
33
33
|
P=len
|
@@ -49,15 +49,14 @@ try:from ujson import dumps
|
|
49
49
|
except:from json import dumps
|
50
50
|
try:from machine import reset
|
51
51
|
except O:pass
|
52
|
-
try:from collections import OrderedDict as
|
53
|
-
except O:from ucollections import OrderedDict as
|
54
|
-
__version__='v1.23.
|
55
|
-
|
52
|
+
try:from collections import OrderedDict as l
|
53
|
+
except O:from ucollections import OrderedDict as l
|
54
|
+
__version__='v1.23.3'
|
55
|
+
A3=2
|
56
56
|
A4=2
|
57
|
-
A5=
|
58
|
-
A6=['lib','/lib','/sd/lib','/flash/lib',J]
|
57
|
+
A5=['lib','/lib','/sd/lib','/flash/lib',J]
|
59
58
|
class L:
|
60
|
-
INFO=20;WARNING=30;ERROR=40;level=INFO;prnt=
|
59
|
+
INFO=20;WARNING=30;ERROR=40;level=INFO;prnt=S
|
61
60
|
@staticmethod
|
62
61
|
def getLogger(name):return L()
|
63
62
|
@classmethod
|
@@ -68,24 +67,24 @@ class L:
|
|
68
67
|
if A.level<=L.WARNING:A.prnt('WARN :',msg)
|
69
68
|
def error(A,msg):
|
70
69
|
if A.level<=L.ERROR:A.prnt('ERROR :',msg)
|
71
|
-
A=L.getLogger(
|
70
|
+
A=L.getLogger(t)
|
72
71
|
L.basicConfig(level=L.INFO)
|
73
72
|
class Stubber:
|
74
73
|
def __init__(B,path=E,firmware_id=E):
|
75
74
|
C=firmware_id
|
76
75
|
try:
|
77
|
-
if os.uname().release=='1.13.0'and os.uname().version<'v1.13-103':raise
|
76
|
+
if os.uname().release=='1.13.0'and os.uname().version<'v1.13-103':raise o('MicroPython 1.13.0 cannot be stubbed')
|
78
77
|
except I:pass
|
79
|
-
B.info=_info();A.info('Port: {}'.format(B.info[K]));A.info('Board: {}'.format(B.info[
|
78
|
+
B.info=_info();A.info('Port: {}'.format(B.info[K]));A.info('Board: {}'.format(B.info[U]));F.collect()
|
80
79
|
if C:B._fwid=C.lower()
|
81
|
-
elif B.info[Q]==
|
80
|
+
elif B.info[Q]==u:B._fwid='{family}-v{version}-{port}-{board}'.format(**B.info).rstrip(V)
|
82
81
|
else:B._fwid='{family}-v{version}-{port}'.format(**B.info)
|
83
82
|
B._start_free=F.mem_free()
|
84
83
|
if path:
|
85
84
|
if path.endswith(G):path=path[:-1]
|
86
85
|
else:path=get_root()
|
87
86
|
B.path='{}/stubs/{}'.format(path,B.flat_fwid).replace('//',G)
|
88
|
-
try:
|
87
|
+
try:X(path+G)
|
89
88
|
except D:A.error('error creating stub folder {}'.format(path))
|
90
89
|
B.problematic=['upip','upysh','webrepl_setup','http_client','http_client_ssl','http_server','http_server_ssl'];B.excluded=['webrepl','_webrepl','port_diag','example_sub_led.py','example_pub_button.py'];B.modules=[];B._json_name=E;B._json_first=H
|
91
90
|
def get_obj_attributes(L,item_instance):
|
@@ -94,17 +93,17 @@ class Stubber:
|
|
94
93
|
if A.startswith('__')and not A in L.modules:continue
|
95
94
|
try:
|
96
95
|
D=getattr(H,A)
|
97
|
-
try:E=
|
98
|
-
except
|
99
|
-
if E in{w,x,y,
|
100
|
-
elif E in{A0
|
96
|
+
try:E=b(type(D)).split("'")[1]
|
97
|
+
except T:E=B
|
98
|
+
if E in{v,w,x,y,e,f,g}:G=1
|
99
|
+
elif E in{z,A0}:G=2
|
101
100
|
elif E in'class':G=3
|
102
101
|
else:G=4
|
103
|
-
C.append((A,
|
102
|
+
C.append((A,b(D),b(type(D)),D,G))
|
104
103
|
except I as J:K.append("Couldn't get attribute '{}' from object '{}', Err: {}".format(A,H,J))
|
105
|
-
except
|
106
|
-
C=
|
107
|
-
def add_modules(A,modules):A.modules=
|
104
|
+
except p as J:S('MemoryError: {}'.format(J));sleep(1);reset()
|
105
|
+
C=q([A for A in C if not A[0].startswith('__')],key=lambda x:x[4]);F.collect();return C,K
|
106
|
+
def add_modules(A,modules):A.modules=q(set(A.modules)|set(modules))
|
108
107
|
def create_all_stubs(B):
|
109
108
|
A.info('Start micropython-stubber {} on {}'.format(__version__,B._fwid));B.report_start();F.collect()
|
110
109
|
for C in B.modules:B.create_one_stub(C)
|
@@ -125,12 +124,12 @@ class Stubber:
|
|
125
124
|
N=E
|
126
125
|
try:N=__import__(C,E,E,'*');Q=F.mem_free();A.info('Stub module: {:<25} to file: {:<70} mem:{:>5}'.format(C,L,Q))
|
127
126
|
except O:return H
|
128
|
-
|
129
|
-
with M(I,
|
127
|
+
X(I)
|
128
|
+
with M(I,h)as P:S=c(K.info).replace('OrderedDict(',B).replace('})','}');T='"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(C,K._fwid,S,__version__);P.write(T);P.write('from __future__ import annotations\nfrom typing import Any, Generator\nfrom _typeshed import Incomplete\n\n');K.write_object_stub(P,N,C,B)
|
130
129
|
K.report_add(C,I)
|
131
130
|
if C not in{'os','sys','logging','gc'}:
|
132
131
|
try:del N
|
133
|
-
except(D,
|
132
|
+
except(D,r):A.warning('could not del new_module')
|
134
133
|
F.collect();return R
|
135
134
|
def write_object_stub(L,fp,object_expr,obj_name,indent,in_class=0):
|
136
135
|
Z=' at ...>';Y='generator';X='{0}{1}: {3} = {2}\n';W='bound_method';V='Incomplete';O=in_class;N='Exception';M=object_expr;K=' at ';J=fp;D=indent;F.collect()
|
@@ -140,13 +139,13 @@ class Stubber:
|
|
140
139
|
for(E,H,I,b,d)in a:
|
141
140
|
if E in['classmethod','staticmethod','BaseException',N]:continue
|
142
141
|
if E[0].isdigit():A.warning('NameError: invalid name {}'.format(E));continue
|
143
|
-
if I=="<class 'type'>"and P(D)<=
|
142
|
+
if I=="<class 'type'>"and P(D)<=A4*4:
|
144
143
|
R=B;S=E.endswith(N)or E.endswith('Error')or E in['KeyboardInterrupt','StopIteration','SystemExit']
|
145
144
|
if S:R=N
|
146
145
|
C='\n{}class {}({}):\n'.format(D,E,R)
|
147
146
|
if S:C+=D+' ...\n';J.write(C);continue
|
148
147
|
J.write(C);L.write_object_stub(J,b,'{0}.{1}'.format(obj_name,E),D+' ',O+1);C=D+' def __init__(self, *argv, **kwargs) -> None:\n';C+=D+' ...\n\n';J.write(C)
|
149
|
-
elif any(A in I for A in[
|
148
|
+
elif any(A in I for A in[A0,z,'closure']):
|
150
149
|
T=V;U=B
|
151
150
|
if O>0:U='self, '
|
152
151
|
if W in I or W in H:C='{}@classmethod\n'.format(D)+'{}def {}(cls, *args, **kwargs) -> {}:\n'.format(D,E,T)
|
@@ -155,8 +154,8 @@ class Stubber:
|
|
155
154
|
elif I=="<class 'module'>":0
|
156
155
|
elif I.startswith("<class '"):
|
157
156
|
G=I[8:-2];C=B
|
158
|
-
if G in(
|
159
|
-
elif G in(
|
157
|
+
if G in(x,v,w,y,'bytearray','bytes'):C=X.format(D,E,H,G)
|
158
|
+
elif G in(g,f,e):c={g:'{}',f:'[]',e:'()'};C=X.format(D,E,c[G],G)
|
160
159
|
elif G in('object','set','frozenset','Pin',Y):
|
161
160
|
if G==Y:G='Generator'
|
162
161
|
C='{0}{1}: {2} ## = {4}\n'.format(D,E,G,I,H)
|
@@ -178,29 +177,29 @@ class Stubber:
|
|
178
177
|
try:os.stat(path);F=os.listdir(path)
|
179
178
|
except(D,I):return
|
180
179
|
for G in F:
|
181
|
-
B=
|
180
|
+
B=i.format(path,G)
|
182
181
|
try:os.remove(B)
|
183
182
|
except D:
|
184
183
|
try:C.clean(B);os.rmdir(B)
|
185
184
|
except D:pass
|
186
|
-
def report_start(B,filename=
|
187
|
-
H='firmware';B._json_name=
|
185
|
+
def report_start(B,filename=j):
|
186
|
+
H='firmware';B._json_name=i.format(B.path,filename);B._json_first=R;X(B._json_name);A.info('Report file: {}'.format(B._json_name));F.collect()
|
188
187
|
try:
|
189
|
-
with M(B._json_name,
|
190
|
-
except D as I:A.error(
|
188
|
+
with M(B._json_name,h)as G:G.write('{');G.write(dumps({H:B.info})[1:-1]);G.write(k);G.write(dumps({t:{C:__version__},'stubtype':H})[1:-1]);G.write(k);G.write('"modules" :[\n')
|
189
|
+
except D as I:A.error(A1);B._json_name=E;raise I
|
191
190
|
def report_add(B,module_name,stub_file):
|
192
|
-
if not B._json_name:raise
|
191
|
+
if not B._json_name:raise s(A2)
|
193
192
|
try:
|
194
193
|
with M(B._json_name,'a')as C:
|
195
|
-
if not B._json_first:C.write(
|
194
|
+
if not B._json_first:C.write(k)
|
196
195
|
else:B._json_first=H
|
197
196
|
E='{{"module": "{}", "file": "{}"}}'.format(module_name,stub_file.replace('\\',G));C.write(E)
|
198
|
-
except D:A.error(
|
197
|
+
except D:A.error(A1)
|
199
198
|
def report_end(B):
|
200
|
-
if not B._json_name:raise
|
199
|
+
if not B._json_name:raise s(A2)
|
201
200
|
with M(B._json_name,'a')as C:C.write('\n]}')
|
202
201
|
A.info('Path: {}'.format(B.path))
|
203
|
-
def
|
202
|
+
def X(path):
|
204
203
|
B=E=0
|
205
204
|
while B!=-1:
|
206
205
|
B=path.find(G,E)
|
@@ -208,57 +207,57 @@ def Y(path):
|
|
208
207
|
C=path[0]if B==0 else path[:B]
|
209
208
|
try:I=os.stat(C)
|
210
209
|
except D as F:
|
211
|
-
if F.args[0]==
|
210
|
+
if F.args[0]==A3:
|
212
211
|
try:os.mkdir(C)
|
213
212
|
except D as H:A.error('failed to create folder {}'.format(C));raise H
|
214
213
|
E=B+1
|
215
|
-
def
|
214
|
+
def Y(s):
|
216
215
|
C=' on '
|
217
216
|
if not s:return B
|
218
217
|
s=s.split(C,1)[0]if C in s else s
|
219
218
|
if s.startswith('v'):
|
220
|
-
if not
|
221
|
-
A=s.split(
|
222
|
-
if not
|
223
|
-
A=s.split(
|
219
|
+
if not V in s:return B
|
220
|
+
A=s.split(V)[1];return A
|
221
|
+
if not W in s:return B
|
222
|
+
A=s.split(W)[1].split(J)[1];return A
|
224
223
|
def _info():
|
225
|
-
|
224
|
+
a='ev3-pybricks';Z='pycom';X='pycopy';V='unix';S='win32';R='arch';P='cpu';M='ver';F='mpy';D='build'
|
226
225
|
try:H=sys.implementation[0]
|
227
|
-
except
|
228
|
-
A=
|
226
|
+
except d:H=sys.implementation.name
|
227
|
+
A=l({Q:H,C:B,D:B,M:B,K:sys.platform,U:'UNKNOWN',P:B,F:B,R:B})
|
229
228
|
if A[K].startswith('pyb'):A[K]='stm32'
|
230
|
-
elif A[K]==
|
231
|
-
elif A[K]=='linux':A[K]=
|
232
|
-
try:A[C]=
|
229
|
+
elif A[K]==S:A[K]='windows'
|
230
|
+
elif A[K]=='linux':A[K]=V
|
231
|
+
try:A[C]=A6(sys.implementation.version)
|
233
232
|
except I:pass
|
234
|
-
try:J=sys.implementation._machine if'_machine'in N(sys.implementation)else os.uname().machine;A[
|
235
|
-
except(I,
|
236
|
-
A[
|
233
|
+
try:J=sys.implementation._machine if'_machine'in N(sys.implementation)else os.uname().machine;A[U]=J;A[P]=J.split('with')[-1].strip();A[F]=sys.implementation._mpy if'_mpy'in N(sys.implementation)else sys.implementation.mpy if F in N(sys.implementation)else B
|
234
|
+
except(I,T):pass
|
235
|
+
A[U]=A7()
|
237
236
|
try:
|
238
237
|
if'uname'in N(os):
|
239
|
-
A[D]=
|
240
|
-
if not A[D]:A[D]=
|
241
|
-
elif C in N(sys):A[D]=
|
242
|
-
except(I,
|
243
|
-
if A[C]==B and sys.platform not in(
|
244
|
-
try:
|
245
|
-
except(
|
246
|
-
for(
|
247
|
-
try:
|
248
|
-
except(O,
|
249
|
-
if A[Q]==
|
250
|
-
if A[Q]==
|
238
|
+
A[D]=Y(os.uname()[3])
|
239
|
+
if not A[D]:A[D]=Y(os.uname()[2])
|
240
|
+
elif C in N(sys):A[D]=Y(sys.version)
|
241
|
+
except(I,T,d):pass
|
242
|
+
if A[C]==B and sys.platform not in(V,S):
|
243
|
+
try:b=os.uname();A[C]=b.release
|
244
|
+
except(T,I,d):pass
|
245
|
+
for(c,e,f)in[(X,X,'const'),(Z,Z,'FAT'),(a,'pybricks.hubs','EV3Brick')]:
|
246
|
+
try:g=__import__(e,E,E,f);A[Q]=c;del g;break
|
247
|
+
except(O,r):pass
|
248
|
+
if A[Q]==a:A['release']='2.0.0'
|
249
|
+
if A[Q]==u:
|
251
250
|
A[C]
|
252
251
|
if A[C]and A[C].endswith('.0')and A[C]>='1.10.0'and A[C]<='1.19.9':A[C]=A[C][:-2]
|
253
252
|
if F in A and A[F]:
|
254
253
|
G=int(A[F]);L=[E,'x86','x64','armv6','armv6m','armv7m','armv7em','armv7emsp','armv7emdp','xtensa','xtensawin'][G>>10]
|
255
254
|
if L:A[R]=L
|
256
255
|
A[F]='v{}.{}'.format(G&255,G>>8&3)
|
257
|
-
if A[D]and not A[C].endswith(
|
256
|
+
if A[D]and not A[C].endswith(W):A[C]=A[C]+W
|
258
257
|
A[M]=f"{A[C]}-{A[D]}"if A[D]else f"{A[C]}";return A
|
259
|
-
def
|
260
|
-
A=version;B=J.join([
|
261
|
-
if P(A)>3 and A[3]:B+=
|
258
|
+
def A6(version):
|
259
|
+
A=version;B=J.join([c(A)for A in A[:3]])
|
260
|
+
if P(A)>3 and A[3]:B+=V+A[3]
|
262
261
|
return B
|
263
262
|
def A7():
|
264
263
|
try:from boardname import BOARDNAME as C;A.info('Found BOARDNAME: {}'.format(C))
|
@@ -272,28 +271,28 @@ def get_root():
|
|
272
271
|
try:C=os.stat(B);break
|
273
272
|
except D:continue
|
274
273
|
return B
|
275
|
-
def
|
274
|
+
def Z(filename):
|
276
275
|
try:
|
277
276
|
if os.stat(filename)[0]>>14:return R
|
278
277
|
return H
|
279
278
|
except D:return H
|
280
|
-
def
|
279
|
+
def m():S("-p, --path path to store the stubs in, defaults to '.'");sys.exit(1)
|
281
280
|
def read_path():
|
282
281
|
path=B
|
283
282
|
if P(sys.argv)==3:
|
284
283
|
A=sys.argv[1].lower()
|
285
284
|
if A in('--path','-p'):path=sys.argv[2]
|
286
|
-
else:
|
287
|
-
elif P(sys.argv)==2:
|
285
|
+
else:m()
|
286
|
+
elif P(sys.argv)==2:m()
|
288
287
|
return path
|
289
|
-
def
|
290
|
-
try:A=bytes('abc',encoding='utf8');B=
|
291
|
-
except(
|
292
|
-
|
288
|
+
def n():
|
289
|
+
try:A=bytes('abc',encoding='utf8');B=n.__module__;return H
|
290
|
+
except(o,I):return R
|
291
|
+
a='modulelist.done'
|
293
292
|
def A8(skip=0):
|
294
|
-
for E in
|
293
|
+
for E in A5:
|
295
294
|
B=E+'/modulelist.txt'
|
296
|
-
if not
|
295
|
+
if not Z(B):continue
|
297
296
|
try:
|
298
297
|
with M(B)as F:
|
299
298
|
C=0
|
@@ -307,27 +306,27 @@ def A8(skip=0):
|
|
307
306
|
break
|
308
307
|
except D:pass
|
309
308
|
def A9(done):
|
310
|
-
with M(
|
309
|
+
with M(a,h)as A:A.write(c(done)+'\n')
|
311
310
|
def AA():
|
312
311
|
A=0
|
313
312
|
try:
|
314
|
-
with M(
|
313
|
+
with M(a)as B:A=int(B.readline().strip())
|
315
314
|
except D:pass
|
316
315
|
return A
|
317
316
|
def main():
|
318
|
-
import machine as D;C=a
|
317
|
+
import machine as D;C=Z(a)
|
319
318
|
if C:A.info('Continue from last run')
|
320
319
|
else:A.info('Starting new run')
|
321
320
|
stubber=Stubber(path=read_path());B=0
|
322
|
-
if not C:stubber.clean();stubber.report_start(
|
323
|
-
else:B=AA();stubber._json_name=
|
321
|
+
if not C:stubber.clean();stubber.report_start(j)
|
322
|
+
else:B=AA();stubber._json_name=i.format(stubber.path,j)
|
324
323
|
for E in A8(B):
|
325
324
|
try:stubber.create_one_stub(E)
|
326
|
-
except
|
325
|
+
except p:D.reset()
|
327
326
|
F.collect();B+=1;A9(B)
|
328
|
-
|
329
|
-
if __name__=='__main__'or
|
330
|
-
if not
|
327
|
+
S('All modules have been processed, Finalizing report');stubber.report_end()
|
328
|
+
if __name__=='__main__'or n():
|
329
|
+
if not Z('no_auto_stubber.txt'):
|
331
330
|
try:F.threshold(4*1024);F.enable()
|
332
331
|
except BaseException:pass
|
333
332
|
main()
|
Binary file
|