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,41 +1,41 @@
1
- A3='No report file'
2
- A2='Failed to create the report.'
3
- A1='method'
4
- A0='function'
5
- z='bool'
6
- y='str'
7
- x='float'
8
- w='int'
9
- v='micropython'
10
- u='stubber'
11
- t=Exception
12
- s=KeyError
13
- r=sorted
14
- q=MemoryError
15
- p=NotImplementedError
16
- l=',\n'
17
- k='modules.json'
18
- j='{}/{}'
19
- i='w'
20
- h='dict'
21
- g='list'
22
- f='tuple'
23
- e=TypeError
24
- d=str
25
- c=repr
26
- X='-preview'
27
- W='-'
28
- V='board'
29
- U=IndexError
30
- T=print
31
- R=True
32
- Q='family'
33
- P=len
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=Exception
12
+ r=KeyError
13
+ q=sorted
14
+ p=MemoryError
15
+ o=NotImplementedError
16
+ k=',\n'
17
+ j='modules.json'
18
+ i='{}/{}'
19
+ h='w'
20
+ g='dict'
21
+ f='list'
22
+ e='tuple'
23
+ d=TypeError
24
+ c=str
25
+ b=repr
26
+ W='-preview'
27
+ V='-'
28
+ U='board'
29
+ T=True
30
+ S='family'
31
+ R=len
32
+ Q=IndexError
33
+ P=print
34
34
  O=ImportError
35
35
  N=dir
36
36
  M=open
37
- K='port'
38
- J='.'
37
+ L='port'
38
+ K='.'
39
39
  I=AttributeError
40
40
  H=False
41
41
  G='/'
@@ -49,43 +49,44 @@ try:from ujson import dumps
49
49
  except:from json import dumps
50
50
  try:from machine import reset
51
51
  except O:pass
52
- try:from collections import OrderedDict as m
53
- except O:from ucollections import OrderedDict as m
54
- __version__='v1.23.2'
55
- S=__version__.rsplit(J,1)[0]
52
+ try:from collections import OrderedDict as l
53
+ except O:from ucollections import OrderedDict as l
54
+ __version__='v1.24.0'
55
+ A3=2
56
56
  A4=2
57
- A5=2
58
- A6=['lib','/lib','/sd/lib','/flash/lib',J]
59
- class L:
60
- INFO=20;WARNING=30;ERROR=40;level=INFO;prnt=T
57
+ A5=['lib','/lib','/sd/lib','/flash/lib',K]
58
+ class J:
59
+ DEBUG=10;INFO=20;WARNING=30;ERROR=40;level=INFO;prnt=P
61
60
  @staticmethod
62
- def getLogger(name):return L()
61
+ def getLogger(name):return J()
63
62
  @classmethod
64
63
  def basicConfig(A,level):A.level=level
64
+ def debug(A,msg):
65
+ if A.level<=J.DEBUG:A.prnt('DEBUG :',msg)
65
66
  def info(A,msg):
66
- if A.level<=L.INFO:A.prnt('INFO :',msg)
67
+ if A.level<=J.INFO:A.prnt('INFO :',msg)
67
68
  def warning(A,msg):
68
- if A.level<=L.WARNING:A.prnt('WARN :',msg)
69
+ if A.level<=J.WARNING:A.prnt('WARN :',msg)
69
70
  def error(A,msg):
70
- if A.level<=L.ERROR:A.prnt('ERROR :',msg)
71
- A=L.getLogger(u)
72
- L.basicConfig(level=L.INFO)
71
+ if A.level<=J.ERROR:A.prnt('ERROR :',msg)
72
+ A=J.getLogger(t)
73
+ J.basicConfig(level=J.INFO)
73
74
  class Stubber:
74
75
  def __init__(B,path=E,firmware_id=E):
75
76
  C=firmware_id
76
77
  try:
77
- if os.uname().release=='1.13.0'and os.uname().version<'v1.13-103':raise p('MicroPython 1.13.0 cannot be stubbed')
78
+ if os.uname().release=='1.13.0'and os.uname().version<'v1.13-103':raise o('MicroPython 1.13.0 cannot be stubbed')
78
79
  except I:pass
