micropython-stubber 1.23.2__py3-none-any.whl → 1.23.3__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.
@@ -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.23.3
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.23.3"
39
38
  ENOENT = 2
40
39
  _MAX_CLASS_LEVEL = 2 # Max class nesting
41
40
  LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
@@ -239,7 +238,7 @@ class Stubber:
239
238
  ensure_folder(file_name)
240
239
  with open(file_name, "w") as fp:
241
240
  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)
241
+ s = '"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(module_name, self._fwid, info_, __version__)
243
242
  fp.write(s)
244
243
  fp.write("from __future__ import annotations\nfrom typing import Any, Generator\nfrom _typeshed import Incomplete\n\n")
245
244
  self.write_object_stub(fp, new_module, module_name, "")
@@ -434,7 +433,7 @@ class Stubber:
434
433
  f.write("{")
435
434
  f.write(dumps({"firmware": self.info})[1:-1])
436
435
  f.write(",\n")
437
- f.write(dumps({"stubber": {"version": version_str}, "stubtype": "firmware"})[1:-1])
436
+ f.write(dumps({"stubber": {"version": __version__}, "stubtype": "firmware"})[1:-1])
438
437
  f.write(",\n")
439
438
  f.write('"modules" :[\n')
440
439
 
@@ -493,7 +492,7 @@ def ensure_folder(path: str):
493
492
 
494
493
  def _build(s):
495
494
  # extract build from sys.version or os.uname().version if available
496
- # sys.version: 'MicroPython v1.23.2-preview.6.g3d0b6276f'
495
+ # sys.version: 'MicroPython v1.23.3-preview.6.g3d0b6276f'
497
496
  # sys.implementation.version: 'v1.13-103-gb137d064e'
498
497
  if not s:
499
498
  return ""
@@ -598,10 +597,10 @@ def _info(): # type:() -> dict[str, str]
598
597
  if (
599
598
  info["version"]
600
599
  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
600
+ and info["version"] >= "1.10.0" # versions from 1.10.0 to 1.23.3 do not have a micro .0
602
601
  and info["version"] <= "1.19.9"
603
602
  ):
604
- # versions from 1.10.0 to 1.23.2 do not have a micro .0
603
+ # versions from 1.10.0 to 1.23.3 do not have a micro .0
605
604
  info["version"] = info["version"][:-2]
606
605
 
607
606
  # spell-checker: disable
@@ -1,29 +1,29 @@
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
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=IndexError
26
+ S=print
27
27
  R=True
28
28
  Q='family'
29
29
  P=len
@@ -45,15 +45,14 @@ 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.23.3'
51
+ y=2
52
52
  z=2
53
- A0=2
54
- A1=['lib','/lib','/sd/lib','/flash/lib',J]
53
+ A0=['lib','/lib','/sd/lib','/flash/lib',J]
55
54
  class L:
56
- INFO=20;WARNING=30;ERROR=40;level=INFO;prnt=T
55
+ INFO=20;WARNING=30;ERROR=40;level=INFO;prnt=S
57
56
  @staticmethod
58
57
  def getLogger(name):return L()
59
58
  @classmethod
@@ -64,24 +63,24 @@ class L:
64
63
  if A.level<=L.WARNING:A.prnt('WARN :',msg)
65
64
  def error(A,msg):
66
65
  if A.level<=L.ERROR:A.prnt('ERROR :',msg)
67
- A=L.getLogger(p)
66
+ A=L.getLogger(o)
68
67
  L.basicConfig(level=L.INFO)
69
68
  class Stubber:
70
69
  def __init__(B,path=E,firmware_id=E):
71
70
  C=firmware_id
72
71
  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')
72
+ if os.uname().release=='1.13.0'and os.uname().version<'v1.13-103':raise k('MicroPython 1.13.0 cannot be stubbed')
74
73
  except I:pass
75
- B.info=_info();A.info('Port: {}'.format(B.info[K]));A.info('Board: {}'.format(B.info[V]));D.collect()
74
+ B.info=_info();A.info('Port: {}'.format(B.info[K]));A.info('Board: {}'.format(B.info[U]));D.collect()
76
75
  if C:B._fwid=C.lower()
77
- elif B.info[Q]==c:B._fwid='{family}-v{version}-{port}-{board}'.format(**B.info).rstrip(W)
76
+ elif B.info[Q]==b:B._fwid='{family}-v{version}-{port}-{board}'.format(**B.info).rstrip(V)
78
77
  else:B._fwid='{family}-v{version}-{port}'.format(**B.info)
79
78
  B._start_free=D.mem_free()
80
79
  if path:
81
80
  if path.endswith(G):path=path[:-1]
82
81
  else:path=get_root()
83
82
  B.path='{}/stubs/{}'.format(path,B.flat_fwid).replace('//',G)
84
- try:Y(path+G)
83
+ try:X(path+G)
85
84
  except F:A.error('error creating stub folder {}'.format(path))
86
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
87
86
  def get_obj_attributes(L,item_instance):
@@ -90,17 +89,17 @@ class Stubber:
90
89
  if A.startswith('__')and not A in L.modules:continue
