micropython-stubber 1.24.0__py3-none-any.whl → 1.24.2__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 (39) hide show
  1. {micropython_stubber-1.24.0.dist-info → micropython_stubber-1.24.2.dist-info}/METADATA +3 -2
  2. {micropython_stubber-1.24.0.dist-info → micropython_stubber-1.24.2.dist-info}/RECORD +38 -36
  3. mpflash/mpflash/bootloader/activate.py +1 -1
  4. mpflash/mpflash/flash/esp.py +1 -1
  5. mpflash/mpflash/flash/uf2/__init__.py +18 -2
  6. mpflash/mpflash/mpboard_id/add_boards.py +5 -2
  7. mpflash/mpflash/mpboard_id/board_id.py +7 -5
  8. mpflash/mpflash/mpboard_id/board_info.zip +0 -0
  9. mpflash/mpflash/vendor/pico-universal-flash-nuke/LICENSE.txt +21 -0
  10. mpflash/mpflash/vendor/pico-universal-flash-nuke/universal_flash_nuke.uf2 +0 -0
  11. mpflash/mpflash/vendor/readme.md +2 -0
  12. mpflash/poetry.lock +754 -488
  13. mpflash/pyproject.toml +1 -1
  14. stubber/__init__.py +1 -1
  15. stubber/board/createstubs.py +44 -38
  16. stubber/board/createstubs_db.py +17 -12
  17. stubber/board/createstubs_db_min.py +63 -63
  18. stubber/board/createstubs_db_mpy.mpy +0 -0
  19. stubber/board/createstubs_mem.py +17 -12
  20. stubber/board/createstubs_mem_min.py +99 -99
  21. stubber/board/createstubs_mem_mpy.mpy +0 -0
  22. stubber/board/createstubs_min.py +111 -112
  23. stubber/board/createstubs_mpy.mpy +0 -0
  24. stubber/board/modulelist.txt +27 -27
  25. stubber/codemod/enrich.py +4 -6
  26. stubber/codemod/merge_docstub.py +10 -10
  27. stubber/codemod/visitors/type_helpers.py +182 -0
  28. stubber/commands/get_docstubs_cmd.py +5 -6
  29. stubber/cst_transformer.py +2 -1
  30. stubber/merge_config.py +3 -0
  31. stubber/publish/merge_docstubs.py +1 -2
  32. stubber/publish/stubpackage.py +36 -14
  33. stubber/rst/lookup.py +3 -0
  34. stubber/rst/reader.py +8 -13
  35. stubber/tools/manifestfile.py +2 -1
  36. stubber/codemod/visitors/typevars.py +0 -200
  37. {micropython_stubber-1.24.0.dist-info → micropython_stubber-1.24.2.dist-info}/LICENSE +0 -0
  38. {micropython_stubber-1.24.0.dist-info → micropython_stubber-1.24.2.dist-info}/WHEEL +0 -0
  39. {micropython_stubber-1.24.0.dist-info → micropython_stubber-1.24.2.dist-info}/entry_points.txt +0 -0
mpflash/pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "mpflash"
3
- version = "1.24.6"
3
+ version = "1.24.7"
4
4
  description = "Flash and download tool for MicroPython firmwares"
5
5
  authors = ["Jos Verlinde <jos_verlinde@hotmail.com>"]
6
6
  license = "MIT"
stubber/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """get the version"""
2
2
 
3
- __version__ = "1.24.0"
3
+ __version__ = "1.24.2"
@@ -25,7 +25,8 @@ except ImportError:
25
25
  from ucollections import OrderedDict # type: ignore
26
26
 
27
27
  __version__ = "v1.24.0"
28
- ENOENT = 2
28
+ ENOENT = 2 # on most ports
29
+ ENOMESSAGE = 44 # on pyscript
29
30
  _MAX_CLASS_LEVEL = 2 # Max class nesting
30
31
  LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
31
32
 
@@ -72,7 +73,7 @@ logging.basicConfig(level=logging.INFO)
72
73
  class Stubber:
73
74
  "Generate stubs for modules in firmware"
74
75
 
75
- def __init__(self, path: str = None, firmware_id: str = None): # type: ignore
76
+ def __init__(self, path: str = "", firmware_id: str = ""): # type: ignore
76
77
  try:
