micropython-stubber 1.23.2__py3-none-any.whl → 1.24.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.
- {micropython_stubber-1.23.2.dist-info → micropython_stubber-1.24.0.dist-info}/METADATA +30 -12
- {micropython_stubber-1.23.2.dist-info → micropython_stubber-1.24.0.dist-info}/RECORD +69 -66
- {micropython_stubber-1.23.2.dist-info → micropython_stubber-1.24.0.dist-info}/WHEEL +1 -1
- mpflash/README.md +2 -2
- mpflash/mpflash/basicgit.py +49 -9
- mpflash/mpflash/common.py +23 -16
- mpflash/mpflash/downloaded.py +10 -2
- mpflash/mpflash/mpboard_id/__init__.py +9 -4
- mpflash/mpflash/mpboard_id/add_boards.py +25 -14
- mpflash/mpflash/mpboard_id/board.py +2 -2
- mpflash/mpflash/mpboard_id/board_id.py +10 -6
- mpflash/mpflash/mpboard_id/board_info.zip +0 -0
- mpflash/mpflash/mpboard_id/store.py +8 -3
- mpflash/mpflash/mpremoteboard/__init__.py +13 -8
- mpflash/mpflash/mpremoteboard/mpy_fw_info.py +27 -16
- mpflash/mpflash/vendor/board_database.py +185 -0
- mpflash/mpflash/vendor/readme.md +10 -1
- mpflash/mpflash/versions.py +28 -40
- mpflash/poetry.lock +1605 -601
- mpflash/pyproject.toml +4 -3
- stubber/__init__.py +1 -1
- stubber/board/createstubs.py +51 -27
- stubber/board/createstubs_db.py +36 -28
- stubber/board/createstubs_db_min.py +171 -165
- stubber/board/createstubs_db_mpy.mpy +0 -0
- stubber/board/createstubs_mem.py +36 -28
- stubber/board/createstubs_mem_min.py +184 -178
- stubber/board/createstubs_mem_mpy.mpy +0 -0
- stubber/board/createstubs_min.py +102 -94
- stubber/board/createstubs_mpy.mpy +0 -0
- stubber/board/modulelist.txt +16 -0
- stubber/codemod/enrich.py +297 -88
- stubber/codemod/merge_docstub.py +250 -65
- stubber/codemod/test_enrich.py +87 -0
- stubber/codemod/visitors/typevars.py +200 -0
- stubber/commands/build_cmd.py +16 -3
- stubber/commands/clone_cmd.py +3 -3
- stubber/commands/config_cmd.py +4 -2
- stubber/commands/enrich_folder_cmd.py +33 -21
- stubber/commands/get_core_cmd.py +1 -2
- stubber/commands/get_docstubs_cmd.py +60 -6
- stubber/commands/get_frozen_cmd.py +15 -12
- stubber/commands/get_mcu_cmd.py +3 -3
- stubber/commands/merge_cmd.py +1 -2
- stubber/commands/publish_cmd.py +19 -4
- stubber/commands/stub_cmd.py +3 -3
- stubber/commands/switch_cmd.py +3 -5
- stubber/commands/variants_cmd.py +3 -3
- stubber/cst_transformer.py +52 -17
- stubber/freeze/common.py +27 -11
- stubber/freeze/freeze_manifest_2.py +8 -1
- stubber/freeze/get_frozen.py +4 -1
- stubber/merge_config.py +111 -0
- stubber/minify.py +1 -2
- stubber/publish/database.py +51 -10
- stubber/publish/merge_docstubs.py +33 -16
- stubber/publish/package.py +32 -18
- stubber/publish/publish.py +8 -8
- stubber/publish/stubpackage.py +110 -47
- stubber/rst/lookup.py +205 -43
- stubber/rst/reader.py +106 -59
- stubber/rst/rst_utils.py +24 -11
- stubber/stubber.py +1 -1
- stubber/stubs_from_docs.py +31 -13
- stubber/update_module_list.py +2 -2
- stubber/utils/config.py +33 -13
- stubber/utils/post.py +9 -6
- stubber/publish/missing_class_methods.py +0 -51
- {micropython_stubber-1.23.2.dist-info → micropython_stubber-1.24.0.dist-info}/LICENSE +0 -0
- {micropython_stubber-1.23.2.dist-info → micropython_stubber-1.24.0.dist-info}/entry_points.txt +0 -0
@@ -1,41 +1,41 @@
|
|
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
|
-
|
31
|
-
R=
|
32
|
-
Q=
|
33
|
-
P=
|
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=True
|
30
|
+
S='family'
|
31
|
+
R=len
|
32
|
+
Q=IndexError
|
33
|
+
P=print
|
34
34
|
O=ImportError
|
35
35
|
N=dir
|
36
36
|
M=open
|
37
|
-
|
38
|
-
|
37
|
+
L='port'
|
38
|
+
K='.'
|
39
39
|
I=AttributeError
|
40
40
|
H=False
|
41
41
|
G='/'
|
@@ -49,43 +49,44 @@ 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.
|
55
|
-
|
52
|
+
try:from collections import OrderedDict as l
|
53
|
+
except O:from ucollections import OrderedDict as l
|
54
|
+
__version__='v1.24.0'
|
55
|
+
A3=2
|
56
56
|
A4=2
|
57
|
-
A5=
|
58
|
-
|
59
|
-
|
60
|
-
INFO=20;WARNING=30;ERROR=40;level=INFO;prnt=T
|
57
|
+
A5=['lib','/lib','/sd/lib','/flash/lib',K]
|
58
|
+
class J:
|
59
|
+
DEBUG=10;INFO=20;WARNING=30;ERROR=40;level=INFO;prnt=P
|
61
60
|
@staticmethod
|
62
|
-
def getLogger(name):return
|
61
|
+
def getLogger(name):return J()
|
63
62
|
@classmethod
|
64
63
|
def basicConfig(A,level):A.level=level
|
64
|
+
def debug(A,msg):
|
65
|
+
if A.level<=J.DEBUG:A.prnt('DEBUG :',msg)
|
65
66
|
def info(A,msg):
|
66
|
-
if A.level<=
|
67
|
+
if A.level<=J.INFO:A.prnt('INFO :',msg)
|
67
68
|
def warning(A,msg):
|
68
|
-
if A.level<=
|
69
|
+
if A.level<=J.WARNING:A.prnt('WARN :',msg)
|
69
70
|
def error(A,msg):
|
70
|
-
if A.level<=
|
71
|
-
A=
|
72
|
-
|
71
|
+
if A.level<=J.ERROR:A.prnt('ERROR :',msg)
|
72
|
+
A=J.getLogger(t)
|
73
|
+
J.basicConfig(level=J.INFO)
|
73
74
|
class Stubber:
|
74
75
|
def __init__(B,path=E,firmware_id=E):
|
75
76
|
C=firmware_id
|
76
77
|
try:
|
77
|
-
if os.uname().release=='1.13.0'and os.uname().version<'v1.13-103':raise
|
78
|
+
if os.uname().release=='1.13.0'and os.uname().version<'v1.13-103':raise o('MicroPython 1.13.0 cannot be stubbed')
|
78
79
|
except I:pass
|
79
|
-
B.info=_info();A.info('Port: {}'.format(B.info[
|
80
|
+
B.info=_info();A.info('Port: {}'.format(B.info[L]));A.info('Board: {}'.format(B.info[U]));F.collect()
|
80
81
|
if C:B._fwid=C.lower()
|
81
|
-
elif B.info[
|
82
|
+
elif B.info[S]==u:B._fwid='{family}-v{version}-{port}-{board}'.format(**B.info).rstrip(V)
|
82
83
|
else:B._fwid='{family}-v{version}-{port}'.format(**B.info)
|
83
84
|
B._start_free=F.mem_free()
|
84
85
|
if path:
|
85
86
|
if path.endswith(G):path=path[:-1]
|
86
87
|
else:path=get_root()
|
87
88
|
B.path='{}/stubs/{}'.format(path,B.flat_fwid).replace('//',G)
|
88
|
-
try:
|
89
|
+
try:X(path+G)
|
89
90
|
except D:A.error('error creating stub folder {}'.format(path))
|
90
91
|
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
92
|
def get_obj_attributes(L,item_instance):
|
@@ -94,17 +95,17 @@ class Stubber:
|
|
94
95
|
if A.startswith('__')and not A in L.modules:continue
|
95
96
|
try:
|
96
97
|
D=getattr(H,A)
|
97
|
-
try:E=
|
98
|
-
except
|
99
|
-
if E in{w,x,y,
|
100
|
-
elif E in{A0
|
98
|
+
try:E=b(type(D)).split("'")[1]
|
99
|
+
except Q:E=B
|
100
|
+
if E in{v,w,x,y,e,f,g}:G=1
|
101
|
+
elif E in{z,A0}:G=2
|
101
102
|
elif E in'class':G=3
|
102
103
|
else:G=4
|
103
|
-
C.append((A,
|
104
|
+
C.append((A,b(D),b(type(D)),D,G))
|
104
105
|
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=
|
106
|
+
except p as J:P('MemoryError: {}'.format(J));sleep(1);reset()
|
107
|
+
C=q([A for A in C if not A[0].startswith('__')],key=lambda x:x[4]);F.collect();return C,K
|
108
|
+
def add_modules(A,modules):A.modules=q(set(A.modules)|set(modules))
|
108
109
|
def create_all_stubs(B):
|
109
110
|
A.info('Start micropython-stubber {} on {}'.format(__version__,B._fwid));B.report_start();F.collect()
|
110
111
|
for C in B.modules:B.create_one_stub(C)
|
@@ -113,60 +114,62 @@ class Stubber:
|
|
113
114
|
B=module_name
|
114
115
|
if B in C.problematic:A.warning('Skip module: {:<25} : Known problematic'.format(B));return H
|
115
116
|
if B in C.excluded:A.warning('Skip module: {:<25} : Excluded'.format(B));return H
|
116
|
-
I='{}/{}.pyi'.format(C.path,B.replace(
|
117
|
+
I='{}/{}.pyi'.format(C.path,B.replace(K,G));F.collect();E=H
|
117
118
|
try:E=C.create_module_stub(B,I)
|
118
119
|
except D:return H
|
119
120
|
F.collect();return E
|
120
|
-
def create_module_stub(
|
121
|
+
def create_module_stub(J,module_name,file_name=E):
|
121
122
|
I=file_name;C=module_name
|
122
|
-
if I is E:L=C.replace(
|
123
|
+
if I is E:L=C.replace(K,'_')+'.pyi';I=J.path+G+L
|
123
124
|
else:L=I.split(G)[-1]
|
124
|
-
if G in C:C=C.replace(G,
|
125
|
+
if G in C:C=C.replace(G,K)
|
125
126
|
N=E
|
126
127
|
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
128
|
except O:return H
|
128
|
-
|
129
|
-
with M(I,
|
130
|
-
|
129
|
+
X(I)
|
130
|
+
with M(I,h)as P:R=c(J.info).replace('OrderedDict(',B).replace('})','}');S='"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(C,J._fwid,R,__version__);P.write(S);P.write('from __future__ import annotations\nfrom typing import Any, Generator\nfrom _typeshed import Incomplete\n\n');J.write_object_stub(P,N,C,B)
|
131
|
+
J.report_add(C,I)
|
131
132
|
if C not in{'os','sys','logging','gc'}:
|
132
133
|
try:del N
|
133
|
-
except(D,
|
134
|
-
F.collect();return
|
134
|
+
except(D,r):A.warning('could not del new_module')
|
135
|
+
F.collect();return T
|
135
136
|
def write_object_stub(L,fp,object_expr,obj_name,indent,in_class=0):
|
136
|
-
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;
|
137
|
+
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;E=indent;F.collect()
|
137
138
|
if M in L.problematic:A.warning('SKIPPING problematic module:{}'.format(M));return
|
138
|
-
a,
|
139
|
-
if
|
140
|
-
for(
|
141
|
-
if
|
142
|
-
if
|
143
|
-
if I=="<class 'type'>"and
|
144
|
-
|
145
|
-
if S:
|
146
|
-
|
147
|
-
if S:
|
148
|
-
J.write(
|
149
|
-
elif any(A in I for A in[
|
139
|
+
a,P=L.get_obj_attributes(M)
|
140
|
+
if P:A.error(P)
|
141
|
+
for(C,H,I,b,d)in a:
|
142
|
+
if C in['classmethod','staticmethod','BaseException',N]:continue
|
143
|
+
if C[0].isdigit():A.warning('NameError: invalid name {}'.format(C));continue
|
144
|
+
if I=="<class 'type'>"and R(E)<=A4*4:
|
145
|
+
Q=B;S=C.endswith(N)or C.endswith('Error')or C in['KeyboardInterrupt','StopIteration','SystemExit']
|
146
|
+
if S:Q=N
|
147
|
+
D='\n{}class {}({}):\n'.format(E,C,Q)
|
148
|
+
if S:D+=E+' ...\n';J.write(D);continue
|
149
|
+
J.write(D);L.write_object_stub(J,b,'{0}.{1}'.format(obj_name,C),E+' ',O+1);D=E+' def __init__(self, *argv, **kwargs) -> None:\n';D+=E+' ...\n\n';J.write(D)
|
150
|
+
elif any(A in I for A in[A0,z,'closure']):
|
150
151
|
T=V;U=B
|
151
152
|
if O>0:U='self, '
|
152
|
-
if W in I or W in H:
|
153
|
-
else:
|
154
|
-
|
153
|
+
if W in I or W in H:D='{}@classmethod\n'.format(E)+'{}def {}(cls, *args, **kwargs) -> {}:\n'.format(E,C,T)
|
154
|
+
else:D='{}def {}({}*args, **kwargs) -> {}:\n'.format(E,C,U,T)
|
155
|
+
D+=E+' ...\n\n';J.write(D)
|
155
156
|
elif I=="<class 'module'>":0
|
156
157
|
elif I.startswith("<class '"):
|
157
|
-
G=I[8:-2];
|
158
|
-
if G in(
|
159
|
-
|
158
|
+
G=I[8:-2];D=B
|
159
|
+
if G in(x,v,w,y,'bytearray','bytes'):
|
160
|
+
if C.upper()==C:D='{0}{1}: Final[{3}] = {2}\n'.format(E,C,H,G)
|
161
|
+
else:D=X.format(E,C,H,G)
|
162
|
+
elif G in(g,f,e):c={g:'{}',f:'[]',e:'()'};D=X.format(E,C,c[G],G)
|
160
163
|
elif G in('object','set','frozenset','Pin',Y):
|
161
164
|
if G==Y:G='Generator'
|
162
|
-
|
165
|
+
D='{0}{1}: {2} ## = {4}\n'.format(E,C,G,I,H)
|
163
166
|
else:
|
164
167
|
G=V
|
165
168
|
if K in H:H=H.split(K)[0]+Z
|
166
169
|
if K in H:H=H.split(K)[0]+Z
|
167
|
-
|
168
|
-
J.write(
|
169
|
-
else:J.write("# all other, type = '{0}'\n".format(I));J.write(
|
170
|
+
D='{0}{1}: {2} ## {3} = {4}\n'.format(E,C,G,I,H)
|
171
|
+
J.write(D)
|
172
|
+
else:J.write("# all other, type = '{0}'\n".format(I));J.write(E+C+' # type: Incomplete\n')
|
170
173
|
@property
|
171
174
|
def flat_fwid(self):
|
172
175
|
A=self._fwid;B=' .()/\\:$'
|
@@ -178,29 +181,29 @@ class Stubber:
|
|
178
181
|
try:os.stat(path);F=os.listdir(path)
|
179
182
|
except(D,I):return
|
180
183
|
for G in F:
|
181
|
-
B=
|
184
|
+
B=i.format(path,G)
|
182
185
|
try:os.remove(B)
|
183
186
|
except D:
|
184
187
|
try:C.clean(B);os.rmdir(B)
|
185
188
|
except D:pass
|
186
|
-
def report_start(B,filename=
|
187
|
-
H='firmware';B._json_name=
|
189
|
+
def report_start(B,filename=j):
|
190
|
+
H='firmware';B._json_name=i.format(B.path,filename);B._json_first=T;X(B._json_name);A.info('Report file: {}'.format(B._json_name));F.collect()
|
188
191
|
try:
|
189
|
-
with M(B._json_name,
|
190
|
-
except D as I:A.error(
|
192
|
+
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')
|
193
|
+
except D as I:A.error(A1);B._json_name=E;raise I
|
191
194
|
def report_add(B,module_name,stub_file):
|
192
|
-
if not B._json_name:raise
|
195
|
+
if not B._json_name:raise s(A2)
|
193
196
|
try:
|
194
197
|
with M(B._json_name,'a')as C:
|
195
|
-
if not B._json_first:C.write(
|
198
|
+
if not B._json_first:C.write(k)
|
196
199
|
else:B._json_first=H
|
197
200
|
E='{{"module": "{}", "file": "{}"}}'.format(module_name,stub_file.replace('\\',G));C.write(E)
|
198
|
-
except D:A.error(
|
201
|
+
except D:A.error(A1)
|
199
202
|
def report_end(B):
|
200
|
-
if not B._json_name:raise
|
203
|
+
if not B._json_name:raise s(A2)
|
201
204
|
with M(B._json_name,'a')as C:C.write('\n]}')
|
202
205
|
A.info('Path: {}'.format(B.path))
|
203
|
-
def
|
206
|
+
def X(path):
|
204
207
|
B=E=0
|
205
208
|
while B!=-1:
|
206
209
|
B=path.find(G,E)
|
@@ -208,57 +211,59 @@ def Y(path):
|
|
208
211
|
C=path[0]if B==0 else path[:B]
|
209
212
|
try:I=os.stat(C)
|
210
213
|
except D as F:
|
211
|
-
if F.args[0]==
|
212
|
-
try:os.mkdir(C)
|
214
|
+
if F.args[0]==A3:
|
215
|
+
try:A.debug('Create folder {}'.format(C));os.mkdir(C)
|
213
216
|
except D as H:A.error('failed to create folder {}'.format(C));raise H
|
214
217
|
E=B+1
|
215
|
-
def
|
218
|
+
def Y(s):
|
216
219
|
C=' on '
|
217
220
|
if not s:return B
|
218
221
|
s=s.split(C,1)[0]if C in s else s
|
219
222
|
if s.startswith('v'):
|
220
|
-
if not
|
221
|
-
A=s.split(
|
222
|
-
if not
|
223
|
-
A=s.split(
|
223
|
+
if not V in s:return B
|
224
|
+
A=s.split(V)[1];return A
|
225
|
+
if not W in s:return B
|
226
|
+
A=s.split(W)[1].split(K)[1];return A
|
224
227
|
def _info():
|
225
|
-
|
226
|
-
try:
|
227
|
-
except
|
228
|
-
A=
|
229
|
-
if A[
|
230
|
-
elif A[
|
231
|
-
elif A[
|
232
|
-
try:A[C]=
|
228
|
+
a='ev3-pybricks';Z='pycom';X='pycopy';V='unix';T='win32';R='arch';P='cpu';M='ver';F='mpy';D='build'
|
229
|
+
try:J=sys.implementation[0]
|
230
|
+
except d:J=sys.implementation.name
|
231
|
+
A=l({S:J,C:B,D:B,M:B,L:sys.platform,U:'UNKNOWN',P:B,F:B,R:B})
|
232
|
+
if A[L].startswith('pyb'):A[L]='stm32'
|
233
|
+
elif A[L]==T:A[L]='windows'
|
234
|
+
elif A[L]=='linux':A[L]=V
|
235
|
+
try:A[C]=A6(sys.implementation.version)
|
233
236
|
except I:pass
|
234
|
-
try:
|
235
|
-
except(I,
|
236
|
-
A[
|
237
|
+
try:K=sys.implementation._machine if'_machine'in N(sys.implementation)else os.uname().machine;A[U]=K;A[P]=K.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
|
238
|
+
except(I,Q):pass
|
239
|
+
A[U]=A7()
|
237
240
|
try:
|
238
241
|
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[
|
250
|
-
if A[
|
242
|
+
A[D]=Y(os.uname()[3])
|
243
|
+
if not A[D]:A[D]=Y(os.uname()[2])
|
244
|
+
elif C in N(sys):A[D]=Y(sys.version)
|
245
|
+
except(I,Q,d):pass
|
246
|
+
if A[C]==B and sys.platform not in(V,T):
|
247
|
+
try:b=os.uname();A[C]=b.release
|
248
|
+
except(Q,I,d):pass
|
249
|
+
for(c,e,f)in[(X,X,'const'),(Z,Z,'FAT'),(a,'pybricks.hubs','EV3Brick')]:
|
250
|
+
try:g=__import__(e,E,E,f);A[S]=c;del g;break
|
251
|
+
except(O,r):pass
|
252
|
+
if A[S]==a:A['release']='2.0.0'
|
253
|
+
if A[S]==u:
|
251
254
|
A[C]
|
252
255
|
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
256
|
if F in A and A[F]:
|
254
|
-
G=int(A[F])
|
255
|
-
|
257
|
+
G=int(A[F])
|
258
|
+
try:H=[E,'x86','x64','armv6','armv6m','armv7m','armv7em','armv7emsp','armv7emdp','xtensa','xtensawin','rv32imc'][G>>10]
|
259
|
+
except Q:H='unknown'
|
260
|
+
if H:A[R]=H
|
256
261
|
A[F]='v{}.{}'.format(G&255,G>>8&3)
|
257
|
-
if A[D]and not A[C].endswith(
|
262
|
+
if A[D]and not A[C].endswith(W):A[C]=A[C]+W
|
258
263
|
A[M]=f"{A[C]}-{A[D]}"if A[D]else f"{A[C]}";return A
|
259
|
-
def
|
260
|
-
A=version;B=
|
261
|
-
if
|
264
|
+
def A6(version):
|
265
|
+
A=version;B=K.join([c(A)for A in A[:3]])
|
266
|
+
if R(A)>3 and A[3]:B+=V+A[3]
|
262
267
|
return B
|
263
268
|
def A7():
|
264
269
|
try:from boardname import BOARDNAME as C;A.info('Found BOARDNAME: {}'.format(C))
|
@@ -266,68 +271,69 @@ def A7():
|
|
266
271
|
return C
|
267
272
|
def get_root():
|
268
273
|
try:A=os.getcwd()
|
269
|
-
except(D,I):A=
|
274
|
+
except(D,I):A=K
|
270
275
|
B=A
|
271
|
-
for B in[
|
276
|
+
for B in['/remote','/sd','/flash',G,A,K]:
|
272
277
|
try:C=os.stat(B);break
|
273
278
|
except D:continue
|
274
279
|
return B
|
275
|
-
def
|
280
|
+
def Z(filename):
|
276
281
|
try:
|
277
|
-
if os.stat(filename)[0]>>14:return
|
282
|
+
if os.stat(filename)[0]>>14:return T
|
278
283
|
return H
|
279
284
|
except D:return H
|
280
|
-
def
|
285
|
+
def m():P("-p, --path path to store the stubs in, defaults to '.'");sys.exit(1)
|
281
286
|
def read_path():
|
282
287
|
path=B
|
283
|
-
if
|
288
|
+
if R(sys.argv)==3:
|
284
289
|
A=sys.argv[1].lower()
|
285
290
|
if A in('--path','-p'):path=sys.argv[2]
|
286
|
-
else:
|
287
|
-
elif
|
291
|
+
else:m()
|
292
|
+
elif R(sys.argv)==2:m()
|
288
293
|
return path
|
289
|
-
def
|
290
|
-
try:A=bytes('abc',encoding='utf8');B=
|
291
|
-
except(
|
292
|
-
|
294
|
+
def n():
|
295
|
+
try:A=bytes('abc',encoding='utf8');B=n.__module__;return H
|
296
|
+
except(o,I):return T
|
297
|
+
a='modulelist.done'
|
293
298
|
def A8(skip=0):
|
294
|
-
for E in
|
299
|
+
for E in A5:
|
295
300
|
B=E+'/modulelist.txt'
|
296
|
-
if not
|
301
|
+
if not Z(B):continue
|
297
302
|
try:
|
298
303
|
with M(B)as F:
|
299
304
|
C=0
|
300
|
-
while
|
305
|
+
while T:
|
301
306
|
A=F.readline().strip()
|
302
307
|
if not A:break
|
303
|
-
if
|
308
|
+
if R(A)>0 and A[0]=='#':continue
|
304
309
|
C+=1
|
305
310
|
if C<skip:continue
|
306
311
|
yield A
|
307
312
|
break
|
308
313
|
except D:pass
|
309
314
|
def A9(done):
|
310
|
-
with M(
|
315
|
+
with M(a,h)as A:A.write(c(done)+'\n')
|
311
316
|
def AA():
|
312
317
|
A=0
|
313
318
|
try:
|
314
|
-
with M(
|
319
|
+
with M(a)as B:A=int(B.readline().strip())
|
315
320
|
except D:pass
|
316
321
|
return A
|
317
322
|
def main():
|
318
|
-
import machine as D;C=a
|
323
|
+
import machine as D;C=Z(a)
|
319
324
|
if C:A.info('Continue from last run')
|
320
325
|
else:A.info('Starting new run')
|
321
326
|
stubber=Stubber(path=read_path());B=0
|
322
|
-
if not C:stubber.clean();stubber.report_start(
|
323
|
-
else:B=AA();stubber._json_name=
|
327
|
+
if not C:stubber.clean();stubber.report_start(j)
|
328
|
+
else:B=AA();stubber._json_name=i.format(stubber.path,j)
|
324
329
|
for E in A8(B):
|
325
330
|
try:stubber.create_one_stub(E)
|
326
|
-
except
|
331
|
+
except p:D.reset()
|
327
332
|
F.collect();B+=1;A9(B)
|
328
|
-
|
329
|
-
if __name__=='__main__'or
|
330
|
-
if not
|
331
|
-
|
333
|
+
P('All modules have been processed, Finalizing report');stubber.report_end()
|
334
|
+
if __name__=='__main__'or n():
|
335
|
+
if not Z('no_auto_stubber.txt'):
|
336
|
+
P(f"createstubs.py: {__version__}")
|
337
|
+
try:F.threshold(4096);F.enable()
|
332
338
|
except BaseException:pass
|
333
339
|
main()
|
Binary file
|
stubber/board/createstubs_mem.py
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
- cross compilation, using mpy-cross,
|
10
10
|
to avoid the compilation step on the micropython device
|
11
11
|
|
12
|
-
This variant was generated from createstubs.py by micropython-stubber v1.
|
12
|
+
This variant was generated from createstubs.py by micropython-stubber v1.24.0
|
13
13
|
"""
|
14
14
|
|
15
15
|
# Copyright (c) 2019-2024 Jos Verlinde
|
@@ -34,8 +34,7 @@ try:
|
|
34
34
|
except ImportError:
|
35
35
|
from ucollections import OrderedDict # type: ignore
|
36
36
|
|
37
|
-
__version__ = "v1.
|
38
|
-
version_str = __version__.rsplit(".", 1)[0]
|
37
|
+
__version__ = "v1.24.0"
|
39
38
|
ENOENT = 2
|
40
39
|
_MAX_CLASS_LEVEL = 2 # Max class nesting
|
41
40
|
LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
|
@@ -43,7 +42,7 @@ LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
|
|
43
42
|
|
44
43
|
# our own logging module to avoid dependency on and interfering with logging module
|
45
44
|
class logging:
|
46
|
-
|
45
|
+
DEBUG = 10
|
47
46
|
INFO = 20
|
48
47
|
WARNING = 30
|
49
48
|
ERROR = 40
|
@@ -58,9 +57,9 @@ class logging:
|
|
58
57
|
def basicConfig(cls, level):
|
59
58
|
cls.level = level
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
def debug(self, msg):
|
61
|
+
if self.level <= logging.DEBUG:
|
62
|
+
self.prnt("DEBUG :", msg)
|
64
63
|
|
65
64
|
def info(self, msg):
|
66
65
|
if self.level <= logging.INFO:
|
@@ -236,10 +235,11 @@ class Stubber:
|
|
236
235
|
return False
|
237
236
|
|
238
237
|
# Start a new file
|
238
|
+
# log.debug("Create file: {}".format(file_name))
|
239
239
|
ensure_folder(file_name)
|
240
240
|
with open(file_name, "w") as fp:
|
241
241
|
info_ = str(self.info).replace("OrderedDict(", "").replace("})", "}")
|
242
|
-
s = '"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(module_name, self._fwid, info_,
|
242
|
+
s = '"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(module_name, self._fwid, info_, __version__)
|
243
243
|
fp.write(s)
|
244
244
|
fp.write("from __future__ import annotations\nfrom typing import Any, Generator\nfrom _typeshed import Incomplete\n\n")
|
245
245
|
self.write_object_stub(fp, new_module, module_name, "")
|
@@ -349,8 +349,10 @@ class Stubber:
|
|
349
349
|
|
350
350
|
if t in ("str", "int", "float", "bool", "bytearray", "bytes"):
|
351
351
|
# known type: use actual value
|
352
|
-
|
353
|
-
|
352
|
+
if item_name.upper() == item_name: # ALL_CAPS --> Final
|
353
|
+
s = "{0}{1}: Final[{3}] = {2}\n".format(indent, item_name, item_repr, t)
|
354
|
+
else:
|
355
|
+
s = "{0}{1}: {3} = {2}\n".format(indent, item_name, item_repr, t)
|
354
356
|
elif t in ("dict", "list", "tuple"):
|
355
357
|
# dict, list , tuple: use empty value
|
356
358
|
ev = {"dict": "{}", "list": "[]", "tuple": "()"}
|
@@ -434,7 +436,7 @@ class Stubber:
|
|
434
436
|
f.write("{")
|
435
437
|
f.write(dumps({"firmware": self.info})[1:-1])
|
436
438
|
f.write(",\n")
|
437
|
-
f.write(dumps({"stubber": {"version":
|
439
|
+
f.write(dumps({"stubber": {"version": __version__}, "stubtype": "firmware"})[1:-1])
|
438
440
|
f.write(",\n")
|
439
441
|
f.write('"modules" :[\n')
|
440
442
|
|
@@ -483,6 +485,7 @@ def ensure_folder(path: str):
|
|
483
485
|
# folder does not exist
|
484
486
|
if e.args[0] == ENOENT:
|
485
487
|
try:
|
488
|
+
log.debug("Create folder {}".format(p))
|
486
489
|
os.mkdir(p)
|
487
490
|
except OSError as e2:
|
488
491
|
log.error("failed to create folder {}".format(p))
|
@@ -493,7 +496,7 @@ def ensure_folder(path: str):
|
|
493
496
|
|
494
497
|
def _build(s):
|
495
498
|
# extract build from sys.version or os.uname().version if available
|
496
|
-
# sys.version: 'MicroPython v1.
|
499
|
+
# sys.version: 'MicroPython v1.24.0-preview.6.g3d0b6276f'
|
497
500
|
# sys.implementation.version: 'v1.13-103-gb137d064e'
|
498
501
|
if not s:
|
499
502
|
return ""
|
@@ -598,29 +601,33 @@ def _info(): # type:() -> dict[str, str]
|
|
598
601
|
if (
|
599
602
|
info["version"]
|
600
603
|
and info["version"].endswith(".0")
|
601
|
-
and info["version"] >= "1.10.0" # versions from 1.10.0 to 1.
|
604
|
+
and info["version"] >= "1.10.0" # versions from 1.10.0 to 1.24.0 do not have a micro .0
|
602
605
|
and info["version"] <= "1.19.9"
|
603
606
|
):
|
604
|
-
# versions from 1.10.0 to 1.
|
607
|
+
# versions from 1.10.0 to 1.24.0 do not have a micro .0
|
605
608
|
info["version"] = info["version"][:-2]
|
606
609
|
|
607
610
|
# spell-checker: disable
|
608
611
|
if "mpy" in info and info["mpy"]: # mpy on some v1.11+ builds
|
609
612
|
sys_mpy = int(info["mpy"])
|
610
613
|
# .mpy architecture
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
614
|
+
try:
|
615
|
+
arch = [
|
616
|
+
None,
|
617
|
+
"x86",
|
618
|
+
"x64",
|
619
|
+
"armv6",
|
620
|
+
"armv6m",
|
621
|
+
"armv7m",
|
622
|
+
"armv7em",
|
623
|
+
"armv7emsp",
|
624
|
+
"armv7emdp",
|
625
|
+
"xtensa",
|
626
|
+
"xtensawin",
|
627
|
+
"rv32imc",
|
628
|
+
][sys_mpy >> 10]
|
629
|
+
except IndexError:
|
630
|
+
arch = "unknown"
|
624
631
|
if arch:
|
625
632
|
info["arch"] = arch
|
626
633
|
# .mpy version.minor
|
@@ -660,7 +667,7 @@ def get_root() -> str: # sourcery skip: use-assigned-variable
|
|
660
667
|
# unix port
|
661
668
|
c = "."
|
662
669
|
r = c
|
663
|
-
for r in [
|
670
|
+
for r in ["/remote", "/sd", "/flash", "/", c, "."]:
|
664
671
|
try:
|
665
672
|
_ = os.stat(r)
|
666
673
|
break
|
@@ -759,6 +766,7 @@ def main():
|
|
759
766
|
|
760
767
|
if __name__ == "__main__" or is_micropython():
|
761
768
|
if not file_exists("no_auto_stubber.txt"):
|
769
|
+
print(f"createstubs.py: {__version__}")
|
762
770
|
try:
|
763
771
|
gc.threshold(4 * 1024) # type: ignore
|
764
772
|
gc.enable()
|