91
90
  try:
92
91
  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
92
+ try:F=Z(type(E)).split("'")[1]
93
+ except T:F=B
94
+ if F in{p,q,r,s,c,d,e}:G=1
95
+ elif F in{t,u}:G=2
97
96
  elif F in'class':G=3
98
97
  else:G=4
99
- C.append((A,a(E),a(type(E)),E,G))
98
+ C.append((A,Z(E),Z(type(E)),E,G))
100
99
  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))
100
+ except MemoryError as J:S('MemoryError: {}'.format(J));sleep(1);reset()
101
+ C=l([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=l(set(A.modules)|set(modules))
104
103
  def create_all_stubs(B):
105
104
  A.info('Start micropython-stubber {} on {}'.format(__version__,B._fwid));B.report_start();D.collect()
106
105
  for C in B.modules:B.create_one_stub(C)
@@ -121,12 +120,12 @@ class Stubber:
121
120
  M=E
122
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))
123
122
  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)
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)
126
125
  K.report_add(C,I)
127
126
  if C not in{'os','sys','logging','gc'}:
128
127
  try:del M
129
- except(F,n):A.warning('could not del new_module')
128
+ except(F,m):A.warning('could not del new_module')
130
129
  D.collect();return R
131
130
  def write_object_stub(L,fp,object_expr,obj_name,indent,in_class=0):
132
131
  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()
@@ -136,13 +135,13 @@ class Stubber:
136
135
  for(F,H,I,b,g)in a:
137
136
  if F in['classmethod','staticmethod','BaseException',N]:continue
138
137
  if F[0].isdigit():A.warning('NameError: invalid name {}'.format(F));continue
139
- if I=="<class 'type'>"and P(E)<=A0*4:
138
+ if I=="<class 'type'>"and P(E)<=z*4:
140
139
  R=B;S=F.endswith(N)or F.endswith('Error')or F in['KeyboardInterrupt','StopIteration','SystemExit']
141
140
  if S:R=N
142
141
  C='\n{}class {}({}):\n'.format(E,F,R)
143
142
  if S:C+=E+' ...\n';J.write(C);continue
144
143
  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']):
144
+ elif any(A in I for A in[u,t,'closure']):
146
145
  T=V;U=B
147
146
  if O>0:U='self, '
148
147
  if W in I or W in H:C='{}@classmethod\n'.format(E)+'{}def {}(cls, *args, **kwargs) -> {}:\n'.format(E,F,T)
@@ -151,8 +150,8 @@ class Stubber:
151
150
  elif I=="<class 'module'>":0
152
151
  elif I.startswith("<class '"):
153
152
  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)
153
+ if G in(r,p,q,s,'bytearray','bytes'):C=X.format(E,F,H,G)
154
+ elif G in(e,d,c):f={e:'{}',d:'[]',c:'()'};C=X.format(E,F,f[G],G)
156
155
  elif G in('object','set','frozenset','Pin',Y):
157
156
  if G==Y:G='Generator'
158
157
  C='{0}{1}: {2} ## = {4}\n'.format(E,F,G,I,H)
@@ -174,29 +173,29 @@ class Stubber:
174
173
  try:os.stat(path);D=os.listdir(path)
175
174
  except(F,I):return
176
175
  for G in D:
177
- B=w.format(path,G)
176
+ B=v.format(path,G)
178
177
  try:os.remove(B)
179
178
  except F:
180
179
  try:C.clean(B);os.rmdir(B)
181
180
  except F:pass
182
181
  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()
182
+ 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()
184
183
  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
184
+ with O(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')
185
+ except F as I:A.error(w);B._json_name=E;raise I
187
186
  def report_add(B,module_name,stub_file):
188
- if not B._json_name:raise o(y)
187
+ if not B._json_name:raise n(x)
189
188
  try:
190
189
  with O(B._json_name,'a')as C:
191
- if not B._json_first:C.write(g)
190
+ if not B._json_first:C.write(f)
192
191
  else:B._json_first=H
193
192
  D='{{"module": "{}", "file": "{}"}}'.format(module_name,stub_file.replace('\\',G));C.write(D)
194
- except F:A.error(x)
193
+ except F:A.error(w)
195
194
  def report_end(B):
196
- if not B._json_name:raise o(y)
195
+ if not B._json_name:raise n(x)
197
196
  with O(B._json_name,'a')as C:C.write('\n]}')
198
197
  A.info('Path: {}'.format(B.path))
199
- def Y(path):
198
+ def X(path):
200
199
  B=D=0
201
200
  while B!=-1:
202
201
  B=path.find(G,D)
@@ -204,57 +203,57 @@ def Y(path):
204
203
  C=path[0]if B==0 else path[:B]
205
204
  try:I=os.stat(C)
206
205
  except F as E:
207
- if E.args[0]==z:
206
+ if E.args[0]==y:
208
207
  try:os.mkdir(C)
209
208
  except F as H:A.error('failed to create folder {}'.format(C));raise H
210
209
  D=B+1
211
- def Z(s):
210
+ def Y(s):
212
211
  C=' on '
213
212
  if not s:return B
214
213
  s=s.split(C,1)[0]if C in s else s
215
214
  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
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
220
219
  def _info():
221
- d='ev3-pybricks';a='pycom';Y='pycopy';W='unix';T='win32';R='arch';P='cpu';O='ver';F='mpy';D='build'
220
+ c='ev3-pybricks';Z='pycom';X='pycopy';V='unix';S='win32';R='arch';P='cpu';O='ver';F='mpy';D='build'
222
221
  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})