77
78
  if os.uname().release == "1.13.0" and os.uname().version < "v1.13-103": # type: ignore
78
79
  raise NotImplementedError("MicroPython 1.13.0 cannot be stubbed")
@@ -240,7 +241,7 @@ class Stubber:
240
241
  )
241
242
  fp.write(s)
242
243
  fp.write(
243
- "from __future__ import annotations\nfrom typing import Any, Generator\nfrom _typeshed import Incomplete\n\n"
244
+ "from __future__ import annotations\nfrom typing import Any, Final, Generator\nfrom _typeshed import Incomplete\n\n"
244
245
  )
245
246
  self.write_object_stub(fp, new_module, module_name, "")
246
247
 
@@ -366,14 +367,18 @@ class Stubber:
366
367
  s = "{0}{1}: {3} = {2}\n".format(indent, item_name, ev[t], t)
367
368
  else:
368
369
  # something else
369
- if t in ("object", "set", "frozenset", "Pin", "generator"): # "FileIO"
370
+ if t in ("object", "set", "frozenset", "Pin"): # "FileIO"
370
371
  # https://docs.python.org/3/tutorial/classes.html#item_instance-objects
371
372
  # use these types for the attribute
372
- if t == "generator":
373
- t = "Generator"
374
373
  s = "{0}{1}: {2} ## = {4}\n".format(
375
374
  indent, item_name, t, item_type_txt, item_repr
376
375
  )
376
+ elif t == "generator":
377
+ # either a normal or async Generator function
378
+ t = "Generator"
379
+ s = "{0}def {1}(*args, **kwargs) -> Generator: ## = {4}\n{0} ...\n\n".format(
380
+ indent, item_name, t, item_type_txt, item_repr
381
+ )
377
382
  else:
378
383
  # Requires Python 3.6 syntax, which is OK for the stubs/pyi
379
384
  t = "Incomplete"
@@ -410,9 +415,9 @@ class Stubber:
410
415
  s = s.replace(c, "_")
411
416
  return s
412
417
 
413
- def clean(self, path: str = None): # type: ignore
418
+ def clean(self, path: str = ""): # type: ignore
414
419
  "Remove all files from the stub folder"
415
- if path is None:
420
+ if not path:
416
421
  path = self.path
417
422
  log.info("Clean/remove files in folder: {}".format(path))
418
423
  try:
@@ -495,7 +500,7 @@ def ensure_folder(path: str):
495
500
  _ = os.stat(p)
496
501
  except OSError as e:
497
502
  # folder does not exist
498
- if e.args[0] == ENOENT:
503
+ if e.args[0] in [ENOENT, ENOMESSAGE] :
499
504
  try:
500
505
  log.debug("Create folder {}".format(p))
501
506
  os.mkdir(p)
@@ -506,6 +511,7 @@ def ensure_folder(path: str):
506
511
  start = i + 1
507
512
 
508
513
 
514
+
509
515
  def _build(s):
510
516
  # extract build from sys.version or os.uname().version if available
511
517
  # sys.version: 'MicroPython v1.24.0-preview.6.g3d0b6276f'
@@ -727,11 +733,11 @@ def is_micropython() -> bool:
727
733
 
728
734
  # b) https://docs.micropython.org/en/latest/genrst/builtin_types.html#bytes-with-keywords-not-implemented
729
735
  # Micropython: NotImplementedError
730
- b = bytes("abc", encoding="utf8") # type: ignore # lgtm [py/unused-local-variable]
736
+ b = bytes("abc", encoding="utf8") # type: ignore
731
737
 
732
738
  # c) https://docs.micropython.org/en/latest/genrst/core_language.html#function-objects-do-not-have-the-module-attribute
733
739
  # Micropython: AttributeError
734
- c = is_micropython.__module__ # type: ignore # lgtm [py/unused-local-variable]
740
+ c = is_micropython.__module__ # type: ignore
735
741
  return False
736
742
  except (NotImplementedError, AttributeError):
737
743
  return True
@@ -749,36 +755,14 @@ def main():
749
755
  # modules to stub : 131
