micropython-stubber 1.24.1__py3-none-any.whl → 1.24.4__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.24.1.dist-info → micropython_stubber-1.24.4.dist-info}/METADATA +9 -29
- micropython_stubber-1.24.4.dist-info/RECORD +107 -0
- {micropython_stubber-1.24.1.dist-info → micropython_stubber-1.24.4.dist-info}/WHEEL +1 -1
- stubber/__init__.py +1 -1
- stubber/board/createstubs.py +44 -38
- stubber/board/createstubs_db.py +17 -12
- stubber/board/createstubs_db_min.py +63 -63
- stubber/board/createstubs_db_mpy.mpy +0 -0
- stubber/board/createstubs_mem.py +17 -12
- stubber/board/createstubs_mem_min.py +99 -99
- stubber/board/createstubs_mem_mpy.mpy +0 -0
- stubber/board/createstubs_min.py +111 -112
- stubber/board/createstubs_mpy.mpy +0 -0
- stubber/board/modulelist.txt +27 -27
- stubber/codemod/board.py +1 -1
- stubber/codemod/enrich.py +13 -13
- stubber/codemod/merge_docstub.py +83 -53
- stubber/codemod/visitors/type_helpers.py +143 -41
- stubber/commands/enrich_folder_cmd.py +17 -17
- stubber/commands/get_docstubs_cmd.py +27 -9
- stubber/commands/get_frozen_cmd.py +1 -0
- stubber/commands/merge_cmd.py +2 -4
- stubber/merge_config.py +5 -36
- stubber/minify.py +3 -3
- stubber/modcat.py +118 -0
- stubber/publish/merge_docstubs.py +22 -5
- stubber/publish/stubpackage.py +33 -28
- stubber/rst/lookup.py +6 -23
- stubber/rst/reader.py +8 -13
- stubber/stubs_from_docs.py +2 -1
- stubber/tools/manifestfile.py +2 -1
- stubber/{cst_transformer.py → typing_collector.py} +36 -4
- micropython_stubber-1.24.1.dist-info/RECORD +0 -161
- mpflash/README.md +0 -220
- mpflash/libusb_flash.ipynb +0 -203
- mpflash/mpflash/__init__.py +0 -0
- mpflash/mpflash/add_firmware.py +0 -98
- mpflash/mpflash/ask_input.py +0 -236
- mpflash/mpflash/basicgit.py +0 -324
- mpflash/mpflash/bootloader/__init__.py +0 -2
- mpflash/mpflash/bootloader/activate.py +0 -60
- mpflash/mpflash/bootloader/detect.py +0 -82
- mpflash/mpflash/bootloader/manual.py +0 -101
- mpflash/mpflash/bootloader/micropython.py +0 -12
- mpflash/mpflash/bootloader/touch1200.py +0 -36
- mpflash/mpflash/cli_download.py +0 -129
- mpflash/mpflash/cli_flash.py +0 -224
- mpflash/mpflash/cli_group.py +0 -111
- mpflash/mpflash/cli_list.py +0 -87
- mpflash/mpflash/cli_main.py +0 -39
- mpflash/mpflash/common.py +0 -217
- mpflash/mpflash/config.py +0 -44
- mpflash/mpflash/connected.py +0 -96
- mpflash/mpflash/download.py +0 -364
- mpflash/mpflash/downloaded.py +0 -138
- mpflash/mpflash/errors.py +0 -9
- mpflash/mpflash/flash/__init__.py +0 -55
- mpflash/mpflash/flash/esp.py +0 -59
- mpflash/mpflash/flash/stm32.py +0 -19
- mpflash/mpflash/flash/stm32_dfu.py +0 -104
- mpflash/mpflash/flash/uf2/__init__.py +0 -88
- mpflash/mpflash/flash/uf2/boardid.py +0 -15
- mpflash/mpflash/flash/uf2/linux.py +0 -136
- mpflash/mpflash/flash/uf2/macos.py +0 -42
- mpflash/mpflash/flash/uf2/uf2disk.py +0 -12
- mpflash/mpflash/flash/uf2/windows.py +0 -43
- mpflash/mpflash/flash/worklist.py +0 -170
- mpflash/mpflash/list.py +0 -106
- mpflash/mpflash/logger.py +0 -41
- mpflash/mpflash/mpboard_id/__init__.py +0 -98
- mpflash/mpflash/mpboard_id/add_boards.py +0 -262
- mpflash/mpflash/mpboard_id/board.py +0 -37
- mpflash/mpflash/mpboard_id/board_id.py +0 -90
- mpflash/mpflash/mpboard_id/board_info.zip +0 -0
- mpflash/mpflash/mpboard_id/store.py +0 -48
- mpflash/mpflash/mpremoteboard/__init__.py +0 -271
- mpflash/mpflash/mpremoteboard/mpy_fw_info.py +0 -152
- mpflash/mpflash/mpremoteboard/runner.py +0 -140
- mpflash/mpflash/vendor/board_database.py +0 -185
- mpflash/mpflash/vendor/click_aliases.py +0 -91
- mpflash/mpflash/vendor/dfu.py +0 -165
- mpflash/mpflash/vendor/pydfu.py +0 -605
- mpflash/mpflash/vendor/readme.md +0 -12
- mpflash/mpflash/versions.py +0 -123
- mpflash/poetry.lock +0 -2603
- mpflash/pyproject.toml +0 -66
- mpflash/stm32_udev_rules.md +0 -63
- stubber/codemod/test_enrich.py +0 -87
- {micropython_stubber-1.24.1.dist-info → micropython_stubber-1.24.4.dist-info}/LICENSE +0 -0
- {micropython_stubber-1.24.1.dist-info → micropython_stubber-1.24.4.dist-info}/entry_points.txt +0 -0
@@ -38,8 +38,8 @@ L='port'
|
|
38
38
|
K='.'
|
39
39
|
I=AttributeError
|
40
40
|
H=False
|
41
|
-
G=
|
42
|
-
E=
|
41
|
+
G=None
|
42
|
+
E='/'
|
43
43
|
D=OSError
|
44
44
|
C='version'
|
45
45
|
B=''
|
@@ -53,8 +53,9 @@ try:from collections import OrderedDict as l
|
|
53
53
|
except O:from ucollections import OrderedDict as l
|
54
54
|
__version__='v1.24.0'
|
55
55
|
A3=2
|
56
|
-
A4=
|
57
|
-
A5=
|
56
|
+
A4=44
|
57
|
+
A5=2
|
58
|
+
A6=['lib','/lib','/sd/lib','/flash/lib',K]
|
58
59
|
class J:
|
59
60
|
DEBUG=10;INFO=20;WARNING=30;ERROR=40;level=INFO;prnt=P
|
60
61
|
@staticmethod
|
@@ -72,7 +73,7 @@ class J:
|
|
72
73
|
A=J.getLogger(t)
|
73
74
|
J.basicConfig(level=J.INFO)
|
74
75
|
class Stubber:
|
75
|
-
def __init__(B,path=
|
76
|
+
def __init__(B,path=B,firmware_id=B):
|
76
77
|
C=firmware_id
|
77
78
|
try:
|
78
79
|
if os.uname().release=='1.13.0'and os.uname().version<'v1.13-103':raise o('MicroPython 1.13.0 cannot be stubbed')
|
@@ -83,12 +84,12 @@ class Stubber:
|
|
83
84
|
else:B._fwid='{family}-v{version}-{port}'.format(**B.info)
|
84
85
|
B._start_free=F.mem_free()
|
85
86
|
if path:
|
86
|
-
if path.endswith(
|
87
|
+
if path.endswith(E):path=path[:-1]
|
87
88
|
else:path=get_root()
|
88
|
-
B.path='{}/stubs/{}'.format(path,B.flat_fwid).replace('//',
|
89
|
-
try:X(path+
|
89
|
+
B.path='{}/stubs/{}'.format(path,B.flat_fwid).replace('//',E)
|
90
|
+
try:X(path+E)
|
90
91
|
except D:A.error('error creating stub folder {}'.format(path))
|
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=
|
92
|
+
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=G;B._json_first=H
|
92
93
|
def get_obj_attributes(L,item_instance):
|
93
94
|
H=item_instance;C=[];K=[]
|
94
95
|
for A in N(H):
|
@@ -114,39 +115,39 @@ class Stubber:
|
|
114
115
|
B=module_name
|
115
116
|
if B in C.problematic:A.warning('Skip module: {:<25} : Known problematic'.format(B));return H
|
116
117
|
if B in C.excluded:A.warning('Skip module: {:<25} : Excluded'.format(B));return H
|
117
|
-
I='{}/{}.pyi'.format(C.path,B.replace(K,
|
118
|
-
try:
|
118
|
+
I='{}/{}.pyi'.format(C.path,B.replace(K,E));F.collect();G=H
|
119
|
+
try:G=C.create_module_stub(B,I)
|
119
120
|
except D:return H
|
120
|
-
F.collect();return
|
121
|
-
def create_module_stub(J,module_name,file_name=
|
121
|
+
F.collect();return G
|
122
|
+
def create_module_stub(J,module_name,file_name=G):
|
122
123
|
I=file_name;C=module_name
|
123
|
-
if I is
|
124
|
-
else:L=I.split(
|
125
|
-
if
|
126
|
-
N=
|
127
|
-
try:N=__import__(C,
|
124
|
+
if I is G:L=C.replace(K,'_')+'.pyi';I=J.path+E+L
|
125
|
+
else:L=I.split(E)[-1]
|
126
|
+
if E in C:C=C.replace(E,K)
|
127
|
+
N=G
|
128
|
+
try:N=__import__(C,G,G,'*');Q=F.mem_free();A.info('Stub module: {:<25} to file: {:<70} mem:{:>5}'.format(C,L,Q))
|
128
129
|
except O:return H
|
129
130
|
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
|
+
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, Final, Generator\nfrom _typeshed import Incomplete\n\n');J.write_object_stub(P,N,C,B)
|
131
132
|
J.report_add(C,I)
|
132
133
|
if C not in{'os','sys','logging','gc'}:
|
133
134
|
try:del N
|
134
135
|
except(D,r):A.warning('could not del new_module')
|
135
136
|
F.collect();return T
|
136
137
|
def write_object_stub(L,fp,object_expr,obj_name,indent,in_class=0):
|
137
|
-
|
138
|
+
Y=' at ...>';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()
|
138
139
|
if M in L.problematic:A.warning('SKIPPING problematic module:{}'.format(M));return
|
139
|
-
|
140
|
+
Z,P=L.get_obj_attributes(M)
|
140
141
|
if P:A.error(P)
|
141
|
-
for(C,H,I,
|
142
|
+
for(C,H,I,a,c)in Z:
|
142
143
|
if C in['classmethod','staticmethod','BaseException',N]:continue
|
143
144
|
if C[0].isdigit():A.warning('NameError: invalid name {}'.format(C));continue
|
144
|
-
if I=="<class 'type'>"and R(E)<=
|
145
|
+
if I=="<class 'type'>"and R(E)<=A5*4:
|
145
146
|
Q=B;S=C.endswith(N)or C.endswith('Error')or C in['KeyboardInterrupt','StopIteration','SystemExit']
|
146
147
|
if S:Q=N
|
147
148
|
D='\n{}class {}({}):\n'.format(E,C,Q)
|
148
149
|
if S:D+=E+' ...\n';J.write(D);continue
|
149
|
-
J.write(D);L.write_object_stub(J,
|
150
|
+
J.write(D);L.write_object_stub(J,a,'{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
151
|
elif any(A in I for A in[A0,z,'closure']):
|
151
152
|
T=V;U=B
|
152
153
|
if O>0:U='self, '
|
@@ -159,14 +160,13 @@ class Stubber:
|
|
159
160
|
if G in(x,v,w,y,'bytearray','bytes'):
|
160
161
|
if C.upper()==C:D='{0}{1}: Final[{3}] = {2}\n'.format(E,C,H,G)
|
161
162
|
else:D=X.format(E,C,H,G)
|
162
|
-
elif G in(g,f,e):
|
163
|
-
elif G in('object','set','frozenset','Pin',
|
164
|
-
|
165
|
-
D='{0}{1}: {2} ## = {4}\n'.format(E,C,G,I,H)
|
163
|
+
elif G in(g,f,e):b={g:'{}',f:'[]',e:'()'};D=X.format(E,C,b[G],G)
|
164
|
+
elif G in('object','set','frozenset','Pin'):D='{0}{1}: {2} ## = {4}\n'.format(E,C,G,I,H)
|
165
|
+
elif G=='generator':G='Generator';D='{0}def {1}(*args, **kwargs) -> Generator: ## = {4}\n{0} ...\n\n'.format(E,C,G,I,H)
|
166
166
|
else:
|
167
167
|
G=V
|
168
|
-
if K in H:H=H.split(K)[0]+
|
169
|
-
if K in H:H=H.split(K)[0]+
|
168
|
+
if K in H:H=H.split(K)[0]+Y
|
169
|
+
if K in H:H=H.split(K)[0]+Y
|
170
170
|
D='{0}{1}: {2} ## {3} = {4}\n'.format(E,C,G,I,H)
|
171
171
|
J.write(D)
|
172
172
|
else:J.write("# all other, type = '{0}'\n".format(I));J.write(E+C+' # type: Incomplete\n')
|
@@ -175,13 +175,13 @@ class Stubber:
|
|
175
175
|
A=self._fwid;B=' .()/\\:$'
|
176
176
|
for C in B:A=A.replace(C,'_')
|
177
177
|
return A
|
178
|
-
def clean(C,path=
|
179
|
-
if path
|
178
|
+
def clean(C,path=B):
|
179
|
+
if not path:path=C.path
|
180
180
|
A.info('Clean/remove files in folder: {}'.format(path))
|
181
|
-
try:os.stat(path);
|
181
|
+
try:os.stat(path);E=os.listdir(path)
|
182
182
|
except(D,I):return
|
183
|
-
for
|
184
|
-
B=i.format(path,
|
183
|
+
for F in E:
|
184
|
+
B=i.format(path,F)
|
185
185
|
try:os.remove(B)
|
186
186
|
except D:
|
187
187
|
try:C.clean(B);os.rmdir(B)
|
@@ -189,32 +189,32 @@ class Stubber:
|
|
189
189
|
def report_start(B,filename=j):
|
190
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()
|
191
191
|
try:
|
192
|
-
with M(B._json_name,h)as
|
193
|
-
except D as I:A.error(A1);B._json_name=
|
192
|
+
with M(B._json_name,h)as E:E.write('{');E.write(dumps({H:B.info})[1:-1]);E.write(k);E.write(dumps({t:{C:__version__},'stubtype':H})[1:-1]);E.write(k);E.write('"modules" :[\n')
|
193
|
+
except D as I:A.error(A1);B._json_name=G;raise I
|
194
194
|
def report_add(B,module_name,stub_file):
|
195
195
|
if not B._json_name:raise s(A2)
|
196
196
|
try:
|
197
197
|
with M(B._json_name,'a')as C:
|
198
198
|
if not B._json_first:C.write(k)
|
199
199
|
else:B._json_first=H
|
200
|
-
|
200
|
+
F='{{"module": "{}", "file": "{}"}}'.format(module_name,stub_file.replace('\\',E));C.write(F)
|
201
201
|
except D:A.error(A1)
|
202
202
|
def report_end(B):
|
203
203
|
if not B._json_name:raise s(A2)
|
204
204
|
with M(B._json_name,'a')as C:C.write('\n]}')
|
205
205
|
A.info('Path: {}'.format(B.path))
|
206
206
|
def X(path):
|
207
|
-
B=
|
207
|
+
B=F=0
|
208
208
|
while B!=-1:
|
209
|
-
B=path.find(
|
209
|
+
B=path.find(E,F)
|
210
210
|
if B!=-1:
|
211
211
|
C=path[0]if B==0 else path[:B]
|
212
212
|
try:I=os.stat(C)
|
213
|
-
except D as
|
214
|
-
if
|
213
|
+
except D as G:
|
214
|
+
if G.args[0]in[A3,A4]:
|
215
215
|
try:A.debug('Create folder {}'.format(C));os.mkdir(C)
|
216
216
|
except D as H:A.error('failed to create folder {}'.format(C));raise H
|
217
|
-
|
217
|
+
F=B+1
|
218
218
|
def Y(s):
|
219
219
|
C=' on '
|
220
220
|
if not s:return B
|
@@ -225,18 +225,18 @@ def Y(s):
|
|
225
225
|
if not W in s:return B
|
226
226
|
A=s.split(W)[1].split(K)[1];return A
|
227
227
|
def _info():
|
228
|
-
a='ev3-pybricks';Z='pycom';X='pycopy';V='unix';T='win32';R='arch';P='cpu';M='ver';
|
228
|
+
a='ev3-pybricks';Z='pycom';X='pycopy';V='unix';T='win32';R='arch';P='cpu';M='ver';E='mpy';D='build'
|
229
229
|
try:J=sys.implementation[0]
|
230
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,
|
231
|
+
A=l({S:J,C:B,D:B,M:B,L:sys.platform,U:'UNKNOWN',P:B,E:B,R:B})
|
232
232
|
if A[L].startswith('pyb'):A[L]='stm32'
|
233
233
|
elif A[L]==T:A[L]='windows'
|
234
234
|
elif A[L]=='linux':A[L]=V
|
235
|
-
try:A[C]=
|
235
|
+
try:A[C]=A7(sys.implementation.version)
|
236
236
|
except I:pass
|
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[
|
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[E]=sys.implementation._mpy if'_mpy'in N(sys.implementation)else sys.implementation.mpy if E in N(sys.implementation)else B
|
238
238
|
except(I,Q):pass
|
239
|
-
A[U]=
|
239
|
+
A[U]=A8()
|
240
240
|
try:
|
241
241
|
if'uname'in N(os):
|
242
242
|
A[D]=Y(os.uname()[3])
|
@@ -247,25 +247,25 @@ def _info():
|
|
247
247
|
try:b=os.uname();A[C]=b.release
|
248
248
|
except(Q,I,d):pass
|
249
249
|
for(c,e,f)in[(X,X,'const'),(Z,Z,'FAT'),(a,'pybricks.hubs','EV3Brick')]:
|
250
|
-
try:g=__import__(e,
|
250
|
+
try:g=__import__(e,G,G,f);A[S]=c;del g;break
|
251
251
|
except(O,r):pass
|
252
252
|
if A[S]==a:A['release']='2.0.0'
|
253
253
|
if A[S]==u:
|
254
254
|
A[C]
|
255
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]
|
256
|
-
if
|
257
|
-
|
258
|
-
try:H=[
|
256
|
+
if E in A and A[E]:
|
257
|
+
F=int(A[E])
|
258
|
+
try:H=[G,'x86','x64','armv6','armv6m','armv7m','armv7em','armv7emsp','armv7emdp','xtensa','xtensawin','rv32imc'][F>>10]
|
259
259
|
except Q:H='unknown'
|
260
260
|
if H:A[R]=H
|
261
|
-
A[
|
261
|
+
A[E]='v{}.{}'.format(F&255,F>>8&3)
|
262
262
|
if A[D]and not A[C].endswith(W):A[C]=A[C]+W
|
263
263
|
A[M]=f"{A[C]}-{A[D]}"if A[D]else f"{A[C]}";return A
|
264
|
-
def
|
264
|
+
def A7(version):
|
265
265
|
A=version;B=K.join([c(A)for A in A[:3]])
|
266
266
|
if R(A)>3 and A[3]:B+=V+A[3]
|
267
267
|
return B
|
268
|
-
def
|
268
|
+
def A8():
|
269
269
|
try:from boardname import BOARDNAME as C;A.info('Found BOARDNAME: {}'.format(C))
|
270
270
|
except O:A.warning('BOARDNAME not found');C=B
|
271
271
|
return C
|
@@ -273,7 +273,7 @@ def get_root():
|
|
273
273
|
try:A=os.getcwd()
|
274
274
|
except(D,I):A=K
|
275
275
|
B=A
|
276
|
-
for B in['/remote','/sd','/flash',
|
276
|
+
for B in['/remote','/sd','/flash',E,A,K]:
|
277
277
|
try:C=os.stat(B);break
|
278
278
|
except D:continue
|
279
279
|
return B
|
@@ -295,8 +295,8 @@ def n():
|
|
295
295
|
try:A=bytes('abc',encoding='utf8');B=n.__module__;return H
|
296
296
|
except(o,I):return T
|
297
297
|
a='modulelist.done'
|
298
|
-
def
|
299
|
-
for E in
|
298
|
+
def A9(skip=0):
|
299
|
+
for E in A6:
|
300
300
|
B=E+'/modulelist.txt'
|
301
301
|
if not Z(B):continue
|
302
302
|
try:
|
@@ -311,9 +311,9 @@ def A8(skip=0):
|
|
311
311
|
yield A
|
312
312
|
break
|
313
313
|
except D:pass
|
314
|
-
def
|
314
|
+
def AA(done):
|
315
315
|
with M(a,h)as A:A.write(c(done)+'\n')
|
316
|
-
def
|
316
|
+
def AB():
|
317
317
|
A=0
|
318
318
|
try:
|
319
319
|
with M(a)as B:A=int(B.readline().strip())
|
@@ -325,11 +325,11 @@ def main():
|
|
325
325
|
else:A.info('Starting new run')
|
326
326
|
stubber=Stubber(path=read_path());B=0
|
327
327
|
if not C:stubber.clean();stubber.report_start(j)
|
328
|
-
else:B=
|
329
|
-
for E in
|
328
|
+
else:B=AB();stubber._json_name=i.format(stubber.path,j)
|
329
|
+
for E in A9(B):
|
330
330
|
try:stubber.create_one_stub(E)
|
331
331
|
except p:D.reset()
|
332
|
-
F.collect();B+=1;
|
332
|
+
F.collect();B+=1;AA(B)
|
333
333
|
P('All modules have been processed, Finalizing report');stubber.report_end()
|
334
334
|
if __name__=='__main__'or n():
|
335
335
|
if not Z('no_auto_stubber.txt'):
|
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.24.
|
12
|
+
This variant was generated from createstubs.py by micropython-stubber v1.24.3
|
13
13
|
"""
|
14
14
|
|
15
15
|
# Copyright (c) 2019-2024 Jos Verlinde
|
@@ -35,7 +35,8 @@ except ImportError:
|
|
35
35
|
from ucollections import OrderedDict # type: ignore
|
36
36
|
|
37
37
|
__version__ = "v1.24.0"
|
38
|
-
ENOENT = 2
|
38
|
+
ENOENT = 2 # on most ports
|
39
|
+
ENOMESSAGE = 44 # on pyscript
|
39
40
|
_MAX_CLASS_LEVEL = 2 # Max class nesting
|
40
41
|
LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
|
41
42
|
|
@@ -82,7 +83,7 @@ logging.basicConfig(level=logging.INFO)
|
|
82
83
|
class Stubber:
|
83
84
|
"Generate stubs for modules in firmware"
|
84
85
|
|
85
|
-
def __init__(self, path: str =
|
86
|
+
def __init__(self, path: str = "", firmware_id: str = ""): # type: ignore
|
86
87
|
try:
|
87
88
|
if os.uname().release == "1.13.0" and os.uname().version < "v1.13-103": # type: ignore
|
88
89
|
raise NotImplementedError("MicroPython 1.13.0 cannot be stubbed")
|
@@ -241,7 +242,7 @@ class Stubber:
|
|
241
242
|
info_ = str(self.info).replace("OrderedDict(", "").replace("})", "}")
|
242
243
|
s = '"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(module_name, self._fwid, info_, __version__)
|
243
244
|
fp.write(s)
|
244
|
-
fp.write("from __future__ import annotations\nfrom typing import Any, Generator\nfrom _typeshed import Incomplete\n\n")
|
245
|
+
fp.write("from __future__ import annotations\nfrom typing import Any, Final, Generator\nfrom _typeshed import Incomplete\n\n")
|
245
246
|
self.write_object_stub(fp, new_module, module_name, "")
|
246
247
|
|
247
248
|
self.report_add(module_name, file_name)
|
@@ -360,12 +361,16 @@ class Stubber:
|
|
360
361
|
s = "{0}{1}: {3} = {2}\n".format(indent, item_name, ev[t], t)
|
361
362
|
else:
|
362
363
|
# something else
|
363
|
-
if t in ("object", "set", "frozenset", "Pin"
|
364
|
+
if t in ("object", "set", "frozenset", "Pin"): # "FileIO"
|
364
365
|
# https://docs.python.org/3/tutorial/classes.html#item_instance-objects
|
365
366
|
# use these types for the attribute
|
366
|
-
if t == "generator":
|
367
|
-
t = "Generator"
|
368
367
|
s = "{0}{1}: {2} ## = {4}\n".format(indent, item_name, t, item_type_txt, item_repr)
|
368
|
+
elif t == "generator":
|
369
|
+
# either a normal or async Generator function
|
370
|
+
t = "Generator"
|
371
|
+
s = "{0}def {1}(*args, **kwargs) -> Generator: ## = {4}\n{0} ...\n\n".format(
|
372
|
+
indent, item_name, t, item_type_txt, item_repr
|
373
|
+
)
|
369
374
|
else:
|
370
375
|
# Requires Python 3.6 syntax, which is OK for the stubs/pyi
|
371
376
|
t = "Incomplete"
|
@@ -400,9 +405,9 @@ class Stubber:
|
|
400
405
|
s = s.replace(c, "_")
|
401
406
|
return s
|
402
407
|
|
403
|
-
def clean(self, path: str =
|
408
|
+
def clean(self, path: str = ""): # type: ignore
|
404
409
|
"Remove all files from the stub folder"
|
405
|
-
if path
|
410
|
+
if not path:
|
406
411
|
path = self.path
|
407
412
|
log.info("Clean/remove files in folder: {}".format(path))
|
408
413
|
try:
|
@@ -483,7 +488,7 @@ def ensure_folder(path: str):
|
|
483
488
|
_ = os.stat(p)
|
484
489
|
except OSError as e:
|
485
490
|
# folder does not exist
|
486
|
-
if e.args[0]
|
491
|
+
if e.args[0] in [ENOENT, ENOMESSAGE]:
|
487
492
|
try:
|
488
493
|
log.debug("Create folder {}".format(p))
|
489
494
|
os.mkdir(p)
|
@@ -712,11 +717,11 @@ def is_micropython() -> bool:
|
|
712
717
|
|
713
718
|
# b) https://docs.micropython.org/en/latest/genrst/builtin_types.html#bytes-with-keywords-not-implemented
|
714
719
|
# Micropython: NotImplementedError
|
715
|
-
b = bytes("abc", encoding="utf8") # type: ignore
|
720
|
+
b = bytes("abc", encoding="utf8") # type: ignore
|
716
721
|
|
717
722
|
# c) https://docs.micropython.org/en/latest/genrst/core_language.html#function-objects-do-not-have-the-module-attribute
|
718
723
|
# Micropython: AttributeError
|
719
|
-
c = is_micropython.__module__ # type: ignore
|
724
|
+
c = is_micropython.__module__ # type: ignore
|
720
725
|
return False
|
721
726
|
except (NotImplementedError, AttributeError):
|
722
727
|
return True
|