79
- B.info=_info();A.info('Port: {}'.format(B.info[K]));A.info('Board: {}'.format(B.info[V]));F.collect()
80
+ B.info=_info();A.info('Port: {}'.format(B.info[L]));A.info('Board: {}'.format(B.info[U]));F.collect()
80
81
  if C:B._fwid=C.lower()
81
- elif B.info[Q]==v:B._fwid='{family}-v{version}-{port}-{board}'.format(**B.info).rstrip(W)
82
+ elif B.info[S]==u:B._fwid='{family}-v{version}-{port}-{board}'.format(**B.info).rstrip(V)
82
83
  else:B._fwid='{family}-v{version}-{port}'.format(**B.info)
83
84
  B._start_free=F.mem_free()
84
85
  if path:
85
86
  if path.endswith(G):path=path[:-1]
86
87
  else:path=get_root()
87
88
  B.path='{}/stubs/{}'.format(path,B.flat_fwid).replace('//',G)
88
- try:Y(path+G)
89
+ try:X(path+G)
89
90
  except D:A.error('error creating stub folder {}'.format(path))
90
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=E;B._json_first=H
91
92
  def get_obj_attributes(L,item_instance):
@@ -94,17 +95,17 @@ class Stubber:
94
95
  if A.startswith('__')and not A in L.modules:continue
95
96
  try:
96
97
  D=getattr(H,A)
97
- try:E=c(type(D)).split("'")[1]
98
- except U:E=B
99
- if E in{w,x,y,z,f,g,h}:G=1
100
- elif E in{A0,A1}:G=2
98
+ try:E=b(type(D)).split("'")[1]
99
+ except Q:E=B
100
+ if E in{v,w,x,y,e,f,g}:G=1
101
+ elif E in{z,A0}:G=2
101
102
  elif E in'class':G=3
102
103
  else:G=4
103
- C.append((A,c(D),c(type(D)),D,G))
104
+ C.append((A,b(D),b(type(D)),D,G))
104
105
  except I as J:K.append("Couldn't get attribute '{}' from object '{}', Err: {}".format(A,H,J))
105
- except q as J:T('MemoryError: {}'.format(J));sleep(1);reset()
106
- C=r([A for A in C if not A[0].startswith('__')],key=lambda x:x[4]);F.collect();return C,K
107
- def add_modules(A,modules):A.modules=r(set(A.modules)|set(modules))
106
+ except p as J:P('MemoryError: {}'.format(J));sleep(1);reset()
107
+ C=q([A for A in C if not A[0].startswith('__')],key=lambda x:x[4]);F.collect();return C,K
108
+ def add_modules(A,modules):A.modules=q(set(A.modules)|set(modules))
108
109
  def create_all_stubs(B):
109
110
  A.info('Start micropython-stubber {} on {}'.format(__version__,B._fwid));B.report_start();F.collect()
110
111
  for C in B.modules:B.create_one_stub(C)
@@ -113,60 +114,62 @@ class Stubber:
113
114
  B=module_name
114
115
  if B in C.problematic:A.warning('Skip module: {:<25} : Known problematic'.format(B));return H
115
116
  if B in C.excluded:A.warning('Skip module: {:<25} : Excluded'.format(B));return H
116
- I='{}/{}.pyi'.format(C.path,B.replace(J,G));F.collect();E=H
117
+ I='{}/{}.pyi'.format(C.path,B.replace(K,G));F.collect();E=H
117
118
  try:E=C.create_module_stub(B,I)
118
119
  except D:return H
119
120
  F.collect();return E
120
- def create_module_stub(K,module_name,file_name=E):
121
+ def create_module_stub(J,module_name,file_name=E):
121
122
  I=file_name;C=module_name
122
- if I is E:L=C.replace(J,'_')+'.pyi';I=K.path+G+L
123
+ if I is E:L=C.replace(K,'_')+'.pyi';I=J.path+G+L
123
124
  else:L=I.split(G)[-1]
124
- if G in C:C=C.replace(G,J)
125
+ if G in C:C=C.replace(G,K)
125
126
  N=E