750
756
  stubber.modules = [
751
757
  "WM8960",
752
- "_OTA",
753
758
  "_asyncio",
754
759
  "_boot_fat",
755
- "_coap",
756
760
  "_espnow",
757
- "_flash_control_OTA",
758
- "_main_pybytes",
759
- "_mqtt",
760
- "_mqtt_core",
761
- "_msg_handl",
762
761
  "_onewire",
763
- "_periodical_pin",
764
- "_pybytes",
765
- "_pybytes_ca",
766
- "_pybytes_config",
767
- "_pybytes_config_reader",
768
- "_pybytes_connection",
769
- "_pybytes_constants",
770
- "_pybytes_debug",
771
- "_pybytes_library",
772
- "_pybytes_machine_learning",
773
- "_pybytes_main",
774
- "_pybytes_protocol",
775
- "_pybytes_pyconfig",
776
- "_pybytes_pymesh_config",
777
762
  "_rp2",
778
- "_terminal",
779
763
  "_thread",
780
764
  "_uasyncio",
781
- "_urequest",
765
+ "abc",
782
766
  "adcfft",
783
767
  "aioble/__init__",
784
768
  "aioble/central",
@@ -801,6 +785,7 @@ def main():
801
785
  "asyncio/funcs",
802
786
  "asyncio/lock",
803
787
  "asyncio/stream",
788
+ "base64",
804
789
  "binascii",
805
790
  "bluetooth",
806
791
  "breakout_as7262",
@@ -830,9 +815,13 @@ def main():
830
815
  "cc3200",
831
816
  "cmath",
832
817
  "collections",
818
+ "collections/__init__",
819
+ "collections/defaultdict",
820
+ "copy",
833
821
  "crypto",
834
822
  "cryptolib",
835
823
  "curl",
824
+ "datetime",
836
825
  "deflate",
837
826
  "dht",
838
827
  "display",
@@ -848,6 +837,7 @@ def main():
848
837
  "espnow",
849
838
  "ffi",
850
839
  "flashbdev",
840
+ "fnmatch",
851
841
  "framebuf",
852
842
  "freesans20",
853
843
  "fs_driver",
@@ -856,20 +846,26 @@ def main():
856
846
  "gc",
857
847
  "gfx_pack",
858
848
  "gsm",
849
+ "gzip",
859
850
  "hashlib",
860
851
  "heapq",
852
+ "hmac",
853
+ "html/__init__",
861
854
  "hub75",
862
855
  "ili9341",
863
856
  "ili9XXX",
864
857
  "imagetools",
865
858
  "inisetup",
859
+ "inspect",
866
860
  "interstate75",
867
861
  "io",
862
+ "itertools",
868
863
  "jpegdec",
869
864
  "js",
870
865
  "jsffi",
871
866
  "json",
872
867
  "lcd160cr",
868
+ "locale",
873
869
  "lodepng",
874
870
  "logging",
875
871
  "lsm6dsox",
@@ -897,7 +893,11 @@ def main():
897
893
  "ntptime",
898
894
  "onewire",
899
895
  "openamp",
896
+ "operator",
900
897
  "os",
898
+ "os/__init__",
899
+ "os/path",
900
+ "pathlib",
901
901
  "pcf85063a",
902
902
  "pic16bit",
903
903
  "picoexplorer",
@@ -913,11 +913,12 @@ def main():
913
913
  "platform",
914
914
  "powerpc",
915
915
  "pyb",
916
- "pycom",
917
916
  "pye",
917
+ "pyscript",
918
+ "pyscript/__init__",
919
+ "pyscript/fs",
918
920
  "qemu",
919
921
  "qrcode",
920
- "queue",
921
922
  "random",
922
923
  "renesas",
923
924
  "renesas-ra",
@@ -932,14 +933,19 @@ def main():
932
933
  "ssd1306",
933
934
  "ssh",
934
935
  "ssl",
936
+ "stat",
935
937
  "stm",
936
938
  "stm32",
939
+ "string",
937
940
  "struct",
938
941
  "sys",
942
+ "tarfile/__init__",
943
+ "tarfile/write",
939
944
  "termios",
940
945
  "time",
941
946
  "tls",
942
947
  "tpcalib",
948
+ "types",
943
949
  "uarray",
944
950
  "uasyncio/__init__",
945
951
  "uasyncio/core",
@@ -951,7 +957,6 @@ def main():
951
957
  "ubinascii",
952
958
  "ubluetooth",
953
959
  "ucollections",
954
- "ucrypto",
955
960
  "ucryptolib",
956
961
  "uctypes",
957
962
  "uerrno",
@@ -974,10 +979,10 @@ def main():
974
979
  "umqtt/__init__",
975
980
  "umqtt/robust",
976
981
  "umqtt/simple",
982
+ "unittest/__init__",
977
983
  "unix",
978
984
  "uos",
979
985
  "uplatform",
980
- "uqueue",
981
986
  "urandom",
982
987
  "ure",
983
988
  "urequests",
@@ -996,6 +1001,7 @@ def main():
996
1001
  "utelnetserver",
997
1002
  "utime",
998
1003
  "utimeq",
1004
+ "uu",
999
1005
  "uwebsocket",
1000
1006
  "uzlib",
1001
1007
  "version",
@@ -18,7 +18,7 @@ Create stubs for (all) modules on a MicroPython board.
18
18
  - cross compilation, using mpy-cross, to avoid the compilation step on the micropython device
19
19
 
20
20
 
21
- This variant was generated from createstubs.py by micropython-stubber v1.24.0
21
+ This variant was generated from createstubs.py by micropython-stubber v1.24.2
22
22
  """
23
23
 
24
24
  # Copyright (c) 2019-2024 Jos Verlinde
@@ -44,7 +44,8 @@ except ImportError:
44
44
  from ucollections import OrderedDict # type: ignore
45
45
 
46
46
  __version__ = "v1.24.0"
47
- ENOENT = 2
47
+ ENOENT = 2 # on most ports
48
+ ENOMESSAGE = 44 # on pyscript
48
49
  _MAX_CLASS_LEVEL = 2 # Max class nesting
49
50
  LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
50
51
 
@@ -91,7 +92,7 @@ logging.basicConfig(level=logging.INFO)
91
92
  class Stubber:
92
93
  "Generate stubs for modules in firmware"
93
94
 
94
- def __init__(self, path: str = None, firmware_id: str = None): # type: ignore
95
+ def __init__(self, path: str = "", firmware_id: str = ""): # type: ignore
95
96
  try:
96
97
  if os.uname().release == "1.13.0" and os.uname().version < "v1.13-103": # type: ignore
97
98
  raise NotImplementedError("MicroPython 1.13.0 cannot be stubbed")
@@ -250,7 +251,7 @@ class Stubber:
250
251
  info_ = str(self.info).replace("OrderedDict(", "").replace("})", "}")
251
252
  s = '"""\nModule: \'{0}\' on {1}\n"""\n# MCU: {2}\n# Stubber: {3}\n'.format(module_name, self._fwid, info_, __version__)
252
253
  fp.write(s)
253
- fp.write("from __future__ import annotations\nfrom typing import Any, Generator\nfrom _typeshed import Incomplete\n\n")
254
+ fp.write("from __future__ import annotations\nfrom typing import Any, Final, Generator\nfrom _typeshed import Incomplete\n\n")
254
255
  self.write_object_stub(fp, new_module, module_name, "")
255
256
 
256
257
  self.report_add(module_name, file_name)
@@ -369,12 +370,16 @@ class Stubber:
369
370
  s = "{0}{1}: {3} = {2}\n".format(indent, item_name, ev[t], t)
370
371
  else:
371
372
  # something else
372
- if t in ("object", "set", "frozenset", "Pin", "generator"): # "FileIO"
373
+ if t in ("object", "set", "frozenset", "Pin"): # "FileIO"
373
374
  # https://docs.python.org/3/tutorial/classes.html#item_instance-objects
374
375
  # use these types for the attribute
375
- if t == "generator":
376
- t = "Generator"
377
376
  s = "{0}{1}: {2} ## = {4}\n".format(indent, item_name, t, item_type_txt, item_repr)
377
+ elif t == "generator":
378
+ # either a normal or async Generator function
379
+ t = "Generator"
380
+ s = "{0}def {1}(*args, **kwargs) -> Generator: ## = {4}\n{0} ...\n\n".format(
381
+ indent, item_name, t, item_type_txt, item_repr
382
+ )
378
383
  else:
379
384
  # Requires Python 3.6 syntax, which is OK for the stubs/pyi
380
385
  t = "Incomplete"
@@ -409,9 +414,9 @@ class Stubber:
409
414
  s = s.replace(c, "_")
410
415
  return s
411
416
 
412
- def clean(self, path: str = None): # type: ignore
417
+ def clean(self, path: str = ""): # type: ignore
413
418
  "Remove all files from the stub folder"
414
- if path is None:
419
+ if not path:
415
420
  path = self.path
416
421
  log.info("Clean/remove files in folder: {}".format(path))
417
422
  try:
@@ -492,7 +497,7 @@ def ensure_folder(path: str):
492
497
  _ = os.stat(p)
493
498
  except OSError as e:
494
499
  # folder does not exist
495
- if e.args[0] == ENOENT:
500
+ if e.args[0] in [ENOENT, ENOMESSAGE]:
496
501
  try:
497
502
  log.debug("Create folder {}".format(p))
498
503
  os.mkdir(p)
@@ -721,11 +726,11 @@ def is_micropython() -> bool:
721
726
 
722
727
  # b) https://docs.micropython.org/en/latest/genrst/builtin_types.html#bytes-with-keywords-not-implemented
723
728
  # Micropython: NotImplementedError
724
- b = bytes("abc", encoding="utf8") # type: ignore # lgtm [py/unused-local-variable]
729
+ b = bytes("abc", encoding="utf8") # type: ignore
725
730
 
726
731
  # c) https://docs.micropython.org/en/latest/genrst/core_language.html#function-objects-do-not-have-the-module-attribute
727
732
  # Micropython: AttributeError
728
- c = is_micropython.__module__ # type: ignore # lgtm [py/unused-local-variable]
733
+ c = is_micropython.__module__ # type: ignore
729
734
  return False
730
735
  except (NotImplementedError, AttributeError):
731
736
  return True
@@ -38,8 +38,8 @@ L='port'
38
38
  K='.'
39
39
  I=AttributeError
40
40
  H=False
41
- G='/'
42
- E=None
41
+ G=None
42
+ E='/'
43
43
  D=OSError
44
44
  C='version'
45
45
  B=''
@@ -53,8 +53,9 @@ try:from collections import OrderedDict as l
53
53
  except O:from ucollections import OrderedDict as l
54
54
  __version__='v1.24.0'
55
55
  A3=2
56
- A4=2
57
- A5=['lib','/lib','/sd/lib','/flash/lib',K]
56
+ A4=44
57
+ A5=2
58
+ A6=['lib','/lib','/sd/lib','/flash/lib',K]
58
59
  class J:
59
60
  DEBUG=10;INFO=20;WARNING=30;ERROR=40;level=INFO;prnt=P
60
61
  @staticmethod
@@ -72,7 +73,7 @@ class J:
72
73
  A=J.getLogger(t)
73
74
  J.basicConfig(level=J.INFO)
74
75
  class Stubber:
75
- def __init__(B,path=E,firmware_id=E):
76
+ def __init__(B,path=B,firmware_id=B):
76
77
  C=firmware_id
77
78
  try:
78
79
  if os.uname().release=='1.13.0'and os.uname().version<'v1.13-103':raise o('MicroPython 1.13.0 cannot be stubbed')
@@ -83,12 +84,12 @@ class Stubber:
83
84
  else:B._fwid='{family}-v{version}-{port}'.format(**B.info)
84
85
  B._start_free=F.mem_free()
85
86
  if path:
86
- if path.endswith(G):path=path[:-1]
87
+ if path.endswith(E):path=path[:-1]
87
88
  else:path=get_root()
88
- B.path='{}/stubs/{}'.format(path,B.flat_fwid).replace('//',G)
89
- try:X(path+G)
89
+ B.path='{}/stubs/{}'.format(path,B.flat_fwid).replace('//',E)
90
+ try:X(path+E)
90
91
  except D:A.error('error creating stub folder {}'.format(path))
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
92
+ 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=G;B._json_first=H
92
93
  def get_obj_attributes(L,item_instance):
93
94
  H=item_instance;C=[];K=[]
94
95
  for A in N(H):
@@ -114,39 +115,39 @@ class Stubber:
114
115
  B=module_name
115
116
  if B in C.problematic:A.warning('Skip module: {:<25} : Known problematic'.format(B));return H
116
117
  if B in C.excluded:A.warning('Skip module: {:<25} : Excluded'.format(B));return H
117
- I='{}/{}.pyi'.format(C.path,B.replace(K,G));F.collect();E=H
118
- try:E=C.create_module_stub(B,I)
118
+ I='{}/{}.pyi'.format(C.path,B.replace(K,E));F.collect();G=H
119
+ try:G=C.create_module_stub(B,I)
119
120
  except D:return H
120
- F.collect();return E
121
- def create_module_stub(J,module_name,file_name=E):
121
+ F.collect();return G
122
+ def create_module_stub(J,module_name,file_name=G):
122
123
  I=file_name;C=module_name
123
- if I is E:L=C.replace(K,'_')+'.pyi';I=J.path+G+L
124
- else:L=I.split(G)[-1]
125
- if G in C:C=C.replace(G,K)
126
- N=E
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))
124
+ if I is G:L=C.replace(K,'_')+'.pyi';I=J.path+E+L
125
+ else:L=I.split(E)[-1]
126
+ if E in C:C=C.replace(E,K)
127
+ N=G
128
+ try:N=__import__(C,G,G,'*');Q=F.mem_free();A.info('Stub module: {:<25} to file: {:<70} mem:{:>5}'.format(C,L,Q))
128
129
  except O:return H
