Skip to content

Commit 31b0684

Browse files
committed
update variants
Signed-off-by: Jos Verlinde <[email protected]>
1 parent 23a22b6 commit 31b0684

26 files changed

+564
-443
lines changed

mip/v5/createstubs.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
except ImportError:
2121
from ucollections import OrderedDict # type: ignore
2222

23-
__version__ = "v1.12.2"
23+
__version__ = "v1.13.4"
2424
ENOENT = 2
2525
_MAX_CLASS_LEVEL = 2 # Max class nesting
2626
LIBS = [".", "/lib", "/sd/lib", "/flash/lib", "lib"]
@@ -183,7 +183,9 @@ def create_module_stub(self, module_name: str, file_name: str = None) -> bool:
183183
ensure_folder(file_name)
184184
with open(file_name, "w") as fp:
185185
# todo: improve header
186-
s = '"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(module_name, self._fwid, self.info, __version__)
186+
s = '"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(
187+
module_name, self._fwid, self.info, __version__
188+
)
187189
fp.write(s)
188190
fp.write("from typing import Any\n\n")
189191
self.write_object_stub(fp, new_module, module_name, "")
@@ -221,6 +223,9 @@ def write_object_stub(self, fp, object_expr: object, obj_name: str, indent: str,
221223
# do not create stubs for these primitives
222224
if item_name in ["classmethod", "staticmethod", "BaseException", "Exception"]:
223225
continue
226+
if item_name[0].isdigit():
227+
self._log.warning("NameError: invalid name {}".format(item_name))
228+
continue
224229
# Class expansion only on first 3 levels (bit of a hack)
225230
if item_type_txt == "<class 'type'>" and len(indent) <= _MAX_CLASS_LEVEL * 4:
226231
self._log.debug("{0}class {1}:".format(indent, item_name))
@@ -271,7 +276,9 @@ def write_object_stub(self, fp, object_expr: object, obj_name: str, indent: str,
271276
first = "self, "
272277
# class method - add function decoration
273278
if "bound_method" in item_type_txt or "bound_method" in item_repr:
274-
s = "{}@classmethod\n".format(indent) + "{}def {}(cls, *args, **kwargs) -> {}:\n".format(indent, item_name, ret)
279+
s = "{}@classmethod\n".format(indent) + "{}def {}(cls, *args, **kwargs) -> {}:\n".format(
280+
indent, item_name, ret
281+
)
275282
else:
276283
s = "{}def {}({}*args, **kwargs) -> {}:\n".format(indent, item_name, first, ret)
277284
s += indent + " ...\n\n"
@@ -283,7 +290,6 @@ def write_object_stub(self, fp, object_expr: object, obj_name: str, indent: str,
283290
pass
284291

285292
elif item_type_txt.startswith("<class '"):
286-
287293
t = item_type_txt[8:-2]
288294
s = ""
289295

@@ -508,7 +514,7 @@ def _info(): # type:() -> dict[str, str]
508514
info["version"]
509515
and info["version"].endswith(".0")
510516
and info["version"] >= "1.10.0" # versions from 1.10.0 to 1.20.0 do not have a micro .0
511-
and info["version"] <= "1.20.0"
517+
and info["version"] <= "1.19.9"
512518
):
513519
# drop the .0 for newer releases
514520
info["version"] = info["version"][:-2]
@@ -623,7 +629,6 @@ def is_micropython() -> bool:
623629

624630

625631
def main():
626-
627632
stubber = Stubber(path=read_path())
628633
# stubber = Stubber(path="/sd")
629634
# Option: Specify a firmware name & version
@@ -868,6 +873,9 @@ def main():
868873
except NameError:
869874
pass
870875
if not file_exists("no_auto_stubber.txt"):
871-
gc.threshold(4 * 1024)
872-
gc.enable()
876+
try:
877+
gc.threshold(4 * 1024)
878+
gc.enable()
879+
except BaseException:
880+
pass
873881
main()

mip/v5/createstubs_db.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
- cross compilation, using mpy-cross, to avoid the compilation step on the micropython device
1919
2020
21-
This variant was generated from createstubs.py by micropython-stubber v1.13.3
21+
This variant was generated from createstubs.py by micropython-stubber v1.13.4
2222
"""
2323
# Copyright (c) 2019-2023 Jos Verlinde
2424
# pylint: disable= invalid-name, missing-function-docstring, import-outside-toplevel, logging-not-lazy
@@ -39,7 +39,7 @@
3939
except ImportError:
4040
from ucollections import OrderedDict # type: ignore
4141

42-
__version__ = "v1.12.2"
42+
__version__ = "v1.13.4"
4343
ENOENT = 2
4444
_MAX_CLASS_LEVEL = 2 # Max class nesting
4545
LIBS = [".", "/lib", "/sd/lib", "/flash/lib", "lib"]
@@ -240,6 +240,9 @@ def write_object_stub(self, fp, object_expr: object, obj_name: str, indent: str,
240240
# do not create stubs for these primitives
241241
if item_name in ["classmethod", "staticmethod", "BaseException", "Exception"]:
242242
continue
243+
if item_name[0].isdigit():
244+
self._log.warning("NameError: invalid name {}".format(item_name))
245+
continue
243246
# Class expansion only on first 3 levels (bit of a hack)
244247
if item_type_txt == "<class 'type'>" and len(indent) <= _MAX_CLASS_LEVEL * 4:
245248
self._log.debug("{0}class {1}:".format(indent, item_name))
@@ -302,7 +305,6 @@ def write_object_stub(self, fp, object_expr: object, obj_name: str, indent: str,
302305
pass
303306

304307
elif item_type_txt.startswith("<class '"):
305-
306308
t = item_type_txt[8:-2]
307309
s = ""
308310

@@ -527,7 +529,7 @@ def _info(): # type:() -> dict[str, str]
527529
info["version"]
528530
and info["version"].endswith(".0")
529531
and info["version"] >= "1.10.0" # versions from 1.10.0 to 1.20.0 do not have a micro .0
530-
and info["version"] <= "1.20.0"
532+
and info["version"] <= "1.19.9"
531533
):
532534
# drop the .0 for newer releases
533535
info["version"] = info["version"][:-2]
@@ -659,21 +661,7 @@ def main():
659661
# Only clean folder if this is a first run
660662
stubber.clean()
661663
# get list of modules to process
662-
stubber.modules = ["micropython"]
663-
for p in LIBS:
664-
try:
665-
with open(p + "/modulelist.txt") as f:
666-
print("Debug: list of modules: " + p + "/modulelist.txt")
667-
stubber.modules = [] # avoid duplicates
668-
for line in f.read().split("\n"):
669-
line = line.strip()
670-
if len(line) > 0 and line[0] != "#":
671-
stubber.modules.append(line)
672-
gc.collect()
673-
break
674-
except OSError:
675-
pass
676-
gc.collect()
664+
get_modulelist(stubber)
677665
# remove the ones that are already done
678666
modules_done = {} # type: dict[str, str]
679667
try:
@@ -714,6 +702,26 @@ def main():
714702
stubber.report()
715703

716704

705+
def get_modulelist(stubber):
706+
stubber.modules = [] # avoid duplicates
707+
for p in LIBS:
708+
try:
709+
with open(p + "/modulelist.txt") as f:
710+
print("DEBUG: list of modules: " + p + "/modulelist.txt")
711+
for line in f.read().split("\n"):
712+
line = line.strip()
713+
if len(line) > 0 and line[0] != "#":
714+
stubber.modules.append(line)
715+
gc.collect()
716+
break
717+
except OSError:
718+
pass
719+
if not stubber.modules:
720+
stubber.modules = ["micropython"]
721+
_log.warn("Could not find modulelist.txt, using default modules")
722+
gc.collect()
723+
724+
717725
if __name__ == "__main__" or is_micropython():
718726
try:
719727
_log = logging.getLogger("stubber")
@@ -722,6 +730,9 @@ def main():
722730
except NameError:
723731
pass
724732
if not file_exists("no_auto_stubber.txt"):
725-
gc.threshold(4 * 1024)
726-
gc.enable()
733+
try:
734+
gc.threshold(4 * 1024)
735+
gc.enable()
736+
except BaseException:
737+
pass
727738
main()

mip/v5/createstubs_db_min.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
except Q:pass
4242
try:from collections import OrderedDict as c
4343
except Q:from ucollections import OrderedDict as c
44-
__version__='v1.12.2'
44+
__version__='v1.13.4'
4545
v=2
4646
w=2
4747
d=[M,'/lib','/sd/lib','/flash/lib','lib']
@@ -116,6 +116,7 @@ def write_object_stub(M,fp,object_expr,obj_name,indent,in_class=0):
116116
if N:I(N)
117117
for (F,K,G,S,f) in R:
118118
if F in['classmethod','staticmethod','BaseException',O]:continue
119+
if F[0].isdigit():continue
119120
if G=="<class 'type'>"and L(E)<=w*4:
120121
U=C;V=F.endswith(O)or F.endswith('Error')or F in['KeyboardInterrupt','StopIteration','SystemExit']
121122
if V:U=O
@@ -218,7 +219,7 @@ def _info():
218219
except (Q,T):pass
219220
if A[O]==j:A['release']='2.0.0'
220221
if A[O]==W:
221-
if A[D]and A[D].endswith('.0')and A[D]>='1.10.0'and A[D]<='1.20.0':A[D]=A[D][:-2]
222+
if A[D]and A[D].endswith('.0')and A[D]>='1.10.0'and A[D]<='1.19.9':A[D]=A[D][:-2]
222223
if G in A and A[G]:
223224
N=int(A[G]);Y=[E,'x86','x64','armv6','armv6m','armv7m','armv7em','armv7emsp','armv7emdp','xtensa','xtensawin'][N>>10]
224225
if Y:A[b]=Y
@@ -259,36 +260,41 @@ def i():
259260
except (j,H):return N
260261
def main():
261262
K='failed';G='modulelist.done';import machine as O
262-
try:D=J(G,'r+b');M=N
263-
except A:D=J(G,'w+b');M=F
263+
try:C=J(G,'r+b');M=N
264+
except A:C=J(G,'w+b');M=F
264265
stubber=Stubber(path=read_path())
265266
if not M:stubber.clean()
266-
stubber.modules=[W]
267-
for P in d:
268-
try:
269-
with J(P+'/modulelist.txt')as D:
270-
stubber.modules=[]
271-
for C in D.read().split('\n'):
272-
C=C.strip()
273-
if L(C)>0 and C[0]!='#':stubber.modules.append(C)
274-
B.collect();break
275-
except A:pass
276-
B.collect();E={}
267+
x(stubber);D={}
277268
try:
278-
with J(G)as D:
279-
for C in D.read().split('\n'):
280-
C=C.strip();B.collect()
281-
if L(C)>0:Q,R=C.split('=',1);E[Q]=R
269+
with J(G)as C:
270+
for E in C.read().split('\n'):
271+
E=E.strip();B.collect()
272+
if L(E)>0:P,Q=E.split('=',1);D[P]=Q
282273
except (A,SyntaxError):pass
283-
B.collect();S=[A for A in stubber.modules if A not in E.keys()];B.collect()
284-
for H in S:
274+
B.collect();R=[A for A in stubber.modules if A not in D.keys()];B.collect()
275+
for H in R:
285276
I=F
286277
try:I=stubber.create_one_stub(H)
287278
except k:O.reset()
288-
B.collect();E[H]=str(stubber._report[-1]if I else K)
289-
with J(G,'a')as D:D.write('{}={}\n'.format(H,'ok'if I else K))
290-
if E:stubber._report=[A for(B,A)in E.items()if A!=K];stubber.report()
279+
B.collect();D[H]=str(stubber._report[-1]if I else K)
280+
with J(G,'a')as C:C.write('{}={}\n'.format(H,'ok'if I else K))
281+
if D:stubber._report=[A for(B,A)in D.items()if A!=K];stubber.report()
282+
def x(stubber):
283+
stubber.modules=[]
284+
for D in d:
285+
try:
286+
with J(D+'/modulelist.txt')as E:
287+
for C in E.read().split('\n'):
288+
C=C.strip()
289+
if L(C)>0 and C[0]!='#':stubber.modules.append(C)
290+
B.collect();break
291+
except A:pass
292+
if not stubber.modules:stubber.modules=[W];_log.warn('Could not find modulelist.txt, using default modules')
293+
B.collect()
291294
if __name__=='__main__'or i():
292295
try:logging.basicConfig(level=logging.INFO)
293296
except m:pass
294-
if not g('no_auto_stubber.txt'):B.threshold(4*1024);B.enable();main()
297+
if not g('no_auto_stubber.txt'):
298+
try:B.threshold(4*1024);B.enable()
299+
except BaseException:pass
300+
main()

mip/v5/createstubs_db_mpy.mpy

152 Bytes
Binary file not shown.

mip/v5/createstubs_lvgl.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
Note that the stubs can be very large, and it may be best to directly store them on an SD card if your device supports this.
55
6-
This variant was generated from createstubs.py by micropython-stubber v1.13.3
6+
This variant was generated from createstubs.py by micropython-stubber v1.13.4
77
"""
88
# Copyright (c) 2019-2023 Jos Verlinde
99
# pylint: disable= invalid-name, missing-function-docstring, import-outside-toplevel, logging-not-lazy
@@ -24,7 +24,7 @@
2424
except ImportError:
2525
from ucollections import OrderedDict # type: ignore
2626

27-
__version__ = "v1.12.2"
27+
__version__ = "v1.13.4"
2828
ENOENT = 2
2929
_MAX_CLASS_LEVEL = 2 # Max class nesting
3030
LIBS = [".", "/lib", "/sd/lib", "/flash/lib", "lib"]
@@ -225,6 +225,9 @@ def write_object_stub(self, fp, object_expr: object, obj_name: str, indent: str,
225225
# do not create stubs for these primitives
226226
if item_name in ["classmethod", "staticmethod", "BaseException", "Exception"]:
227227
continue
228+
if item_name[0].isdigit():
229+
self._log.warning("NameError: invalid name {}".format(item_name))
230+
continue
228231
# Class expansion only on first 3 levels (bit of a hack)
229232
if item_type_txt == "<class 'type'>" and len(indent) <= _MAX_CLASS_LEVEL * 4:
230233
self._log.debug("{0}class {1}:".format(indent, item_name))
@@ -287,7 +290,6 @@ def write_object_stub(self, fp, object_expr: object, obj_name: str, indent: str,
287290
pass
288291

289292
elif item_type_txt.startswith("<class '"):
290-
291293
t = item_type_txt[8:-2]
292294
s = ""
293295

@@ -512,7 +514,7 @@ def _info(): # type:() -> dict[str, str]
512514
info["version"]
513515
and info["version"].endswith(".0")
514516
and info["version"] >= "1.10.0" # versions from 1.10.0 to 1.20.0 do not have a micro .0
515-
and info["version"] <= "1.20.0"
517+
and info["version"] <= "1.19.9"
516518
):
517519
# drop the .0 for newer releases
518520
info["version"] = info["version"][:-2]
@@ -664,6 +666,9 @@ def main():
664666
except NameError:
665667
pass
666668
if not file_exists("no_auto_stubber.txt"):
667-
gc.threshold(4 * 1024)
668-
gc.enable()
669+
try:
670+
gc.threshold(4 * 1024)
671+
gc.enable()
672+
except BaseException:
673+
pass
669674
main()

0 commit comments

Comments
 (0)