126
127
  try:N=__import__(C,E,E,'*');Q=F.mem_free();A.info('Stub module: {:<25} to file: {:<70} mem:{:>5}'.format(C,L,Q))
127
128
  except O:return H
128
- Y(I)
129
- with M(I,i)as P:T=d(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,N,C,B)
130
- K.report_add(C,I)
129
+ 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
+ J.report_add(C,I)
131
132
  if C not in{'os','sys','logging','gc'}:
132
133
  try:del N
133
- except(D,s):A.warning('could not del new_module')
134
- F.collect();return R
134
+ except(D,r):A.warning('could not del new_module')
135
+ F.collect();return T
135
136
  def write_object_stub(L,fp,object_expr,obj_name,indent,in_class=0):
136
- 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;D=indent;F.collect()
137
+ 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;F.collect()
137
138
  if M in L.problematic:A.warning('SKIPPING problematic module:{}'.format(M));return
138
- a,Q=L.get_obj_attributes(M)
139
- if Q:A.error(Q)
140
- for(E,H,I,b,d)in a:
141
- if E in['classmethod','staticmethod','BaseException',N]:continue
142
- if E[0].isdigit():A.warning('NameError: invalid name {}'.format(E));continue
143
- if I=="<class 'type'>"and P(D)<=A5*4:
144
- R=B;S=E.endswith(N)or E.endswith('Error')or E in['KeyboardInterrupt','StopIteration','SystemExit']
145
- if S:R=N
146
- C='\n{}class {}({}):\n'.format(D,E,R)
147
- if S:C+=D+' ...\n';J.write(C);continue
148
- J.write(C);L.write_object_stub(J,b,'{0}.{1}'.format(obj_name,E),D+' ',O+1);C=D+' def __init__(self, *argv, **kwargs) -> None:\n';C+=D+' ...\n\n';J.write(C)
149
- elif any(A in I for A in[A1,A0,'closure']):
139
+ a,P=L.get_obj_attributes(M)
140
+ if P:A.error(P)
141
+ for(C,H,I,b,d)in a:
142
+ if C in['classmethod','staticmethod','BaseException',N]:continue
143
+ if C[0].isdigit():A.warning('NameError: invalid name {}'.format(C));continue
144
+ if I=="<class 'type'>"and R(E)<=A4*4:
145
+ Q=B;S=C.endswith(N)or C.endswith('Error')or C in['KeyboardInterrupt','StopIteration','SystemExit']
146
+ if S:Q=N
147
+ D='\n{}class {}({}):\n'.format(E,C,Q)
148
+ if S:D+=E+' ...\n';J.write(D);continue
149
+ J.write(D);L.write_object_stub(J,b,'{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
+ elif any(A in I for A in[A0,z,'closure']):
150
151
  T=V;U=B
151
152
  if O>0:U='self, '
152
- if W in I or W in H:C='{}@classmethod\n'.format(D)+'{}def {}(cls, *args, **kwargs) -> {}:\n'.format(D,E,T)
153
- else:C='{}def {}({}*args, **kwargs) -> {}:\n'.format(D,E,U,T)
154
- C+=D+' ...\n\n';J.write(C)
153
+ if W in I or W in H:D='{}@classmethod\n'.format(E)+'{}def {}(cls, *args, **kwargs) -> {}:\n'.format(E,C,T)
154
+ else:D='{}def {}({}*args, **kwargs) -> {}:\n'.format(E,C,U,T)
155
+ D+=E+' ...\n\n';J.write(D)
155
156
  elif I=="<class 'module'>":0
156
157
  elif I.startswith("<class '"):
157
- G=I[8:-2];C=B
158
- if G in(y,w,x,z,'bytearray','bytes'):C=X.format(D,E,H,G)
159
- elif G in(h,g,f):c={h:'{}',g:'[]',f:'()'};C=X.format(D,E,c[G],G)
158
+ G=I[8:-2];D=B
159
+ if G in(x,v,w,y,'bytearray','bytes'):
160
+ if C.upper()==C:D='{0}{1}: Final[{3}] = {2}\n'.format(E,C,H,G)
161
+ else:D=X.format(E,C,H,G)
162
+ elif G in(g,f,e):c={g:'{}',f:'[]',e:'()'};D=X.format(E,C,c[G],G)
160
163
  elif G in('object','set','frozenset','Pin',Y):
161
164
  if G==Y:G='Generator'
162
- C='{0}{1}: {2} ## = {4}\n'.format(D,E,G,I,H)
165
+ D='{0}{1}: {2} ## = {4}\n'.format(E,C,G,I,H)
163
166
  else:
164
167
  G=V
165
168
  if K in H:H=H.split(K)[0]+Z
166
169
  if K in H:H=H.split(K)[0]+Z
167
- C='{0}{1}: {2} ## {3} = {4}\n'.format(D,E,G,I,H)
168
- J.write(C)
169
- else:J.write("# all other, type = '{0}'\n".format(I));J.write(D+E+' # type: Incomplete\n')
170
+ D='{0}{1}: {2} ## {3} = {4}\n'.format(E,C,G,I,H)
171
+ J.write(D)
172
+ else:J.write("# all other, type = '{0}'\n".format(I));J.write(E+C+' # type: Incomplete\n')
170
173
  @property
171
174
  def flat_fwid(self):
172
175
  A=self._fwid;B=' .()/\\:$'
@@ -178,29 +181,29 @@ class Stubber:
178
181
  try:os.stat(path);F=os.listdir(path)
179
182
  except(D,I):return
180
183
  for G in F:
181
- B=j.format(path,G)
184
+ B=i.format(path,G)
182
185
  try:os.remove(B)
183
186
  except D:
184
187
  try:C.clean(B);os.rmdir(B)
185
188
  except D:pass
186
- def report_start(B,filename=k):
187
- H='firmware';B._json_name=j.format(B.path,filename);B._json_first=R;Y(B._json_name);A.info('Report file: {}'.format(B._json_name));F.collect()
189
+ def report_start(B,filename=j):
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()
188
191
  try:
189
- with M(B._json_name,i)as G:G.write('{');G.write(dumps({H:B.info})[1:-1]);G.write(l);G.write(dumps({u:{C:S},'stubtype':H})[1:-1]);G.write(l);G.write('"modules" :[\n')
190
- except D as I:A.error(A2);B._json_name=E;raise I
192
+ with M(B._json_name,h)as G:G.write('{');G.write(dumps({H:B.info})[1:-1]);G.write(k);G.write(dumps({t:{C:__version__},'stubtype':H})[1:-1]);G.write(k);G.write('"modules" :[\n')
193
+ except D as I:A.error(A1);B._json_name=E;raise I
191
194
  def report_add(B,module_name,stub_file):
192
- if not B._json_name:raise t(A3)
195
+ if not B._json_name:raise s(A2)
193
196
  try:
194
197
  with M(B._json_name,'a')as C:
195
- if not B._json_first:C.write(l)
198
+ if not B._json_first:C.write(k)
196
199
  else:B._json_first=H
197
200
  E='{{"module": "{}", "file": "{}"}}'.format(module_name,stub_file.replace('\\',G));C.write(E)
198
- except D:A.error(A2)
201
+ except D:A.error(A1)
199
202
  def report_end(B):
200
- if not B._json_name:raise t(A3)
203
+ if not B._json_name:raise s(A2)
201
204
  with M(B._json_name,'a')as C:C.write('\n]}')
202
205
  A.info('Path: {}'.format(B.path))
203
- def Y(path):
206
+ def X(path):
204
207
  B=E=0
205
208
  while B!=-1:
206
209
  B=path.find(G,E)
@@ -208,57 +211,59 @@ def Y(path):
208
211
  C=path[0]if B==0 else path[:B]
209
212
  try:I=os.stat(C)
210
213
  except D as F:
211
- if F.args[0]==A4:
212
- try:os.mkdir(C)
214
+ if F.args[0]==A3:
215
+ try:A.debug('Create folder {}'.format(C));os.mkdir(C)
213
216
  except D as H:A.error('failed to create folder {}'.format(C));raise H
214
217
  E=B+1
215
- def Z(s):
218
+ def Y(s):
216
219
  C=' on '
217
220
  if not s:return B
218
221
  s=s.split(C,1)[0]if C in s else s
219
222
  if s.startswith('v'):
220
- if not W in s:return B
221
- A=s.split(W)[1];return A
222
- if not X in s:return B
223
- A=s.split(X)[1].split(J)[1];return A
223
+ if not V in s:return B
224
+ A=s.split(V)[1];return A
225
+ if not W in s:return B
226
+ A=s.split(W)[1].split(K)[1];return A
224
227
  def _info():
225
- b='ev3-pybricks';a='pycom';Y='pycopy';W='unix';T='win32';R='arch';P='cpu';M='ver';F='mpy';D='build'
226
- try:H=sys.implementation[0]
227
- except e:H=sys.implementation.name
228
- A=m({Q:H,C:B,D:B,M:B,K:sys.platform,V:'UNKNOWN',P:B,F:B,R:B})
229
- if A[K].startswith('pyb'):A[K]='stm32'
230
- elif A[K]==T:A[K]='windows'
231
- elif A[K]=='linux':A[K]=W
232
- try:A[C]=S(sys.implementation.version)
228
+ a='ev3-pybricks';Z='pycom';X='pycopy';V='unix';T='win32';R='arch';P='cpu';M='ver';F='mpy';D='build'
229
+ try:J=sys.implementation[0]
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,F:B,R:B})
232
+ if A[L].startswith('pyb'):A[L]='stm32'
233
+ elif A[L]==T:A[L]='windows'
234
+ elif A[L]=='linux':A[L]=V
235
+ try:A[C]=A6(sys.implementation.version)
233
236
  except I:pass