129
130
  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
+ 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, Final, Generator\nfrom _typeshed import Incomplete\n\n');J.write_object_stub(P,N,C,B)
131
132
  J.report_add(C,I)
132
133
  if C not in{'os','sys','logging','gc'}:
133
134
  try:del N
134
135
  except(D,r):A.warning('could not del new_module')
135
136
  F.collect();return T
136
137
  def write_object_stub(L,fp,object_expr,obj_name,indent,in_class=0):
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()
138
+ Y=' at ...>';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()
138
139
  if M in L.problematic:A.warning('SKIPPING problematic module:{}'.format(M));return
139
- a,P=L.get_obj_attributes(M)
140
+ Z,P=L.get_obj_attributes(M)
140
141
  if P:A.error(P)
141
- for(C,H,I,b,d)in a:
142
+ for(C,H,I,a,c)in Z:
142
143
  if C in['classmethod','staticmethod','BaseException',N]:continue
143
144
  if C[0].isdigit():A.warning('NameError: invalid name {}'.format(C));continue
144
- if I=="<class 'type'>"and R(E)<=A4*4:
145
+ if I=="<class 'type'>"and R(E)<=A5*4:
145
146
  Q=B;S=C.endswith(N)or C.endswith('Error')or C in['KeyboardInterrupt','StopIteration','SystemExit']
