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