micropython-stubber 1.16.2__py3-none-any.whl → 1.17.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.
Files changed (55) hide show
  1. {micropython_stubber-1.16.2.dist-info → micropython_stubber-1.17.0.dist-info}/METADATA +2 -1
  2. {micropython_stubber-1.16.2.dist-info → micropython_stubber-1.17.0.dist-info}/RECORD +54 -54
  3. stubber/__init__.py +1 -1
  4. stubber/basicgit.py +27 -33
  5. stubber/board/board_info.csv +137 -103
  6. stubber/board/createstubs.py +222 -189
  7. stubber/board/createstubs_db.py +284 -214
  8. stubber/board/createstubs_db_min.py +286 -265
  9. stubber/board/createstubs_db_mpy.mpy +0 -0
  10. stubber/board/createstubs_lvgl.py +171 -113
  11. stubber/board/createstubs_lvgl_min.py +738 -275
  12. stubber/board/createstubs_lvgl_mpy.mpy +0 -0
  13. stubber/board/createstubs_mem.py +237 -174
  14. stubber/board/createstubs_mem_min.py +263 -247
  15. stubber/board/createstubs_mem_mpy.mpy +0 -0
  16. stubber/board/createstubs_min.py +242 -227
  17. stubber/board/createstubs_mpy.mpy +0 -0
  18. stubber/board/fw_info.py +135 -0
  19. stubber/board/modulelist.txt +1 -2
  20. stubber/codemod/_partials/__init__.py +1 -1
  21. stubber/codemod/_partials/db_main.py +90 -72
  22. stubber/codemod/_partials/modules_reader.py +29 -17
  23. stubber/codemod/board.py +2 -4
  24. stubber/codemod/enrich.py +1 -1
  25. stubber/commands/build_cmd.py +6 -4
  26. stubber/commands/get_docstubs_cmd.py +6 -11
  27. stubber/commands/get_frozen_cmd.py +6 -11
  28. stubber/commands/switch_cmd.py +6 -4
  29. stubber/data/board_info.csv +134 -101
  30. stubber/data/board_info.json +1357 -901
  31. stubber/freeze/freeze_manifest_2.py +2 -1
  32. stubber/freeze/get_frozen.py +28 -13
  33. stubber/minify.py +56 -43
  34. stubber/publish/candidates.py +15 -23
  35. stubber/publish/defaults.py +2 -2
  36. stubber/publish/merge_docstubs.py +5 -7
  37. stubber/publish/missing_class_methods.py +2 -2
  38. stubber/publish/pathnames.py +2 -2
  39. stubber/publish/publish.py +2 -1
  40. stubber/publish/stubpackage.py +20 -40
  41. stubber/rst/lookup.py +9 -7
  42. stubber/rst/reader.py +2 -1
  43. stubber/stubber.py +5 -6
  44. stubber/update_fallback.py +3 -1
  45. stubber/update_module_list.py +1 -1
  46. stubber/utils/__init__.py +1 -1
  47. stubber/utils/config.py +7 -9
  48. stubber/utils/post.py +1 -1
  49. stubber/utils/repos.py +10 -7
  50. stubber/utils/versions.py +48 -7
  51. stubber/variants.py +3 -3
  52. stubber/board/logging.py +0 -99
  53. {micropython_stubber-1.16.2.dist-info → micropython_stubber-1.17.0.dist-info}/LICENSE +0 -0
  54. {micropython_stubber-1.16.2.dist-info → micropython_stubber-1.17.0.dist-info}/WHEEL +0 -0
  55. {micropython_stubber-1.16.2.dist-info → micropython_stubber-1.17.0.dist-info}/entry_points.txt +0 -0