146
147
  if S:Q=N
147
148
  D='\n{}class {}({}):\n'.format(E,C,Q)
148
149
  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
+ J.write(D);L.write_object_stub(J,a,'{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
151
  elif any(A in I for A in[A0,z,'closure']):
151
152
  T=V;U=B
152
153
  if O>0:U='self, '
@@ -159,14 +160,13 @@ class Stubber:
159
160
  if G in(x,v,w,y,'bytearray','bytes'):
160
161
  if C.upper()==C:D='{0}{1}: Final[{3}] = {2}\n'.format(E,C,H,G)
161
162
  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)
163
- elif G in('object','set','frozenset','Pin',Y):
164
- if G==Y:G='Generator'
165
- D='{0}{1}: {2} ## = {4}\n'.format(E,C,G,I,H)
163
+ elif G in(g,f,e):b={g:'{}',f:'[]',e:'()'};D=X.format(E,C,b[G],G)
164
+ elif G in('object','set','frozenset','Pin'):D='{0}{1}: {2} ## = {4}\n'.format(E,C,G,I,H)
165
+ elif G=='generator':G='Generator';D='{0}def {1}(*args, **kwargs) -> Generator: ## = {4}\n{0} ...\n\n'.format(E,C,G,I,H)
166
166
  else:
167
167
  G=V