234
- try:J=sys.implementation._machine if'_machine'in N(sys.implementation)else os.uname().machine;A[V]=J;A[P]=J.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
235
- except(I,U):pass
236
- A[V]=A7()
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[F]=sys.implementation._mpy if'_mpy'in N(sys.implementation)else sys.implementation.mpy if F in N(sys.implementation)else B
238
+ except(I,Q):pass
239
+ A[U]=A7()
237
240
  try:
238
241
  if'uname'in N(os):
239
- A[D]=Z(os.uname()[3])
240
- if not A[D]:A[D]=Z(os.uname()[2])
241
- elif C in N(sys):A[D]=Z(sys.version)
242
- except(I,U,e):pass
243
- if A[C]==B and sys.platform not in(W,T):
244
- try:c=os.uname();A[C]=c.release
245
- except(U,I,e):pass
246
- for(d,f,g)in[(Y,Y,'const'),(a,a,'FAT'),(b,'pybricks.hubs','EV3Brick')]:
247
- try:h=__import__(f,E,E,g);A[Q]=d;del h;break
248
- except(O,s):pass
249
- if A[Q]==b:A['release']='2.0.0'
250
- if A[Q]==v:
242
+ A[D]=Y(os.uname()[3])
243
+ if not A[D]:A[D]=Y(os.uname()[2])
244
+ elif C in N(sys):A[D]=Y(sys.version)
245
+ except(I,Q,d):pass
246
+ if A[C]==B and sys.platform not in(V,T):
247
+ try:b=os.uname();A[C]=b.release
248
+ except(Q,I,d):pass
249
+ for(c,e,f)in[(X,X,'const'),(Z,Z,'FAT'),(a,'pybricks.hubs','EV3Brick')]:
250
+ try:g=__import__(e,E,E,f);A[S]=c;del g;break
251
+ except(O,r):pass
252
+ if A[S]==a:A['release']='2.0.0'
253
+ if A[S]==u:
251
254
  A[C]