@@ -1,304 +1,325 @@
1
- v='stubber'
2
- u='{}/{}'
3
- t='method'
4
- s='function'
5
- r='bool'
6
- q='str'
7
- p='float'
8
- o='int'
9
- n=NameError
10
- m=sorted
11
- l=MemoryError
12
- k=NotImplementedError
13
- b=',\n'
14
- a='dict'
15
- Z='list'
16
- Y='tuple'
17
- X='micropython'
18
- W=str
19
- V=repr
20
- T='_'
21
- S=KeyError
22
- R=IndexError
23
- Q=dir
24
- P=ImportError
25
- O='family'
26
- N=print
27
- M=True
28
- L=len
29
- K='board'
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=TypeError
12
+ r=Exception
13
+ q=KeyError
14
+ p=sorted
15
+ o=MemoryError
16
+ n=NotImplementedError
17
+ j=',\n'
18
+ i='modules.json'
19
+ h='{}/{}'
20
+ g='w'
21
+ f='dict'
22
+ e='list'
23
+ d='tuple'
24
+ c=str
25
+ b=repr
26
+ W='-preview'
27
+ V='-'
28
+ U='board'
29
+ T=IndexError
30
+ S=print
31
+ R=True
32
+ Q='family'
33
+ P=len
34
+ O=ImportError
35
+ N=dir
36
+ M=open
37
+ K='port'
30
38
  J='.'
31
- I=open
32
- H=AttributeError
39
+ I=AttributeError
40
+ H=False
33
41
  G='/'
34
- F=False
35
42
  E=None
36
- D='version'
37
- A=OSError
38
- C=''
39
- import gc as B,os,sys
40
- from ujson import dumps as c
41
- try:from machine import reset
42
- except P:pass
43
- try:from collections import OrderedDict as d
44
- except P:from ucollections import OrderedDict as d
45
- __version__='v1.16.2'
46
- w=2
47
- x=2
48
- e=[J,'/lib','/sd/lib','/flash/lib','lib']
43
+ D=OSError
44
+ C='version'
45
+ B=''
46
+ import gc as F,os,sys
49
47
  from time import sleep
48
+ try:from ujson import dumps
49
+ except:from json import dumps
50
+ try:from machine import reset
51
+ except O:pass
52
+ try:from collections import OrderedDict as k
53
+ except O:from ucollections import OrderedDict as k
54
+ __version__='v1.17.0'
55
+ A3=2
56
+ A4=2
57
+ A5=['lib','/lib','/sd/lib','/flash/lib',J]
58
+ class L:
59
+ INFO=20;WARNING=30;ERROR=40;level=INFO;prnt=S
60
+ @staticmethod
61
+ def getLogger(name):return L()
62
+ @classmethod
63
+ def basicConfig(A,level):A.level=level
64
+ def info(A,msg):
65
+ if A.level<=L.INFO:A.prnt('INFO :',msg)
66
+ def warning(A,msg):
67
+ if A.level<=L.WARNING:A.prnt('WARN :',msg)
68
+ def error(A,msg):
69
+ if A.level<=L.ERROR:A.prnt('ERROR :',msg)
70
+ A=L.getLogger(t)
71
+ L.basicConfig(level=L.INFO)
50
72
  class Stubber:
51
- def __init__(C,path=E,firmware_id=E):
52
- D=firmware_id
73
+ def __init__(B,path=E,firmware_id=E):
74
+ C=firmware_id
53
75
  try:
54
- if os.uname().release=='1.13.0'and os.uname().version<'v1.13-103':raise k('MicroPython 1.13.0 cannot be stubbed')
55
- except H:pass
56
- C._report=[];C.info=_info();B.collect()
57
- if D:C._fwid=D.lower()
58
- elif C.info[O]==X:C._fwid='{family}-{ver}-{port}-{board}'.format(**C.info)
59
- else:C._fwid='{family}-{ver}-{port}'.format(**C.info)
60
- C._start_free=B.mem_free()
76
+ if os.uname().release=='1.13.0'and os.uname().version<'v1.13-103':raise n('MicroPython 1.13.0 cannot be stubbed')
77
+ except I:pass
78
+ B.info=_info();A.info('Port: {}'.format(B.info[K]));A.info('Board: {}'.format(B.info[U]));F.collect()
79
+ if C:B._fwid=C.lower()
80
+ elif B.info[Q]==u:B._fwid='{family}-v{version}-{port}-{board}'.format(**B.info).rstrip(V)
81
+ else:B._fwid='{family}-v{version}-{port}'.format(**B.info)
82
+ B._start_free=F.mem_free()
61
83
  if path:
62
84
  if path.endswith(G):path=path[:-1]
63
85
  else:path=get_root()
64
- C.path='{}/stubs/{}'.format(path,C.flat_fwid).replace('//',G)
65
- try:f(path+G)
66
- except A:N('error creating stub folder {}'.format(path))
67
- C.problematic=['upip','upysh','webrepl_setup','http_client','http_client_ssl','http_server','http_server_ssl'];C.excluded=['webrepl','_webrepl','port_diag','example_sub_led.py','example_pub_button.py'];C.modules=[]
86
+ B.path='{}/stubs/{}'.format(path,B.flat_fwid).replace('//',G)
87
+ try:X(path+G)
88
+ except D:A.error('error creating stub folder {}'.format(path))
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
68
90
  def get_obj_attributes(L,item_instance):
69
- I=item_instance;D=[];J=[]
70
- for A in Q(I):
71
- if A.startswith(T)and not A in L.modules:continue
91
+ H=item_instance;C=[];K=[]
92
+ for A in N(H):
93
+ if A.startswith('__')and not A in L.modules:continue
72
94
  try:
73
- E=getattr(I,A)
74
- try:F=V(type(E)).split("'")[1]
75
- except R:F=C
76
- if F in{o,p,q,r,Y,Z,a}:G=1
77
- elif F in{s,t}:G=2
78
- elif F in'class':G=3
95
+ D=getattr(H,A)
96
+ try:E=b(type(D)).split("'")[1]
97
+ except T:E=B
98
+ if E in{v,w,x,y,d,e,f}:G=1
99
+ elif E in{z,A0}:G=2
100
+ elif E in'class':G=3
79
101
  else:G=4
80
- D.append((A,V(E),V(type(E)),E,G))
81
- except H as K:J.append("Couldn't get attribute '{}' from object '{}', Err: {}".format(A,I,K))
82
- except l as K:sleep(1);reset()
83
- D=m([A for A in D if not A[0].startswith('__')],key=lambda x:x[4]);B.collect();return D,J
84
- def add_modules(A,modules):A.modules=m(set(A.modules)|set(modules))
85
- def create_all_stubs(A):
86
- B.collect()
87
- for C in A.modules:A.create_one_stub(C)
102
+ C.append((A,b(D),b(type(D)),D,G))
103
+ except I as J:K.append("Couldn't get attribute '{}' from object '{}', Err: {}".format(A,H,J))
104
+ except o as J:S('MemoryError: {}'.format(J));sleep(1);reset()
105
+ C=p([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=p(set(A.modules)|set(modules))
107
+ def create_all_stubs(B):
108
+ A.info('Start micropython-stubber {} on {}'.format(__version__,B._fwid));B.report_start();F.collect()
109
+ for C in B.modules:B.create_one_stub(C)
110
+ B.report_end();A.info('Finally done')
88
111
  def create_one_stub(C,module_name):
89
- D=module_name
90
- if D in C.problematic:return F
91
- if D in C.excluded:return F
92
- H='{}/{}.py'.format(C.path,D.replace(J,G));B.collect();E=F
93
- try:E=C.create_module_stub(D,H)
94
- except A:return F
95
- B.collect();return E
112
+ B=module_name
113
+ if B in C.problematic:A.warning('Skip module: {:<25} : Known problematic'.format(B));return H
114
+ if B in C.excluded:A.warning('Skip module: {:<25} : Excluded'.format(B));return H
115
+ I='{}/{}.pyi'.format(C.path,B.replace(J,G));F.collect();E=H
116
+ try:E=C.create_module_stub(B,I)
117
+ except D:return H
118
+ F.collect();return E
96
119
  def create_module_stub(K,module_name,file_name=E):
97
- H=file_name;D=module_name
98
- if H is E:O=D.replace(J,T)+'.py';H=K.path+G+O
99
- else:O=H.split(G)[-1]
100
- if G in D:D=D.replace(G,J)
101
- L=E
102
- try:L=__import__(D,E,E,'*');U=B.mem_free()
103
- except P:return F
104
- f(H)
105
- with I(H,'w')as N:Q=W(K.info).replace('OrderedDict(',C).replace('})','}');R='"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(D,K._fwid,Q,__version__);N.write(R);N.write('from typing import Any\nfrom _typeshed import Incomplete\n\n');K.write_object_stub(N,L,D,C)
106
- K._report.append('{{"module": "{}", "file": "{}"}}'.format(D,H.replace('\\',G)))
107
- if D not in{'os','sys','logging','gc'}:
108
- try:del L
109
- except(A,S):pass
110
- try:del sys.modules[D]
111
- except S:pass
112
- B.collect();return M
120
+ I=file_name;C=module_name
121
+ if I is E:L=C.replace(J,'_')+'.pyi';I=K.path+G+L
122
+ else:L=I.split(G)[-1]
123
+ if G in C:C=C.replace(G,J)
124
+ N=E
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))
126
+ except O:return H
127
+ X(I)
128
+ with M(I,g)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)
129
+ K.report_add(C,I)
130
+ if C not in{'os','sys','logging','gc'}:
131
+ try:del N
132
+ except(D,q):A.warning('could not del new_module')
133
+ F.collect();return R
113
134
  def write_object_stub(K,fp,object_expr,obj_name,indent,in_class=0):
