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