252
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]
253
256
  if F in A and A[F]:
254
- G=int(A[F]);L=[E,'x86','x64','armv6','armv6m','armv7m','armv7em','armv7emsp','armv7emdp','xtensa','xtensawin'][G>>10]
255
- if L:A[R]=L
257
+ G=int(A[F])
258
+ try:H=[E,'x86','x64','armv6','armv6m','armv7m','armv7em','armv7emsp','armv7emdp','xtensa','xtensawin','rv32imc'][G>>10]
259
+ except Q:H='unknown'
260
+ if H:A[R]=H
256
261
  A[F]='v{}.{}'.format(G&255,G>>8&3)
257
- if A[D]and not A[C].endswith(X):A[C]=A[C]+X
262
+ if A[D]and not A[C].endswith(W):A[C]=A[C]+W
258
263
  A[M]=f"{A[C]}-{A[D]}"if A[D]else f"{A[C]}";return A
259
- def S(version):
260
- A=version;B=J.join([d(A)for A in A[:3]])
261
- if P(A)>3 and A[3]:B+=W+A[3]
264
+ def A6(version):
265
+ A=version;B=K.join([c(A)for A in A[:3]])
266
+ if R(A)>3 and A[3]:B+=V+A[3]
262
267
  return B
263
268
  def A7():
