micropython-stubber 1.23.3__py3-none-any.whl → 1.24.1__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.3.dist-info → micropython_stubber-1.24.1.dist-info}/METADATA +29 -11
- {micropython_stubber-1.23.3.dist-info → micropython_stubber-1.24.1.dist-info}/RECORD +68 -65
- {micropython_stubber-1.23.3.dist-info → micropython_stubber-1.24.1.dist-info}/WHEEL +1 -1
- mpflash/README.md +2 -2
- mpflash/mpflash/basicgit.py +22 -2
- mpflash/mpflash/common.py +23 -13
- mpflash/mpflash/downloaded.py +10 -2
- mpflash/mpflash/flash/esp.py +1 -1
- 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/mpremoteboard/__init__.py +13 -8
- mpflash/mpflash/vendor/board_database.py +185 -0
- mpflash/mpflash/vendor/readme.md +10 -1
- mpflash/mpflash/versions.py +28 -40
- mpflash/poetry.lock +1147 -231
- mpflash/pyproject.toml +4 -3
- stubber/__init__.py +1 -1
- stubber/board/createstubs.py +76 -34
- stubber/board/createstubs_db.py +34 -25
- stubber/board/createstubs_db_min.py +90 -83
- stubber/board/createstubs_db_mpy.mpy +0 -0
- stubber/board/createstubs_mem.py +34 -25
- stubber/board/createstubs_mem_min.py +123 -116
- stubber/board/createstubs_mem_mpy.mpy +0 -0
- stubber/board/createstubs_min.py +154 -145
- stubber/board/createstubs_mpy.mpy +0 -0
- stubber/board/modulelist.txt +16 -0
- stubber/codemod/enrich.py +301 -86
- stubber/codemod/merge_docstub.py +251 -66
- stubber/codemod/test_enrich.py +87 -0
- stubber/codemod/visitors/type_helpers.py +182 -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 +38 -17
- stubber/publish/package.py +32 -18
- stubber/publish/publish.py +8 -8
- stubber/publish/stubpackage.py +117 -50
- stubber/rst/lookup.py +205 -41
- 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.3.dist-info → micropython_stubber-1.24.1.dist-info}/LICENSE +0 -0
- {micropython_stubber-1.23.3.dist-info → micropython_stubber-1.24.1.dist-info}/entry_points.txt +0 -0
@@ -26,16 +26,16 @@ b=repr
|
|
26
26
|
W='-preview'
|
27
27
|
V='-'
|
28
28
|
U='board'
|
29
|
-
T=
|
30
|
-
S=
|
31
|
-
R=
|
32
|
-
Q=
|
33
|
-
P=
|
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='/'
|
@@ -51,33 +51,35 @@ try:from machine import reset
|
|
51
51
|
except O:pass
|
52
52
|
try:from collections import OrderedDict as l
|
53
53
|
except O:from ucollections import OrderedDict as l
|
54
|
-
__version__='v1.
|
54
|
+
__version__='v1.24.0'
|
55
55
|
A3=2
|
56
56
|
A4=2
|
57
|
-
A5=['lib','/lib','/sd/lib','/flash/lib',
|
58
|
-
class
|
59
|
-
INFO=20;WARNING=30;ERROR=40;level=INFO;prnt=
|
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
|
60
60
|
@staticmethod
|
61
|
-
def getLogger(name):return
|
61
|
+
def getLogger(name):return J()
|
62
62
|
@classmethod
|
63
63
|
def basicConfig(A,level):A.level=level
|
64
|
+
def debug(A,msg):
|
65
|
+
if A.level<=J.DEBUG:A.prnt('DEBUG :',msg)
|
64
66
|
def info(A,msg):
|
65
|
-
if A.level<=
|
67
|
+
if A.level<=J.INFO:A.prnt('INFO :',msg)
|
66
68
|
def warning(A,msg):
|
67
|
-
if A.level<=
|
69
|
+
if A.level<=J.WARNING:A.prnt('WARN :',msg)
|
68
70
|
def error(A,msg):
|
69
|
-
if A.level<=
|
70
|
-
A=
|
71
|
-
|
71
|
+
if A.level<=J.ERROR:A.prnt('ERROR :',msg)
|
72
|
+
A=J.getLogger(t)
|
73
|
+
J.basicConfig(level=J.INFO)
|
72
74
|
class Stubber:
|
73
75
|
def __init__(B,path=E,firmware_id=E):
|
74
76
|
C=firmware_id
|
75
77
|
try:
|
76
78
|
if os.uname().release=='1.13.0'and os.uname().version<'v1.13-103':raise o('MicroPython 1.13.0 cannot be stubbed')
|
77
79
|
except I:pass
|
78
|
-
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()
|
79
81
|
if C:B._fwid=C.lower()
|
80
|
-
elif B.info[
|
82
|
+
elif B.info[S]==u:B._fwid='{family}-v{version}-{port}-{board}'.format(**B.info).rstrip(V)
|
81
83
|
else:B._fwid='{family}-v{version}-{port}'.format(**B.info)
|
82
84
|
B._start_free=F.mem_free()
|
83
85
|
if path:
|
@@ -94,14 +96,14 @@ class Stubber:
|
|
94
96
|
try:
|
95
97
|
D=getattr(H,A)
|
96
98
|
try:E=b(type(D)).split("'")[1]
|
97
|
-
except
|
99
|
+
except Q:E=B
|
98
100
|
if E in{v,w,x,y,e,f,g}:G=1
|
99
101
|
elif E in{z,A0}:G=2
|
100
102
|
elif E in'class':G=3
|
101
103
|
else:G=4
|
102
104
|
C.append((A,b(D),b(type(D)),D,G))
|
103
105
|
except I as J:K.append("Couldn't get attribute '{}' from object '{}', Err: {}".format(A,H,J))
|
104
|
-
except p as J:
|
106
|
+
except p as J:P('MemoryError: {}'.format(J));sleep(1);reset()
|
105
107
|
C=q([A for A in C if not A[0].startswith('__')],key=lambda x:x[4]);F.collect();return C,K
|
106
108
|
def add_modules(A,modules):A.modules=q(set(A.modules)|set(modules))
|
107
109
|
def create_all_stubs(B):
|
@@ -112,60 +114,62 @@ class Stubber:
|
|
112
114
|
B=module_name
|
113
115
|
if B in C.problematic:A.warning('Skip module: {:<25} : Known problematic'.format(B));return H
|
114
116
|
if B in C.excluded:A.warning('Skip module: {:<25} : Excluded'.format(B));return H
|
115
|
-
I='{}/{}.pyi'.format(C.path,B.replace(
|
117
|
+
I='{}/{}.pyi'.format(C.path,B.replace(K,G));F.collect();E=H
|
116
118
|
try:E=C.create_module_stub(B,I)
|
117
119
|
except D:return H
|
118
120
|
F.collect();return E
|
119
|
-
def create_module_stub(
|
121
|
+
def create_module_stub(J,module_name,file_name=E):
|
120
122
|
I=file_name;C=module_name
|
121
|
-
if I is E:L=C.replace(
|
123
|
+
if I is E:L=C.replace(K,'_')+'.pyi';I=J.path+G+L
|
122
124
|
else:L=I.split(G)[-1]
|
123
|
-
if G in C:C=C.replace(G,
|
125
|
+
if G in C:C=C.replace(G,K)
|
124
126
|
N=E
|
125
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))
|
126
128
|
except O:return H
|
127
129
|
X(I)
|
128
|
-
with M(I,h)as P:
|
129
|
-
|
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)
|
130
132
|
if C not in{'os','sys','logging','gc'}:
|
131
133
|
try:del N
|
132
134
|
except(D,r):A.warning('could not del new_module')
|
133
|
-
F.collect();return
|
135
|
+
F.collect();return T
|
134
136
|
def write_object_stub(L,fp,object_expr,obj_name,indent,in_class=0):
|
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;
|
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()
|
136
138
|
if M in L.problematic:A.warning('SKIPPING problematic module:{}'.format(M));return
|
137
|
-
a,
|
138
|
-
if
|
139
|
-
for(
|
140
|
-
if
|
141
|
-
if
|
142
|
-
if I=="<class 'type'>"and
|
143
|
-
|
144
|
-
if S:
|
145
|
-
|
146
|
-
if S:
|
147
|
-
J.write(
|
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)
|
148
150
|
elif any(A in I for A in[A0,z,'closure']):
|
149
151
|
T=V;U=B
|
150
152
|
if O>0:U='self, '
|
151
|
-
if W in I or W in H:
|
152
|
-
else:
|
153
|
-
|
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)
|
154
156
|
elif I=="<class 'module'>":0
|
155
157
|
elif I.startswith("<class '"):
|
156
|
-
G=I[8:-2];
|
157
|
-
if G in(x,v,w,y,'bytearray','bytes'):
|
158
|
-
|
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)
|
159
163
|
elif G in('object','set','frozenset','Pin',Y):
|
160
164
|
if G==Y:G='Generator'
|
161
|
-
|
165
|
+
D='{0}{1}: {2} ## = {4}\n'.format(E,C,G,I,H)
|
162
166
|
else:
|
163
167
|
G=V
|
164
168
|
if K in H:H=H.split(K)[0]+Z
|
165
169
|
if K in H:H=H.split(K)[0]+Z
|
166
|
-
|
167
|
-
J.write(
|
168
|
-
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')
|
169
173
|
@property
|
170
174
|
def flat_fwid(self):
|
171
175
|
A=self._fwid;B=' .()/\\:$'
|
@@ -183,7 +187,7 @@ class Stubber:
|
|
183
187
|
try:C.clean(B);os.rmdir(B)
|
184
188
|
except D:pass
|
185
189
|
def report_start(B,filename=j):
|
186
|
-
H='firmware';B._json_name=i.format(B.path,filename);B._json_first=
|
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()
|
187
191
|
try:
|
188
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')
|
189
193
|
except D as I:A.error(A1);B._json_name=E;raise I
|
@@ -208,7 +212,7 @@ def X(path):
|
|
208
212
|
try:I=os.stat(C)
|
209
213
|
except D as F:
|
210
214
|
if F.args[0]==A3:
|
211
|
-
try:os.mkdir(C)
|
215
|
+
try:A.debug('Create folder {}'.format(C));os.mkdir(C)
|
212
216
|
except D as H:A.error('failed to create folder {}'.format(C));raise H
|
213
217
|
E=B+1
|
214
218
|
def Y(s):
|
@@ -219,45 +223,47 @@ def Y(s):
|
|
219
223
|
if not V in s:return B
|
220
224
|
A=s.split(V)[1];return A
|
221
225
|
if not W in s:return B
|
222
|
-
A=s.split(W)[1].split(
|
226
|
+
A=s.split(W)[1].split(K)[1];return A
|
223
227
|
def _info():
|
224
|
-
a='ev3-pybricks';Z='pycom';X='pycopy';V='unix';
|
225
|
-
try:
|
226
|
-
except d:
|
227
|
-
A=l({
|
228
|
-
if A[
|
229
|
-
elif A[
|
230
|
-
elif A[
|
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
|
231
235
|
try:A[C]=A6(sys.implementation.version)
|
232
236
|
except I:pass
|
233
|
-
try:
|
234
|
-
except(I,
|
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
|
235
239
|
A[U]=A7()
|
236
240
|
try:
|
237
241
|
if'uname'in N(os):
|
238
242
|
A[D]=Y(os.uname()[3])
|
239
243
|
if not A[D]:A[D]=Y(os.uname()[2])
|
240
244
|
elif C in N(sys):A[D]=Y(sys.version)
|
241
|
-
except(I,
|
242
|
-
if A[C]==B and sys.platform not in(V,
|
245
|
+
except(I,Q,d):pass
|
246
|
+
if A[C]==B and sys.platform not in(V,T):
|
243
247
|
try:b=os.uname();A[C]=b.release
|
244
|
-
except(
|
248
|
+
except(Q,I,d):pass
|
245
249
|
for(c,e,f)in[(X,X,'const'),(Z,Z,'FAT'),(a,'pybricks.hubs','EV3Brick')]:
|
246
|
-
try:g=__import__(e,E,E,f);A[
|
250
|
+
try:g=__import__(e,E,E,f);A[S]=c;del g;break
|
247
251
|
except(O,r):pass
|
248
|
-
if A[
|
249
|
-
if A[
|
252
|
+
if A[S]==a:A['release']='2.0.0'
|
253
|
+
if A[S]==u:
|
250
254
|
A[C]
|
251
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]
|
252
256
|
if F in A and A[F]:
|
253
|
-
G=int(A[F])
|
254
|
-
|
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
|
255
261
|
A[F]='v{}.{}'.format(G&255,G>>8&3)
|
256
262
|
if A[D]and not A[C].endswith(W):A[C]=A[C]+W
|
257
263
|
A[M]=f"{A[C]}-{A[D]}"if A[D]else f"{A[C]}";return A
|
258
264
|
def A6(version):
|
259
|
-
A=version;B=
|
260
|
-
if
|
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]
|
261
267
|
return B
|
262
268
|
def A7():
|
263
269
|
try:from boardname import BOARDNAME as C;A.info('Found BOARDNAME: {}'.format(C))
|
@@ -265,29 +271,29 @@ def A7():
|
|
265
271
|
return C
|
266
272
|
def get_root():
|
267
273
|
try:A=os.getcwd()
|
268
|
-
except(D,I):A=
|
274
|
+
except(D,I):A=K
|
269
275
|
B=A
|
270
|
-
for B in[
|
276
|
+
for B in['/remote','/sd','/flash',G,A,K]:
|
271
277
|
try:C=os.stat(B);break
|
272
278
|
except D:continue
|
273
279
|
return B
|
274
280
|
def Z(filename):
|
275
281
|
try:
|
276
|
-
if os.stat(filename)[0]>>14:return
|
282
|
+
if os.stat(filename)[0]>>14:return T
|
277
283
|
return H
|
278
284
|
except D:return H
|
279
|
-
def m():
|
285
|
+
def m():P("-p, --path path to store the stubs in, defaults to '.'");sys.exit(1)
|
280
286
|
def read_path():
|
281
287
|
path=B
|
282
|
-
if
|
288
|
+
if R(sys.argv)==3:
|
283
289
|
A=sys.argv[1].lower()
|
284
290
|
if A in('--path','-p'):path=sys.argv[2]
|
285
291
|
else:m()
|
286
|
-
elif
|
292
|
+
elif R(sys.argv)==2:m()
|
287
293
|
return path
|
288
294
|
def n():
|
289
295
|
try:A=bytes('abc',encoding='utf8');B=n.__module__;return H
|
290
|
-
except(o,I):return
|
296
|
+
except(o,I):return T
|
291
297
|
a='modulelist.done'
|
292
298
|
def A8(skip=0):
|
293
299
|
for E in A5:
|
@@ -296,10 +302,10 @@ def A8(skip=0):
|
|
296
302
|
try:
|
297
303
|
with M(B)as F:
|
298
304
|
C=0
|
299
|
-
while
|
305
|
+
while T:
|
300
306
|
A=F.readline().strip()
|
301
307
|
if not A:break
|
302
|
-
if
|
308
|
+
if R(A)>0 and A[0]=='#':continue
|
303
309
|
C+=1
|
304
310
|
if C<skip:continue
|
305
311
|
yield A
|
@@ -324,9 +330,10 @@ def main():
|
|
324
330
|
try:stubber.create_one_stub(E)
|
325
331
|
except p:D.reset()
|
326
332
|
F.collect();B+=1;A9(B)
|
327
|
-
|
333
|
+
P('All modules have been processed, Finalizing report');stubber.report_end()
|
328
334
|
if __name__=='__main__'or n():
|
329
335
|
if not Z('no_auto_stubber.txt'):
|
330
|
-
|
336
|
+
P(f"createstubs.py: {__version__}")
|
337
|
+
try:F.threshold(4096);F.enable()
|
331
338
|
except BaseException:pass
|
332
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,7 +34,7 @@ try:
|
|
34
34
|
except ImportError:
|
35
35
|
from ucollections import OrderedDict # type: ignore
|
36
36
|
|
37
|
-
__version__ = "v1.
|
37
|
+
__version__ = "v1.24.0"
|
38
38
|
ENOENT = 2
|
39
39
|
_MAX_CLASS_LEVEL = 2 # Max class nesting
|
40
40
|
LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
|
@@ -42,7 +42,7 @@ LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
|
|
42
42
|
|
43
43
|
# our own logging module to avoid dependency on and interfering with logging module
|
44
44
|
class logging:
|
45
|
-
|
45
|
+
DEBUG = 10
|
46
46
|
INFO = 20
|
47
47
|
WARNING = 30
|
48
48
|
ERROR = 40
|
@@ -57,9 +57,9 @@ class logging:
|
|
57
57
|
def basicConfig(cls, level):
|
58
58
|
cls.level = level
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
def debug(self, msg):
|
61
|
+
if self.level <= logging.DEBUG:
|
62
|
+
self.prnt("DEBUG :", msg)
|
63
63
|
|
64
64
|
def info(self, msg):
|
65
65
|
if self.level <= logging.INFO:
|
@@ -235,6 +235,7 @@ class Stubber:
|
|
235
235
|
return False
|
236
236
|
|
237
237
|
# Start a new file
|
238
|
+
# log.debug("Create file: {}".format(file_name))
|
238
239
|
ensure_folder(file_name)
|
239
240
|
with open(file_name, "w") as fp:
|
240
241
|
info_ = str(self.info).replace("OrderedDict(", "").replace("})", "}")
|
@@ -348,8 +349,10 @@ class Stubber:
|
|
348
349
|
|
349
350
|
if t in ("str", "int", "float", "bool", "bytearray", "bytes"):
|
350
351
|
# known type: use actual value
|
351
|
-
|
352
|
-
|
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)
|
353
356
|
elif t in ("dict", "list", "tuple"):
|
354
357
|
# dict, list , tuple: use empty value
|
355
358
|
ev = {"dict": "{}", "list": "[]", "tuple": "()"}
|
@@ -482,6 +485,7 @@ def ensure_folder(path: str):
|
|
482
485
|
# folder does not exist
|
483
486
|
if e.args[0] == ENOENT:
|
484
487
|
try:
|
488
|
+
log.debug("Create folder {}".format(p))
|
485
489
|
os.mkdir(p)
|
486
490
|
except OSError as e2:
|
487
491
|
log.error("failed to create folder {}".format(p))
|
@@ -492,7 +496,7 @@ def ensure_folder(path: str):
|
|
492
496
|
|
493
497
|
def _build(s):
|
494
498
|
# extract build from sys.version or os.uname().version if available
|
495
|
-
# sys.version: 'MicroPython v1.
|
499
|
+
# sys.version: 'MicroPython v1.24.0-preview.6.g3d0b6276f'
|
496
500
|
# sys.implementation.version: 'v1.13-103-gb137d064e'
|
497
501
|
if not s:
|
498
502
|
return ""
|
@@ -597,29 +601,33 @@ def _info(): # type:() -> dict[str, str]
|
|
597
601
|
if (
|
598
602
|
info["version"]
|
599
603
|
and info["version"].endswith(".0")
|
600
|
-
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
|
601
605
|
and info["version"] <= "1.19.9"
|
602
606
|
):
|
603
|
-
# versions from 1.10.0 to 1.
|
607
|
+
# versions from 1.10.0 to 1.24.0 do not have a micro .0
|
604
608
|
info["version"] = info["version"][:-2]
|
605
609
|
|
606
610
|
# spell-checker: disable
|
607
611
|
if "mpy" in info and info["mpy"]: # mpy on some v1.11+ builds
|
608
612
|
sys_mpy = int(info["mpy"])
|
609
613
|
# .mpy architecture
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
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"
|
623
631
|
if arch:
|
624
632
|
info["arch"] = arch
|
625
633
|
# .mpy version.minor
|
@@ -659,7 +667,7 @@ def get_root() -> str: # sourcery skip: use-assigned-variable
|
|
659
667
|
# unix port
|
660
668
|
c = "."
|
661
669
|
r = c
|
662
|
-
for r in [
|
670
|
+
for r in ["/remote", "/sd", "/flash", "/", c, "."]:
|
663
671
|
try:
|
664
672
|
_ = os.stat(r)
|
665
673
|
break
|
@@ -758,6 +766,7 @@ def main():
|
|
758
766
|
|
759
767
|
if __name__ == "__main__" or is_micropython():
|
760
768
|
if not file_exists("no_auto_stubber.txt"):
|
769
|
+
print(f"createstubs.py: {__version__}")
|
761
770
|
try:
|
762
771
|
gc.threshold(4 * 1024) # type: ignore
|
763
772
|
gc.enable()
|