114
- d='{0}{1} = {2} # type: {3}\n';c='bound_method';b='Incomplete';Q=in_class;P=object_expr;O='Exception';H=fp;E=indent;B.collect()
115
- if P in K.problematic:return
116
- R,M=K.get_obj_attributes(P)
117
- if M:N(M)
118
- for(F,J,G,T,f)in R:
119
- if F in['classmethod','staticmethod','BaseException',O]:continue
120
- if F[0].isdigit():continue
121
- if G=="<class 'type'>"and L(E)<=x*4:
122
- U=C;V=F.endswith(O)or F.endswith('Error')or F in['KeyboardInterrupt','StopIteration','SystemExit']
123
- if V:U=O
124
- D='\n{}class {}({}):\n'.format(E,F,U)
125
- if V:D+=E+' ...\n';H.write(D);return
126
- H.write(D);K.write_object_stub(H,T,'{0}.{1}'.format(obj_name,F),E+' ',Q+1);D=E+' def __init__(self, *argv, **kwargs) -> None:\n';D+=E+' ...\n\n';H.write(D)
127
- elif any(A in G for A in[t,s,'closure']):
128
- W=b;X=C
129
- if Q>0:X='self, '
130
- if c in G or c in J:D='{}@classmethod\n'.format(E)+'{}def {}(cls, *args, **kwargs) -> {}:\n'.format(E,F,W)
131
- else:D='{}def {}({}*args, **kwargs) -> {}:\n'.format(E,F,X,W)
132
- D+=E+' ...\n\n';H.write(D)
133
- elif G=="<class 'module'>":0
134
- elif G.startswith("<class '"):
135
- I=G[8:-2];D=C
136
- if I in[q,o,p,r,'bytearray','bytes']:D=d.format(E,F,J,I)
137
- elif I in[a,Z,Y]:e={a:'{}',Z:'[]',Y:'()'};D=d.format(E,F,e[I],I)
138
- else:
139
- if I not in['object','set','frozenset']:I=b
140
- D='{0}{1} : {2} ## {3} = {4}\n'.format(E,F,I,G,J)
141
- H.write(D)
142
- else:H.write("# all other, type = '{0}'\n".format(G));H.write(E+F+' # type: Incomplete\n')
143
- del R;del M
144
- try:del F,J,G,T
145
- except(A,S,n):pass
135
+ X='generator';W='{0}{1}: {3} = {2}\n';V='bound_method';U='Incomplete';N=in_class;M='Exception';L=object_expr;I=fp;D=indent;F.collect()
136
+ if L in K.problematic:A.warning('SKIPPING problematic module:{}'.format(L));return
137
+ Y,O=K.get_obj_attributes(L)
138
+ if O:A.error(O)
139
+ for(E,J,H,Z,b)in Y:
140
+ if E in['classmethod','staticmethod','BaseException',M]:continue
141
+ if E[0].isdigit():A.warning('NameError: invalid name {}'.format(E));continue
142
+ if H=="<class 'type'>"and P(D)<=A4*4:
143
+ Q=B;R=E.endswith(M)or E.endswith('Error')or E in['KeyboardInterrupt','StopIteration','SystemExit']
144
+ if R:Q=M
145
+ C='\n{}class {}({}):\n'.format(D,E,Q)
146
+ if R:C+=D+' ...\n';I.write(C);continue
147
+ I.write(C);K.write_object_stub(I,Z,'{0}.{1}'.format(obj_name,E),D+' ',N+1);C=D+' def __init__(self, *argv, **kwargs) -> None:\n';C+=D+' ...\n\n';I.write(C)
148
+ elif any(A in H for A in[A0,z,'closure']):
149
+ S=U;T=B
150
+ if N>0:T='self, '
151
+ if V in H or V in J:C='{}@classmethod\n'.format(D)+'{}def {}(cls, *args, **kwargs) -> {}:\n'.format(D,E,S)
152
+ else:C='{}def {}({}*args, **kwargs) -> {}:\n'.format(D,E,T,S)
153
+ C+=D+' ...\n\n';I.write(C)
154
+ elif H=="<class 'module'>":0
155
+ elif H.startswith("<class '"):
156
+ G=H[8:-2];C=B
157
+ if G in(x,v,w,y,'bytearray','bytes'):C=W.format(D,E,J,G)
158
+ elif G in(f,e,d):a={f:'{}',e:'[]',d:'()'};C=W.format(D,E,a[G],G)
159
+ elif G in('object','set','frozenset','Pin',X):
160
+ if G==X:G='Generator'
161
+ C='{0}{1}: {2} ## = {4}\n'.format(D,E,G,H,J)
162
+ else:G=U;C='{0}{1}: {2} ## {3} = {4}\n'.format(D,E,G,H,J)
163
+ I.write(C)
164
+ else:I.write("# all other, type = '{0}'\n".format(H));I.write(D+E+' # type: Incomplete\n')
146
165
  @property