168
- if K in H:H=H.split(K)[0]+Z
169
- if K in H:H=H.split(K)[0]+Z
168
+ if K in H:H=H.split(K)[0]+Y
169
+ if K in H:H=H.split(K)[0]+Y
170
170
  D='{0}{1}: {2} ## {3} = {4}\n'.format(E,C,G,I,H)
171
171
  J.write(D)
172
172
  else:J.write("# all other, type = '{0}'\n".format(I));J.write(E+C+' # type: Incomplete\n')
@@ -175,13 +175,13 @@ class Stubber:
175
175
  A=self._fwid;B=' .()/\\:$'
176
176
  for C in B:A=A.replace(C,'_')
177
177
  return A
178
- def clean(C,path=E):
179
- if path is E:path=C.path
178
+ def clean(C,path=B):
179
+ if not path:path=C.path
180
180
  A.info('Clean/remove files in folder: {}'.format(path))
181
- try:os.stat(path);F=os.listdir(path)
181
+ try:os.stat(path);E=os.listdir(path)
182
182
  except(D,I):return
183
- for G in F:
184
- B=i.format(path,G)
183
+ for F in E:
184
+ B=i.format(path,F)
185
185
  try:os.remove(B)
186
186
  except D:
187
187
  try:C.clean(B);os.rmdir(B)