264
269
  try:from boardname import BOARDNAME as C;A.info('Found BOARDNAME: {}'.format(C))
@@ -266,68 +271,69 @@ def A7():
266
271
  return C
267
272
  def get_root():
268
273
  try:A=os.getcwd()
269
- except(D,I):A=J
274
+ except(D,I):A=K
270
275
  B=A
271
- for B in[A,'/sd','/flash',G,J]:
276
+ for B in['/remote','/sd','/flash',G,A,K]:
272
277
  try:C=os.stat(B);break
273
278
  except D:continue
274
279
  return B
275
- def a(filename):
280
+ def Z(filename):
276
281
  try:
277
- if os.stat(filename)[0]>>14:return R
282
+ if os.stat(filename)[0]>>14:return T
278
283
  return H
279
284
  except D:return H
280
- def n():T("-p, --path path to store the stubs in, defaults to '.'");sys.exit(1)
285
+ def m():P("-p, --path path to store the stubs in, defaults to '.'");sys.exit(1)
281
286
  def read_path():
282
287
  path=B
283
- if P(sys.argv)==3:
288
+ if R(sys.argv)==3:
284
289
  A=sys.argv[1].lower()
285
290
  if A in('--path','-p'):path=sys.argv[2]
286
- else:n()
287
- elif P(sys.argv)==2:n()
291
+ else:m()
292
+ elif R(sys.argv)==2:m()
288
293
  return path
289
- def o():
290
- try:A=bytes('abc',encoding='utf8');B=o.__module__;return H
291
- except(p,I):return R
292
- b='modulelist.done'
294
+ def n():
295
+ try:A=bytes('abc',encoding='utf8');B=n.__module__;return H
296
+ except(o,I):return T
297
+ a='modulelist.done'
293
298
  def A8(skip=0):
294
- for E in A6:
299
+ for E in A5:
295
300
  B=E+'/modulelist.txt'
296
- if not a(B):continue
301
+ if not Z(B):continue
297
302
  try:
298
303
  with M(B)as F:
299
304
  C=0
300
- while R:
305
+ while T:
301
306
  A=F.readline().strip()
302
307
  if not A:break
303
- if P(A)>0 and A[0]=='#':continue
308
+ if R(A)>0 and A[0]=='#':continue
304
309
  C+=1
305
310
  if C<skip:continue
306
311
  yield A
307
312
  break
308
313
  except D:pass
309
314
  def A9(done):
310
- with M(b,i)as A:A.write(d(done)+'\n')
315
+ with M(a,h)as A:A.write(c(done)+'\n')
311
316
  def AA():
312
317
  A=0
313
318
  try:
314
- with M(b)as B:A=int(B.readline().strip())
319
+ with M(a)as B:A=int(B.readline().strip())
315
320
  except D:pass
316
321
  return A
317
322
  def main():
318
- import machine as D;C=a(b)
323
+ import machine as D;C=Z(a)
319
324
  if C:A.info('Continue from last run')
320
325
  else:A.info('Starting new run')
321
326
  stubber=Stubber(path=read_path());B=0