147
166
  def flat_fwid(self):
148
167
  A=self._fwid;B=' .()/\\:$'
149
- for C in B:A=A.replace(C,T)
168
+ for C in B:A=A.replace(C,'_')
150
169
  return A
151
170
  def clean(C,path=E):
152
171
  if path is E:path=C.path
153
- try:os.stat(path);D=os.listdir(path)
154
- except(A,H):return
155
- for F in D:
156
- B=u.format(path,F)
172
+ A.info('Clean/remove files in folder: {}'.format(path))
173
+ try:os.stat(path);F=os.listdir(path)
174
+ except(D,I):return
175
+ for G in F:
176
+ B=h.format(path,G)
157
177
  try:os.remove(B)
158
- except A:
178
+ except D:
159
179
  try:C.clean(B);os.rmdir(B)
160
- except A:pass
161
- def report(C,filename='modules.json'):
162
- G=u.format(C.path,filename);B.collect()
180
+ except D:pass
181
+ def report_start(B,filename=i):
182
+ H='firmware';B._json_name=h.format(B.path,filename);B._json_first=R;X(B._json_name);A.info('Report file: {}'.format(B._json_name));F.collect()
183
+ try:
184
+ with M(B._json_name,g)as G:G.write('{');G.write(dumps({H:B.info})[1:-1]);G.write(j);G.write(dumps({t:{C:__version__},'stubtype':H})[1:-1]);G.write(j);G.write('"modules" :[\n')
185
+ except D as I:A.error(A1);B._json_name=E;raise I
186
+ def report_add(B,module_name,stub_file):
187
+ if not B._json_name:raise r(A2)
163
188
  try:
164
- with I(G,'w')as D:
165
- C.write_json_header(D);E=M
166
- for H in C._report:C.write_json_node(D,H,E);E=F
167
- C.write_json_end(D)
168
- J=C._start_free-B.mem_free()
169
- except A:N('Failed to create the report.')
170
- def write_json_header(B,f):A='firmware';f.write('{');f.write(c({A:B.info})[1:-1]);f.write(b);f.write(c({v:{D:__version__},'stubtype':A})[1:-1]);f.write(b);f.write('"modules" :[\n')
171
- def write_json_node(A,f,n,first):
172
- if not first:f.write(b)
173
- f.write(n)
174
- def write_json_end(A,f):f.write('\n]}')
175
- def f(path):
176
- B=D=0
189
+ with M(B._json_name,'a')as C:
190
+ if not B._json_first:C.write(j)
191
+ else:B._json_first=H
192
+ E='{{"module": "{}", "file": "{}"}}'.format(module_name,stub_file.replace('\\',G));C.write(E)
193
+ except D:A.error(A1)
194
+ def report_end(B):
195
+ if not B._json_name:raise r(A2)
196
+ with M(B._json_name,'a')as C:C.write('\n]}')
197
+ A.info('Path: {}'.format(B.path))
198
+ def X(path):
199
+ B=E=0
177
200
  while B!=-1:
178
- B=path.find(G,D)
201
+ B=path.find(G,E)
179
202
  if B!=-1:
180
203
  C=path[0]if B==0 else path[:B]
181
- try:H=os.stat(C)
182
- except A as E:
183
- if E.args[0]==w:
204
+ try:I=os.stat(C)
205
+ except D as F:
206
+ if F.args[0]==A3:
184
207
  try:os.mkdir(C)
185
- except A as F:N('failed to create folder {}'.format(C));raise F
186
- D=B+1
187
- def U(s):
188
- A=' on '
189
- if not s:return C
190
- if A in s:s=s.split(A,1)[0]
191
- return s.split('-')[1]if'-'in s else C
208
+ except D as H:A.error('failed to create folder {}'.format(C));raise H
209
+ E=B+1
210
+ def Y(s):
211
+ C=' on '
212
+ if not s:return B
213
+ s=s.split(C,1)[0]if C in s else s
214
+ if s.startswith('v'):
215
+ if not V in s:return B
216
+ A=s.split(V)[1];return A
217
+ if not W in s:return B
218
+ A=s.split(W)[1].split(J)[1];return A
192
219
  def _info():
193
- n='ev3-pybricks';m='pycom';l='pycopy';k='unix';j='win32';i='GENERIC';f='arch';c='cpu';b='ver';Y='with';I='mpy';G='port';F='build';A=d({O:sys.implementation.name,D:C,F:C,b:C,G:sys.platform,K:i,c:C,I:C,f:C})
194
- if A[G].startswith('pyb'):A[G]='stm32'
195
- elif A[G]==j:A[G]='windows'
196
- elif A[G]=='linux':A[G]=k
197
- try:A[D]=J.join([W(A)for A in sys.implementation.version])
198
- except H:pass
199
- try:Z=sys.implementation._machine if'_machine'in Q(sys.implementation)else os.uname().machine;A[K]=Z.strip();A[c]=Z.split(Y)[1].strip();A[I]=sys.implementation._mpy if'_mpy'in Q(sys.implementation)else sys.implementation.mpy if I in Q(sys.implementation)else C
200
- except(H,R):pass
201
- B.collect()
202
- for N in[A+'/board_info.csv'for A in e]:
203
- if h(N):
204
- M=A[K].strip()
205
- if g(A,M,N):break
206
- if Y in M:
207
- M=M.split(Y)[0].strip()
208
- if g(A,M,N):break
209
- A[K]=i
210
- A[K]=A[K].replace(' ',T);B.collect()
220
+ Z='ev3-pybricks';X='pycom';V='pycopy';S='unix';R='win32';P='arch';M='cpu';L='ver';F='mpy';D='build';A=k({Q:sys.implementation.name,C:B,D:B,L:B,K:sys.platform,U:'UNKNOWN',M:B,F:B,P:B})
221
+ if A[K].startswith('pyb'):A[K]='stm32'
222
+ elif A[K]==R:A[K]='windows'
223
+ elif A[K]=='linux':A[K]=S
224
+ try:A[C]=A6(sys.implementation.version)
225
+ except I:pass
226
+ try:H=sys.implementation._machine if'_machine'in N(sys.implementation)else os.uname().machine;A[U]=H;A[M]=H.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
227
+ except(I,T):pass
228
+ A[U]=A7()
211
229
  try:
212
- A[F]=U(os.uname()[3])
213
- if not A[F]:A[F]=U(os.uname()[2])
214
- if not A[F]and';'in sys.version:A[F]=U(sys.version.split(';')[1])
215
- except(H,R):pass
216
- if A[F]and L(A[F])>5:A[F]=C
217
- if A[D]==C and sys.platform not in(k,j):
218
- try:o=os.uname();A[D]=o.release
219
- except(R,H,TypeError):pass
220
- for(p,q,r)in[(l,l,'const'),(m,m,'FAT'),(n,'pybricks.hubs','EV3Brick')]:
221
- try:s=__import__(q,E,E,r);A[O]=p;del s;break
222
- except(P,S):pass
223
- if A[O]==n:A['release']='2.0.0'
224
- if A[O]==X:
225
- 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]
226
- if I in A and A[I]:
227
- V=int(A[I]);a=[E,'x86','x64','armv6','armv6m','armv7m','armv7em','armv7emsp','armv7emdp','xtensa','xtensawin'][V>>10]
228
- if a:A[f]=a
229
- A[I]='v{}.{}'.format(V&255,V>>8&3)
230
- A[b]=f"v{A[D]}-{A[F]}"if A[F]else f"v{A[D]}";return A
231
- def g(info,board_descr,filename):
232
- with I(filename,'r')as B:
233
- while 1:
234
- A=B.readline()
235
- if not A:break
236
- C,D=A.split(',')[0].strip(),A.split(',')[1].strip()
237
- if C==board_descr:info[K]=D;return M
238
- return F
239
- def get_root():
240
- try:B=os.getcwd()
241
- except(A,H):B=J
242
- C=B
243
- for C in[B,'/sd','/flash',G,J]:
244
- try:D=os.stat(C);break
245
- except A:continue
230
+ if'uname'in N(os):
231
+ A[D]=Y(os.uname()[3])
232
+ if not A[D]:A[D]=Y(os.uname()[2])
233
+ elif C in N(sys):A[D]=Y(sys.version)
234
+ except(I,T,s):pass
235
+ if A[C]==B and sys.platform not in(S,R):
236
+ try:a=os.uname();A[C]=a.release
237
+ except(T,I,s):pass
238
+ for(b,c,d)in[(V,V,'const'),(X,X,'FAT'),(Z,'pybricks.hubs','EV3Brick')]:
239
+ try:e=__import__(c,E,E,d);A[Q]=b;del e;break
240
+ except(O,q):pass
241
+ if A[Q]==Z:A['release']='2.0.0'
242
+ if A[Q]==u:
243
+ A[C]
244
+ 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]
245
+ if F in A and A[F]:
246
+ G=int(A[F]);J=[E,'x86','x64','armv6','armv6m','armv7m','armv7em','armv7emsp','armv7emdp','xtensa','xtensawin'][G>>10]
247
+ if J:A[P]=J
248
+ A[F]='v{}.{}'.format(G&255,G>>8&3)
249
+ if A[D]and not A[C].endswith(W):A[C]=A[C]+W
250
+ A[L]=f"{A[C]}-{A[D]}"if A[D]else f"{A[C]}";return A
251
+ def A6(version):
252
+ A=version;B=J.join([c(A)for A in A[:3]])
253
+ if P(A)>3 and A[3]:B+=V+A[3]
254
+ return B
255
+ def A7():
256
+ try:from boardname import BOARDNAME as C;A.info('Found BOARDNAME: {}'.format(C))
257
+ except O:A.warning('BOARDNAME not found');C=B
246
258
  return C
247
- def h(filename):
259
+ def get_root():
260
+ try:A=os.getcwd()
261
+ except(D,I):A=J
262
+ B=A
263
+ for B in[A,'/sd','/flash',G,J]:
264
+ try:C=os.stat(B);break
265
+ except D:continue
266
+ return B
267
+ def Z(filename):
248
268
  try:
249
- if os.stat(filename)[0]>>14:return M
250
- return F
251
- except A:return F
252
- def i():sys.exit(1)
269
+ if os.stat(filename)[0]>>14:return R
270
+ return H
271
+ except D:return H
272
+ def l():S("-p, --path path to store the stubs in, defaults to '.'");sys.exit(1)
253
273
  def read_path():