@@ -189,32 +189,32 @@ class Stubber:
189
189
  def report_start(B,filename=j):
190
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()
191
191
  try:
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
192
+ with M(B._json_name,h)as E:E.write('{');E.write(dumps({H:B.info})[1:-1]);E.write(k);E.write(dumps({t:{C:__version__},'stubtype':H})[1:-1]);E.write(k);E.write('"modules" :[\n')
193
+ except D as I:A.error(A1);B._json_name=G;raise I
194
194
  def report_add(B,module_name,stub_file):
195
195
  if not B._json_name:raise s(A2)
196
196
  try:
197
197
  with M(B._json_name,'a')as C:
198
198
  if not B._json_first:C.write(k)
199
199
  else:B._json_first=H
200
- E='{{"module": "{}", "file": "{}"}}'.format(module_name,stub_file.replace('\\',G));C.write(E)
200
+ F='{{"module": "{}", "file": "{}"}}'.format(module_name,stub_file.replace('\\',E));C.write(F)
201
201
  except D:A.error(A1)
202
202
  def report_end(B):
203
203
  if not B._json_name:raise s(A2)
204
204
  with M(B._json_name,'a')as C:C.write('\n]}')
205
205
  A.info('Path: {}'.format(B.path))
206
206
  def X(path):
207
- B=E=0
207
+ B=F=0
208
208
  while B!=-1:
209
- B=path.find(G,E)
209
+ B=path.find(E,F)
210
210
  if B!=-1:
211
211
  C=path[0]if B==0 else path[:B]
212
212
  try:I=os.stat(C)
213
- except D as F:
214
- if F.args[0]==A3:
213
+ except D as G:
214
+ if G.args[0]in[A3,A4]:
215
215
  try:A.debug('Create folder {}'.format(C));os.mkdir(C)
216
216
  except D as H:A.error('failed to create folder {}'.format(C));raise H
217
- E=B+1
217
+ F=B+1
218
218
  def Y(s):
219
219
  C=' on '
220
220
  if not s:return B
@@ -225,18 +225,18 @@ def Y(s):
225
225
  if not W in s:return B
226
226
  A=s.split(W)[1].split(K)[1];return A
227
227
  def _info():
228
- a='ev3-pybricks';Z='pycom';X='pycopy';V='unix';T='win32';R='arch';P='cpu';M='ver';F='mpy';D='build'
228
+ a='ev3-pybricks';Z='pycom';X='pycopy';V='unix';T='win32';R='arch';P='cpu';M='ver';E='mpy';D='build'
229
229
  try:J=sys.implementation[0]
230
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})
231
+ A=l({S:J,C:B,D:B,M:B,L:sys.platform,U:'UNKNOWN',P:B,E:B,R:B})
232
232
  if A[L].startswith('pyb'):A[L]='stm32'
233
233
  elif A[L]==T:A[L]='windows'
234
234
  elif A[L]=='linux':A[L]=V
235
- try:A[C]=A6(sys.implementation.version)
235
+ try:A[C]=A7(sys.implementation.version)
236
236
  except I:pass
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
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[E]=sys.implementation._mpy if'_mpy'in N(sys.implementation)else sys.implementation.mpy if E in N(sys.implementation)else B
238
238
  except(I,Q):pass