322
- if not C:stubber.clean();stubber.report_start(k)
323
- else:B=AA();stubber._json_name=j.format(stubber.path,k)
327
+ if not C:stubber.clean();stubber.report_start(j)
328
+ else:B=AA();stubber._json_name=i.format(stubber.path,j)
324
329
  for E in A8(B):
325
330
  try:stubber.create_one_stub(E)
326
- except q:D.reset()
331
+ except p:D.reset()
327
332
  F.collect();B+=1;A9(B)
328
- T('All modules have been processed, Finalizing report');stubber.report_end()
329
- if __name__=='__main__'or o():
330
- if not a('no_auto_stubber.txt'):
331
- try:F.threshold(4*1024);F.enable()
333
+ P('All modules have been processed, Finalizing report');stubber.report_end()
334
+ if __name__=='__main__'or n():
335
+ if not Z('no_auto_stubber.txt'):
336
+ P(f"createstubs.py: {__version__}")
337
+ try:F.threshold(4096);F.enable()
332
338
  except BaseException:pass
333
339
  main()
Binary file
@@ -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.23.2
12
+ This variant was generated from createstubs.py by micropython-stubber v1.24.0
13
13
  """
14
14
 
15
15
  # Copyright (c) 2019-2024 Jos Verlinde
@@ -34,8 +34,7 @@ try:
34
34
  except ImportError:
35
35
  from ucollections import OrderedDict # type: ignore
36
36
 
37
- __version__ = "v1.23.2"
38
- version_str = __version__.rsplit(".", 1)[0]
37
+ __version__ = "v1.24.0"
39
38
  ENOENT = 2
40
39
  _MAX_CLASS_LEVEL = 2 # Max class nesting
41
40
  LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
@@ -43,7 +42,7 @@ LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
43
42
 
44
43
  # our own logging module to avoid dependency on and interfering with logging module
45
44
  class logging:
46
- # DEBUG = 10
45
+ DEBUG = 10
47
46
  INFO = 20
48
47
  WARNING = 30
49
48
  ERROR = 40
@@ -58,9 +57,9 @@ class logging:
58
57
  def basicConfig(cls, level):
59
58
  cls.level = level
60
59
 
61
- # def debug(self, msg):
62
- # if self.level <= logging.DEBUG:
63
- # self.prnt("DEBUG :", msg)
60
+ def debug(self, msg):
61
+ if self.level <= logging.DEBUG:
62
+ self.prnt("DEBUG :", msg)
64
63
 
65
64
  def info(self, msg):
66
65
  if self.level <= logging.INFO:
@@ -236,10 +235,11 @@ class Stubber:
236
235
  return False
237
236
 
238
237
  # Start a new file
238
+ # log.debug("Create file: {}".format(file_name))
239
239
  ensure_folder(file_name)
240
240
  with open(file_name, "w") as fp:
241
241
  info_ = str(self.info).replace("OrderedDict(", "").replace("})", "}")
242
- s = '"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(module_name, self._fwid, info_, version_str)
242
+ s = '"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(module_name, self._fwid, info_, __version__)
243
243
  fp.write(s)
244
244
  fp.write("from __future__ import annotations\nfrom typing import Any, Generator\nfrom _typeshed import Incomplete\n\n")
245
245
  self.write_object_stub(fp, new_module, module_name, "")
@@ -349,8 +349,10 @@ class Stubber:
349
349
 
350
350
  if t in ("str", "int", "float", "bool", "bytearray", "bytes"):
351
351
  # known type: use actual value
352
- # s = "{0}{1} = {2} # type: {3}\n".format(indent, item_name, item_repr, t)
353
- s = "{0}{1}: {3} = {2}\n".format(indent, item_name, item_repr, t)
352
+ if item_name.upper() == item_name: # ALL_CAPS --> Final
353
+ s = "{0}{1}: Final[{3}] = {2}\n".format(indent, item_name, item_repr, t)
354
+ else:
355
+ s = "{0}{1}: {3} = {2}\n".format(indent, item_name, item_repr, t)
354
356
  elif t in ("dict", "list", "tuple"):
355
357
  # dict, list , tuple: use empty value
356
358
  ev = {"dict": "{}", "list": "[]", "tuple": "()"}
@@ -434,7 +436,7 @@ class Stubber:
434
436
  f.write("{")
435
437
  f.write(dumps({"firmware": self.info})[1:-1])
436
438
  f.write(",\n")
437
- f.write(dumps({"stubber": {"version": version_str}, "stubtype": "firmware"})[1:-1])
439
+ f.write(dumps({"stubber": {"version": __version__}, "stubtype": "firmware"})[1:-1])
438
440
  f.write(",\n")
439
441
  f.write('"modules" :[\n')
440
442
 
@@ -483,6 +485,7 @@ def ensure_folder(path: str):
483
485
  # folder does not exist
484
486
  if e.args[0] == ENOENT:
485
487
  try:
488
+ log.debug("Create folder {}".format(p))
486
489
  os.mkdir(p)
487
490
  except OSError as e2:
488
491
  log.error("failed to create folder {}".format(p))
@@ -493,7 +496,7 @@ def ensure_folder(path: str):
493
496
 
494
497
  def _build(s):
495
498
  # extract build from sys.version or os.uname().version if available
496
- # sys.version: 'MicroPython v1.23.2-preview.6.g3d0b6276f'
499
+ # sys.version: 'MicroPython v1.24.0-preview.6.g3d0b6276f'
497
500
  # sys.implementation.version: 'v1.13-103-gb137d064e'
498
501
  if not s:
499
502
  return ""
@@ -598,29 +601,33 @@ def _info(): # type:() -> dict[str, str]
598
601
  if (
599
602
  info["version"]
600
603
  and info["version"].endswith(".0")
601
- and info["version"] >= "1.10.0" # versions from 1.10.0 to 1.23.2 do not have a micro .0
604
+ and info["version"] >= "1.10.0" # versions from 1.10.0 to 1.24.0 do not have a micro .0
602
605
  and info["version"] <= "1.19.9"
603
606
  ):
604
- # versions from 1.10.0 to 1.23.2 do not have a micro .0
607
+ # versions from 1.10.0 to 1.24.0 do not have a micro .0
605
608
  info["version"] = info["version"][:-2]
606
609
 
607
610
  # spell-checker: disable
608
611
  if "mpy" in info and info["mpy"]: # mpy on some v1.11+ builds
609
612
  sys_mpy = int(info["mpy"])
610
613
  # .mpy architecture
611
- arch = [
612
- None,
613
- "x86",
614
- "x64",
615
- "armv6",
616
- "armv6m",
617
- "armv7m",
618
- "armv7em",
619
- "armv7emsp",
620
- "armv7emdp",
621
- "xtensa",
622
- "xtensawin",
623
- ][sys_mpy >> 10]
614
+ try:
615
+ arch = [
616
+ None,
617
+ "x86",
618
+ "x64",
619
+ "armv6",
620
+ "armv6m",
621
+ "armv7m",
622
+ "armv7em",
623
+ "armv7emsp",
624
+ "armv7emdp",
625
+ "xtensa",
626
+ "xtensawin",
627
+ "rv32imc",
628
+ ][sys_mpy >> 10]
629
+ except IndexError:
630
+ arch = "unknown"
624
631
  if arch:
625
632
  info["arch"] = arch
626
633
  # .mpy version.minor
@@ -660,7 +667,7 @@ def get_root() -> str: # sourcery skip: use-assigned-variable
660
667
  # unix port
661
668
  c = "."
662
669
  r = c
663
- for r in [c, "/sd", "/flash", "/", "."]:
670
+ for r in ["/remote", "/sd", "/flash", "/", c, "."]:
664
671
  try:
665
672
  _ = os.stat(r)
666
673
  break
@@ -759,6 +766,7 @@ def main():
759
766
 
760
767
  if __name__ == "__main__" or is_micropython():
761
768
  if not file_exists("no_auto_stubber.txt"):
769
+ print(f"createstubs.py: {__version__}")
762
770
  try:
763
771
  gc.threshold(4 * 1024) # type: ignore
764
772
  gc.enable()