254
- path=C
255
- if L(sys.argv)==3:
274
+ path=B
275
+ if P(sys.argv)==3:
256
276
  A=sys.argv[1].lower()
257
277
  if A in('--path','-p'):path=sys.argv[2]
258
- else:i()
259
- elif L(sys.argv)==2:i()
278
+ else:l()
279
+ elif P(sys.argv)==2:l()
260
280
  return path
261
- def j():
262
- try:A=bytes('abc',encoding='utf8');B=j.__module__;return F
263
- except(k,H):return M
264
- def main():
265
- K='failed';G='modulelist.done';import machine as O
266
- try:C=I(G,'r+b');N=M
267
- except A:C=I(G,'w+b');N=F
268
- stubber=Stubber(path=read_path())
269
- if not N:stubber.clean()
270
- y(stubber);D={}
271
- try:
272
- with I(G)as C:
273
- for E in C.read().split('\n'):
274
- E=E.strip();B.collect()
275
- if L(E)>0:P,Q=E.split('=',1);D[P]=Q
276
- except(A,SyntaxError):pass
277
- B.collect();R=[A for A in stubber.modules if A not in D.keys()];B.collect()
278
- for H in R:
279
- J=F
280
- try:J=stubber.create_one_stub(H)
281
- except l:O.reset()
282
- B.collect();D[H]=W(stubber._report[-1]if J else K)
283
- with I(G,'a')as C:C.write('{}={}\n'.format(H,'ok'if J else K))
284
- if D:stubber._report=[A for(B,A)in D.items()if A!=K];stubber.report()
285
- def y(stubber):
286
- E='/modulelist.txt';stubber.modules=[]
287
- for D in e:
281
+ def m():
282
+ try:A=bytes('abc',encoding='utf8');B=m.__module__;return H
283
+ except(n,I):return R
284
+ a='modulelist.done'
285
+ def A8(skip=0):
286
+ for E in A5:
287
+ B=E+'/modulelist.txt'
288
+ if not Z(B):continue
288
289
  try:
289
- with I(D+E)as F:
290
- N('DEBUG: list of modules: '+D+E)
291
- for C in F.read().split('\n'):
292
- C=C.strip()
293
- if L(C)>0 and C[0]!='#':stubber.modules.append(C)
294
- B.collect();break
295
- except A:pass
296
- if not stubber.modules:stubber.modules=[X];_log.warn('Could not find modulelist.txt, using default modules')
297
- B.collect()
298
- if __name__=='__main__'or j():
299
- try:z=logging.getLogger(v);logging.basicConfig(level=logging.INFO)
300
- except n:pass
301
- if not h('no_auto_stubber.txt'):
302
- try:B.threshold(4*1024);B.enable()
290
+ with M(B)as F:
291
+ C=0
292
+ while R:
293
+ A=F.readline().strip()
294
+ if not A:break
295
+ if P(A)>0 and A[0]=='#':continue
296
+ C+=1
297
+ if C<skip:continue
298
+ yield A
299
+ break
300
+ except D:pass
301
+ def A9(done):
302
+ with M(a,g)as A:A.write(c(done)+'\n')
303
+ def AA():
304
+ A=0
305
+ try:
306
+ with M(a)as B:A=int(B.readline().strip())
307
+ except D:pass
308
+ return A
309
+ def main():
310
+ import machine as D;C=Z(a)
311
+ if C:A.info('Continue from last run')
312
+ else:A.info('Starting new run')
313
+ stubber=Stubber(path=read_path());B=0
314
+ if not C:stubber.clean();stubber.report_start(i)
315
+ else:B=AA();stubber._json_name=h.format(stubber.path,i)
316
+ for E in A8(B):
317
+ try:stubber.create_one_stub(E)
318
+ except o:D.reset()
319
+ F.collect();B+=1;A9(B)
320
+ S('All modules have been processed, Finalizing report');stubber.report_end()
321
+ if __name__=='__main__'or m():
322
+ if not Z('no_auto_stubber.txt'):
323
+ try:F.threshold(4*1024);F.enable()
303
324
  except BaseException:pass
304
325
  main()
Binary file