222
+ except a:H=sys.implementation.name
223
+ A=g({Q:H,C:B,D:B,O:B,K:sys.platform,U:'UNKNOWN',P:B,F:B,R:B})
225
224
  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)
225
+ elif A[K]==S:A[K]='windows'
226
+ elif A[K]=='linux':A[K]=V
227
+ try:A[C]=A1(sys.implementation.version)
229
228
  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()
229
+ try:J=sys.implementation._machine if'_machine'in M(sys.implementation)else os.uname().machine;A[U]=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
230
+ except(I,T):pass
231
+ A[U]=A2()
233
232
  try:
234
233
  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:
234
+ A[D]=Y(os.uname()[3])
235
+ if not A[D]:A[D]=Y(os.uname()[2])
236
+ elif C in M(sys):A[D]=Y(sys.version)
237
+ except(I,T,a):pass
238
+ if A[C]==B and sys.platform not in(V,S):
239
+ try:d=os.uname();A[C]=d.release
240
+ except(T,I,a):pass
241
+ for(e,f,h)in[(X,X,'const'),(Z,Z,'FAT'),(c,'pybricks.hubs','EV3Brick')]:
242
+ try:i=__import__(f,E,E,h);A[Q]=e;del i;break
243
+ except(N,m):pass
244
+ if A[Q]==c:A['release']='2.0.0'
245
+ if A[Q]==b:
247
246
  A[C]
248
247
  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
248
  if F in A and A[F]:
250
249
  G=int(A[F]);L=[E,'x86','x64','armv6','armv6m','armv7m','armv7em','armv7emsp','armv7emdp','xtensa','xtensawin'][G>>10]
251
250
  if L:A[R]=L
252
251
  A[F]='v{}.{}'.format(G&255,G>>8&3)
253
- if A[D]and not A[C].endswith(X):A[C]=A[C]+X
252
+ if A[D]and not A[C].endswith(W):A[C]=A[C]+W
254
253
  A[O]=f"{A[C]}-{A[D]}"if A[D]else f"{A[C]}";return A
255
- def S(version):
254
+ def A1(version):
256
255
  A=version;B=J.join([str(A)for A in A[:3]])
257
- if P(A)>3 and A[3]:B+=W+A[3]
256
+ if P(A)>3 and A[3]:B+=V+A[3]
258
257
  return B
259
258
  def A2():
260
259
  try:from boardname import BOARDNAME as C;A.info('Found BOARDNAME: {}'.format(C))
@@ -268,41 +267,41 @@ def get_root():
268
267
  try:C=os.stat(B);break
269
268
  except F:continue
270
269
  return B
271
- def i(filename):
270
+ def h(filename):
272
271
  try:
273
272
  if os.stat(filename)[0]>>14:return R
274
273
  return H
275
274
  except F:return H
276
- def j():T("-p, --path path to store the stubs in, defaults to '.'");sys.exit(1)
275
+ def i():S("-p, --path path to store the stubs in, defaults to '.'");sys.exit(1)
277
276
  def read_path():
278
277
  path=B
279
278
  if P(sys.argv)==3:
280
279
  A=sys.argv[1].lower()
281
280
  if A in('--path','-p'):path=sys.argv[2]
282
- else:j()
283
- elif P(sys.argv)==2:j()
281
+ else:i()
282
+ elif P(sys.argv)==2:i()
284
283
  return path
285
- def k():
286
- try:A=bytes('abc',encoding='utf8');B=k.__module__;return H
287
- except(l,I):return R
284
+ def j():
285
+ try:A=bytes('abc',encoding='utf8');B=j.__module__;return H
286
+ except(k,I):return R
288
287
  def main():
289
288
  stubber=Stubber(path=read_path());stubber.clean()
290
289
  def A(stubber):
291
290
  D.collect();stubber.modules=[]
292
- for C in A1:
291
+ for C in A0:
293
292
  B=C+'/modulelist.txt'
294
- if not i(B):continue
293
+ if not h(B):continue
295
294
  with O(B)as E:
296
295
  while R:
297
296
  A=E.readline().strip()
298
297
  if not A:break
299
298
  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]
299
+ D.collect();S('BREAK');break
300
+ if not stubber.modules:stubber.modules=[b]
302
301
  D.collect()
303
302
  stubber.modules=[];A(stubber);D.collect();stubber.create_all_stubs()
304
- if __name__=='__main__'or k():
305
- if not i('no_auto_stubber.txt'):
303
+ if __name__=='__main__'or j():
304
+ if not h('no_auto_stubber.txt'):
306
305
  try:D.threshold(4*1024);D.enable()
307
306
  except BaseException:pass
308
307
  main()
Binary file