239
- A[U]=A7()
239
+ A[U]=A8()
240
240
  try:
241
241
  if'uname'in N(os):
242
242
  A[D]=Y(os.uname()[3])
@@ -247,25 +247,25 @@ def _info():
247
247
  try:b=os.uname();A[C]=b.release
248
248
  except(Q,I,d):pass
249
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
250
+ try:g=__import__(e,G,G,f);A[S]=c;del g;break
251
251
  except(O,r):pass
252
252
  if A[S]==a:A['release']='2.0.0'
253
253
  if A[S]==u:
254
254
  A[C]
255
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]
256
- if F in A and A[F]:
257
- G=int(A[F])
258
- try:H=[E,'x86','x64','armv6','armv6m','armv7m','armv7em','armv7emsp','armv7emdp','xtensa','xtensawin','rv32imc'][G>>10]
256
+ if E in A and A[E]:
257
+ F=int(A[E])
258
+ try:H=[G,'x86','x64','armv6','armv6m','armv7m','armv7em','armv7emsp','armv7emdp','xtensa','xtensawin','rv32imc'][F>>10]
259
259
  except Q:H='unknown'
260
260
  if H:A[R]=H
261
- A[F]='v{}.{}'.format(G&255,G>>8&3)
261
+ A[E]='v{}.{}'.format(F&255,F>>8&3)
262
262
  if A[D]and not A[C].endswith(W):A[C]=A[C]+W
263
263
  A[M]=f"{A[C]}-{A[D]}"if A[D]else f"{A[C]}";return A
264
- def A6(version):
264
+ def A7(version):
265
265
  A=version;B=K.join([c(A)for A in A[:3]])
266
266
  if R(A)>3 and A[3]:B+=V+A[3]
267
267
  return B
268
- def A7():
268
+ def A8():
269
269
  try:from boardname import BOARDNAME as C;A.info('Found BOARDNAME: {}'.format(C))
270
270
  except O:A.warning('BOARDNAME not found');C=B
271
271
  return C
@@ -273,7 +273,7 @@ def get_root():
273
273
  try:A=os.getcwd()
274
274
  except(D,I):A=K
275
275
  B=A
276
- for B in['/remote','/sd','/flash',G,A,K]:
276
+ for B in['/remote','/sd','/flash',E,A,K]:
277
277
  try:C=os.stat(B);break
278
278
  except D:continue
279
279
  return B
@@ -295,8 +295,8 @@ def n():
295
295
  try:A=bytes('abc',encoding='utf8');B=n.__module__;return H
296
296
  except(o,I):return T
297
297
  a='modulelist.done'
298
- def A8(skip=0):
299
- for E in A5:
298
+ def A9(skip=0):
299
+ for E in A6:
300
300
  B=E+'/modulelist.txt'
301
301
  if not Z(B):continue
302
302
  try:
@@ -311,9 +311,9 @@ def A8(skip=0):
311
311
  yield A
312
312
  break
313
313
  except D:pass
314
- def A9(done):
314
+ def AA(done):
315
315
  with M(a,h)as A:A.write(c(done)+'\n')
316
- def AA():
316
+ def AB():
317
317
  A=0
318
318
  try:
319
319
  with M(a)as B:A=int(B.readline().strip())
@@ -325,11 +325,11 @@ def main():
325
325
  else:A.info('Starting new run')
326
326
  stubber=Stubber(path=read_path());B=0
327
327
  if not C:stubber.clean();stubber.report_start(j)
328
- else:B=AA();stubber._json_name=i.format(stubber.path,j)
329
- for E in A8(B):
328
+ else:B=AB();stubber._json_name=i.format(stubber.path,j)
329
+ for E in A9(B):
330
330
  try:stubber.create_one_stub(E)
331
331
  except p:D.reset()
332
- F.collect();B+=1;A9(B)
332
+ F.collect();B+=1;AA(B)
333
333
  P('All modules have been processed, Finalizing report');stubber.report_end()
334
334
  if __name__=='__main__'or n():
335
335
  if not Z('no_auto_stubber.txt'):
Binary file