micropython-stubber 1.24.4__tar.gz → 1.25.0.post1__tar.gz

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 (115) hide show
  1. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/PKG-INFO +3 -3
  2. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/pyproject.toml +10 -9
  3. micropython_stubber-1.25.0.post1/src/stubber/__init__.py +3 -0
  4. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/board/createstubs.py +22 -12
  5. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/board/createstubs_db.py +24 -14
  6. micropython_stubber-1.25.0.post1/src/stubber/board/createstubs_db_min.py +344 -0
  7. micropython_stubber-1.25.0.post1/src/stubber/board/createstubs_db_mpy.mpy +0 -0
  8. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/board/createstubs_mem.py +23 -13
  9. micropython_stubber-1.25.0.post1/src/stubber/board/createstubs_mem_min.py +320 -0
  10. micropython_stubber-1.25.0.post1/src/stubber/board/createstubs_mem_mpy.mpy +0 -0
  11. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/board/createstubs_min.py +194 -188
  12. micropython_stubber-1.25.0.post1/src/stubber/board/createstubs_mpy.mpy +0 -0
  13. micropython_stubber-1.25.0.post1/src/stubber/board/pkg_full.json +22 -0
  14. micropython_stubber-1.25.0.post1/src/stubber/board/pkg_minified.json +22 -0
  15. micropython_stubber-1.25.0.post1/src/stubber/board/pkg_mpy.json +22 -0
  16. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/bulk/mcu_stubber.py +62 -102
  17. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/codemod/_partials/db_main.py +1 -1
  18. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/codemod/merge_docstub.py +99 -18
  19. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/commands/clone_cmd.py +1 -1
  20. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/commands/get_core_cmd.py +1 -1
  21. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/commands/get_docstubs_cmd.py +3 -3
  22. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/commands/get_frozen_cmd.py +3 -3
  23. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/commands/stub_cmd.py +1 -1
  24. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/stubs_from_docs.py +2 -2
  25. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/typing_collector.py +6 -2
  26. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/utils/post.py +2 -2
  27. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/utils/repos.py +42 -6
  28. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/utils/stubmaker.py +1 -1
  29. micropython_stubber-1.24.4/src/stubber/__init__.py +0 -3
  30. micropython_stubber-1.24.4/src/stubber/board/createstubs_db_min.py +0 -339
  31. micropython_stubber-1.24.4/src/stubber/board/createstubs_db_mpy.mpy +0 -0
  32. micropython_stubber-1.24.4/src/stubber/board/createstubs_mem_min.py +0 -314
  33. micropython_stubber-1.24.4/src/stubber/board/createstubs_mem_mpy.mpy +0 -0
  34. micropython_stubber-1.24.4/src/stubber/board/createstubs_mpy.mpy +0 -0
  35. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/LICENSE +0 -0
  36. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/readme.md +0 -0
  37. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/board/board_info.csv +0 -0
  38. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/board/boot.py +0 -0
  39. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/board/createstubs_lvgl.py +0 -0
  40. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/board/createstubs_lvgl_min.py +0 -0
  41. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/board/createstubs_lvgl_mpy.mpy +0 -0
  42. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/board/fw_info.py +0 -0
  43. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/board/info.py +0 -0
  44. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/board/main.py +0 -0
  45. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/board/modulelist.txt +0 -0
  46. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/board/pyrightconfig.json +0 -0
  47. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/codemod/__init__.py +0 -0
  48. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/codemod/_partials/__init__.py +0 -0
  49. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/codemod/_partials/lvgl_main.py +0 -0
  50. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/codemod/_partials/modules_reader.py +0 -0
  51. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/codemod/add_comment.py +0 -0
  52. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/codemod/add_method.py +0 -0
  53. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/codemod/board.py +0 -0
  54. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/codemod/enrich.py +0 -0
  55. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/codemod/modify_list.py +0 -0
  56. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/codemod/utils.py +0 -0
  57. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/codemod/visitors/type_helpers.py +0 -0
  58. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/commands/__init__.py +0 -0
  59. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/commands/build_cmd.py +0 -0
  60. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/commands/cli.py +0 -0
  61. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/commands/config_cmd.py +0 -0
  62. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/commands/enrich_folder_cmd.py +0 -0
  63. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/commands/get_mcu_cmd.py +0 -0
  64. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/commands/merge_cmd.py +0 -0
  65. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/commands/publish_cmd.py +0 -0
  66. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/commands/switch_cmd.py +0 -0
  67. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/commands/variants_cmd.py +0 -0
  68. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/data/board_info.csv +0 -0
  69. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/data/board_info.json +0 -0
  70. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/data/micropython_tags.csv +0 -0
  71. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/data/requirements-core-micropython.txt +0 -0
  72. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/data/requirements-core-pycopy.txt +0 -0
  73. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/downloader.py +0 -0
  74. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/freeze/__init__.py +0 -0
  75. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/freeze/common.py +0 -0
  76. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/freeze/freeze_folder.py +0 -0
  77. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/freeze/freeze_manifest_2.py +0 -0
  78. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/freeze/get_frozen.py +0 -0
  79. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/get_cpython.py +0 -0
  80. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/get_lobo.py +0 -0
  81. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/merge_config.py +0 -0
  82. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/minify.py +0 -0
  83. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/modcat.py +0 -0
  84. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/publish/__init__.py +0 -0
  85. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/publish/bump.py +0 -0
  86. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/publish/candidates.py +0 -0
  87. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/publish/database.py +0 -0
  88. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/publish/defaults.py +0 -0
  89. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/publish/enums.py +0 -0
  90. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/publish/helpers.py +0 -0
  91. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/publish/merge_docstubs.py +0 -0
  92. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/publish/package.py +0 -0
  93. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/publish/pathnames.py +0 -0
  94. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/publish/publish.py +0 -0
  95. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/publish/pypi.py +0 -0
  96. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/publish/stubpackage.py +0 -0
  97. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/rst/__init__.py +0 -0
  98. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/rst/classsort.py +0 -0
  99. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/rst/lookup.py +0 -0
  100. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/rst/output_dict.py +0 -0
  101. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/rst/reader.py +0 -0
  102. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/rst/report_return.py +0 -0
  103. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/rst/rst_utils.py +0 -0
  104. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/stubber.py +0 -0
  105. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/tools/__init__.py +0 -0
  106. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/tools/manifestfile.py +0 -0
  107. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/tools/readme.md +0 -0
  108. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/update_fallback.py +0 -0
  109. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/update_module_list.py +0 -0
  110. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/utils/__init__.py +0 -0
  111. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/utils/config.py +0 -0
  112. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/utils/makeversionhdr.py +0 -0
  113. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/utils/manifest.py +0 -0
  114. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/utils/typed_config_toml.py +0 -0
  115. {micropython_stubber-1.24.4 → micropython_stubber-1.25.0.post1}/src/stubber/variants.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: micropython-stubber
3
- Version: 1.24.4
3
+ Version: 1.25.0.post1
4
4
  Summary: Tooling to create and maintain stubs for MicroPython
5
5
  License: MIT
6
6
  Keywords: MicroPython,stubs,vscode,pyright,linting,static type check
@@ -25,7 +25,7 @@ Requires-Dist: executing (>=2.0.1,<3.0.0)
25
25
  Requires-Dist: importlib-metadata (>=1,<9) ; python_version < "3.8"
26
26
  Requires-Dist: libcst (>=1.1.0,<2.0.0)
27
27
  Requires-Dist: loguru (>=0.6,<0.8)
28
- Requires-Dist: mpflash (>=1.24.7)
28
+ Requires-Dist: mpflash (>=1.25.0)
29
29
  Requires-Dist: mpremote (>=1.24.1)
30
30
  Requires-Dist: mypy (>=1.10)
31
31
  Requires-Dist: mypy-gitlab-code-quality (>=1.1.0,<2.0.0)
@@ -40,7 +40,7 @@ Requires-Dist: pyserial (>=3.5)
40
40
  Requires-Dist: python-minifier (>=2.7.0,<3.0.0) ; python_version < "3.14"
41
41
  Requires-Dist: requests (>=2.32.3,<3.0.0)
42
42
  Requires-Dist: rich-click (>=1.8.3,<2.0.0)
43
- Requires-Dist: tenacity (>=8.2.2,<9.0.0)
43
+ Requires-Dist: tenacity (==9.0.0)
44
44
  Requires-Dist: tomli (>=2.0.1,<3.0.0) ; python_version < "3.11"
45
45
  Requires-Dist: tomli-w (>=1.0.0,<2.0.0)
46
46
  Requires-Dist: typed-config (>=1.3.0,<2.0.0)
@@ -8,7 +8,7 @@ repo-path = "./repos"
8
8
 
9
9
  [tool.poetry]
10
10
  name = "micropython-stubber"
11
- version = "1.24.4"
11
+ version = "1.25.0.post1"
12
12
  description = "Tooling to create and maintain stubs for MicroPython"
13
13
  authors = ["Jos Verlinde <jos_verlinde@hotmail.com>"]
14
14
  license = "MIT"
@@ -50,8 +50,7 @@ mpremote = "mpremote.main:main"
50
50
  python = ">=3.9.2,<4.0"
51
51
  python-minifier = { version = "^2.7.0", python = "<3.14" }
52
52
  requests = "^2.32.3"
53
- mypy = ">=1.10"
54
- mpflash = ">=1.24.7"
53
+ mpflash = ">=1.25.0"
55
54
  mpremote = ">=1.24.1"
56
55
  # others
57
56
  autoflake = ">=1.7,<3.0"
@@ -66,27 +65,29 @@ mypy-gitlab-code-quality = "^1.1.0"
66
65
  packaging = "^24.2"
67
66
  pipx = "^1.1.0"
68
67
  pygithub = "^2.1.1"
69
- pyright = ">=1.1.341"
70
68
  pyserial = ">=3.5"
71
69
  pypi-simple = "^1.0.0"
72
70
  rich-click = "^1.8.3"
73
- tenacity = "^8.2.2"
71
+ tenacity = "9.0.0"
74
72
  tomli = { version = "^2.0.1", python = "<3.11" }
75
73
  tomli-w = "^1.0.0"
76
74
  typed-config = "^1.3.0"
77
75
  urllib3 = "^2.2.2"
78
76
  poetry = "^2.0.1"
79
77
  pydeps = "3.0.1"
78
+ pyright = ">=1.1.341"
79
+ mypy = ">=1.10"
80
+
80
81
 
81
82
  [tool.poetry.group.docs]
82
83
  optional = true
83
84
  [tool.poetry.group.docs.dependencies]
84
- sphinx = "^7.2.6"
85
- myst-parser = ">=0.17"
85
+ sphinx = "^7.4.7"
86
+ myst-parser = "^3.0.1"
86
87
  sphinx_rtd_theme = ">=1,<3"
87
- sphinx-autoapi = "^3.0.0"
88
+ sphinx-autoapi = "^3.6.0"
88
89
  sphinx-click = "6.0.0"
89
- sphinxcontrib-mermaid = ">=0.9.2"
90
+ sphinxcontrib-mermaid = ">=1.0.0"
90
91
 
91
92
  [tool.poetry.group.test]
92
93
  optional = true
@@ -0,0 +1,3 @@
1
+ """get the version"""
2
+
3
+ __version__ = "1.25.0"
@@ -24,7 +24,7 @@ try:
24
24
  except ImportError:
25
25
  from ucollections import OrderedDict # type: ignore
26
26
 
27
- __version__ = "v1.24.0"
27
+ __version__ = "v1.25.0"
28
28
  ENOENT = 2 # on most ports
29
29
  ENOMESSAGE = 44 # on pyscript
30
30
  _MAX_CLASS_LEVEL = 2 # Max class nesting
@@ -82,12 +82,13 @@ class Stubber:
82
82
  self.info = _info()
83
83
  log.info("Port: {}".format(self.info["port"]))
84
84
  log.info("Board: {}".format(self.info["board"]))
85
+ log.info("Board_ID: {}".format(self.info["board_id"]))
85
86
  gc.collect()
86
87
  if firmware_id:
87
88
  self._fwid = firmware_id.lower()
88
89
  else:
89
90
  if self.info["family"] == "micropython":
90
- self._fwid = "{family}-v{version}-{port}-{board}".format(**self.info).rstrip("-")
91
+ self._fwid = "{family}-v{version}-{port}-{board_id}".format(**self.info).rstrip("-")
91
92
  else:
92
93
  self._fwid = "{family}-v{version}-{port}".format(**self.info)
93
94
  self._start_free = gc.mem_free() # type: ignore
@@ -545,6 +546,8 @@ def _info(): # type:() -> dict[str, str]
545
546
  "ver": "",
546
547
  "port": sys.platform, # port: esp32 / win32 / linux / stm32
547
548
  "board": "UNKNOWN",
549
+ "board_id": "",
550
+ "variant": "",
548
551
  "cpu": "",
549
552
  "mpy": "",
550
553
  "arch": "",
@@ -565,8 +568,12 @@ def _info(): # type:() -> dict[str, str]
565
568
  _machine = (
566
569
  sys.implementation._machine if "_machine" in dir(sys.implementation) else os.uname().machine # type: ignore
567
570
  )
568
- # info["board"] = "with".join(_machine.split("with")[:-1]).strip()
569
- info["board"] = _machine
571
+ info["board"] = _machine.strip()
572
+ si_build = sys.implementation._build if "_build" in dir(sys.implementation) else ""
573
+ if si_build:
574
+ info["board"] = si_build.split("-")[0]
575
+ info["variant"] = si_build.split("-")[1] if "-" in si_build else ""
576
+ info["board_id"] = si_build
570
577
  info["cpu"] = _machine.split("with")[-1].strip()
571
578
  info["mpy"] = (
572
579
  sys.implementation._mpy # type: ignore
@@ -575,7 +582,8 @@ def _info(): # type:() -> dict[str, str]
575
582
  )
576
583
  except (AttributeError, IndexError):
577
584
  pass
578
- info["board"] = get_boardname()
585
+ if not info["board_id"]:
586
+ get_boardname(info)
579
587
 
580
588
  try:
581
589
  if "uname" in dir(os): # old
@@ -668,16 +676,18 @@ def version_str(version: tuple): # -> str:
668
676
  return v_str
669
677
 
670
678
 
671
- def get_boardname() -> str:
672
- "Read the board name from the boardname.py file that may have been created upfront"
679
+ def get_boardname(info: dict) -> str:
680
+ "Read the board_id from the boardname.py file that may have been created upfront"
673
681
  try:
674
- from boardname import BOARDNAME # type: ignore
682
+ from boardname import BOARD_ID # type: ignore
675
683
 
676
- log.info("Found BOARDNAME: {}".format(BOARDNAME))
684
+ log.info("Found BOARD_ID: {}".format(BOARD_ID))
677
685
  except ImportError:
678
- log.warning("BOARDNAME not found")
679
- BOARDNAME = ""
680
- return BOARDNAME
686
+ log.warning("BOARD_ID not found")
687
+ BOARD_ID = ""
688
+ info["board_id"] = BOARD_ID
689
+ info["board"] = BOARD_ID.split("-")[0] if "-" in BOARD_ID else BOARD_ID
690
+ info["variant"] == BOARD_ID.split("-")[1] if "-" in BOARD_ID else ""
681
691
 
682
692
 
683
693
  def get_root() -> str: # sourcery skip: use-assigned-variable
@@ -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.3
21
+ This variant was generated from createstubs.py by micropython-stubber v1.24.4
22
22
  """
23
23
 
24
24
  # Copyright (c) 2019-2024 Jos Verlinde
@@ -43,7 +43,7 @@ try:
43
43
  except ImportError:
44
44
  from ucollections import OrderedDict # type: ignore
45
45
 
46
- __version__ = "v1.24.0"
46
+ __version__ = "v1.25.0"
47
47
  ENOENT = 2 # on most ports
48
48
  ENOMESSAGE = 44 # on pyscript
49
49
  _MAX_CLASS_LEVEL = 2 # Max class nesting
@@ -101,12 +101,13 @@ class Stubber:
101
101
  self.info = _info()
102
102
  log.info("Port: {}".format(self.info["port"]))
103
103
  log.info("Board: {}".format(self.info["board"]))
104
+ log.info("Board_ID: {}".format(self.info["board_id"]))
104
105
  gc.collect()
105
106
  if firmware_id:
106
107
  self._fwid = firmware_id.lower()
107
108
  else:
108
109
  if self.info["family"] == "micropython":
109
- self._fwid = "{family}-v{version}-{port}-{board}".format(**self.info).rstrip("-")
110
+ self._fwid = "{family}-v{version}-{port}-{board_id}".format(**self.info).rstrip("-")
110
111
  else:
111
112
  self._fwid = "{family}-v{version}-{port}".format(**self.info)
112
113
  self._start_free = gc.mem_free() # type: ignore
@@ -541,6 +542,8 @@ def _info(): # type:() -> dict[str, str]
541
542
  "ver": "",
542
543
  "port": sys.platform, # port: esp32 / win32 / linux / stm32
543
544
  "board": "UNKNOWN",
545
+ "board_id": "",
546
+ "variant": "",
544
547
  "cpu": "",
545
548
  "mpy": "",
546
549
  "arch": "",
@@ -559,8 +562,12 @@ def _info(): # type:() -> dict[str, str]
559
562
  pass
560
563
  try:
561
564
  _machine = sys.implementation._machine if "_machine" in dir(sys.implementation) else os.uname().machine # type: ignore
562
- # info["board"] = "with".join(_machine.split("with")[:-1]).strip()
563
- info["board"] = _machine
565
+ info["board"] = _machine.strip()
566
+ si_build = sys.implementation._build if "_build" in dir(sys.implementation) else ""
567
+ if si_build:
568
+ info["board"] = si_build.split("-")[0]
569
+ info["variant"] = si_build.split("-")[1] if "-" in si_build else ""
570
+ info["board_id"] = si_build
564
571
  info["cpu"] = _machine.split("with")[-1].strip()
565
572
  info["mpy"] = (
566
573
  sys.implementation._mpy # type: ignore
@@ -569,7 +576,8 @@ def _info(): # type:() -> dict[str, str]
569
576
  )
570
577
  except (AttributeError, IndexError):
571
578
  pass
572
- info["board"] = get_boardname()
579
+ if not info["board_id"]:
580
+ get_boardname(info)
573
581
 
574
582
  try:
575
583
  if "uname" in dir(os): # old
@@ -661,16 +669,18 @@ def version_str(version: tuple): # -> str:
661
669
  return v_str
662
670
 
663
671
 
664
- def get_boardname() -> str:
665
- "Read the board name from the boardname.py file that may have been created upfront"
672
+ def get_boardname(info: dict) -> str:
673
+ "Read the board_id from the boardname.py file that may have been created upfront"
666
674
  try:
667
- from boardname import BOARDNAME # type: ignore
675
+ from boardname import BOARD_ID # type: ignore
668
676
 
669
- log.info("Found BOARDNAME: {}".format(BOARDNAME))
677
+ log.info("Found BOARD_ID: {}".format(BOARD_ID))
670
678
  except ImportError:
671
- log.warning("BOARDNAME not found")
672
- BOARDNAME = ""
673
- return BOARDNAME
679
+ log.warning("BOARD_ID not found")
680
+ BOARD_ID = ""
681
+ info["board_id"] = BOARD_ID
682
+ info["board"] = BOARD_ID.split("-")[0] if "-" in BOARD_ID else BOARD_ID
683
+ info["variant"] == BOARD_ID.split("-")[1] if "-" in BOARD_ID else ""
674
684
 
675
685
 
676
686
  def get_root() -> str: # sourcery skip: use-assigned-variable
@@ -746,7 +756,7 @@ def get_modules(skip=0):
746
756
  if not file_exists(fname):
747
757
  continue
748
758
  try:
749
- with open(fname) as f:
759
+ with open(fname, encoding="utf-8") as f:
750
760
  i = 0
751
761
  while True:
752
762
  line = f.readline().strip()
@@ -0,0 +1,344 @@
1
+ A3='No report file'
2
+ A2='Failed to create the report.'
3
+ A1='method'
4
+ A0='function'
5
+ z='str'
6
+ y='float'
7
+ x='int'
8
+ w='micropython'
9
+ v='stubber'
10
+ u=Exception
11
+ t=KeyError
12
+ s=sorted
13
+ r=MemoryError
14
+ q=NotImplementedError
15
+ m='variant'
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=True
28
+ V='family'
29
+ U='board_id'
30
+ T='board'
31
+ S=len
32
+ R=IndexError
33
+ Q=print
34
+ P=ImportError
35
+ O=open
36
+ N=dir
37
+ M='port'
38
+ L='.'
39
+ J=AttributeError
40
+ I=False
41
+ H=None
42
+ G='/'
43
+ E='-'
44
+ D=OSError
45
+ C='version'
46
+ B=''
47
+ import gc as F,os,sys
48
+ from time import sleep
49
+ try:from ujson import dumps
50
+ except:from json import dumps
51
+ try:from machine import reset
52
+ except P:pass
53
+ try:from collections import OrderedDict as n
54
+ except P:from ucollections import OrderedDict as n
55
+ __version__='v1.25.0'
56
+ A4=2
57
+ A5=44
58
+ A6=2
59
+ A7=['lib','/lib','/sd/lib','/flash/lib',L]
60
+ class K:
61
+ DEBUG=10;INFO=20;WARNING=30;ERROR=40;level=INFO;prnt=Q
62
+ @staticmethod
63
+ def getLogger(name):return K()
64
+ @classmethod
65
+ def basicConfig(A,level):A.level=level
66
+ def debug(A,msg):
67
+ if A.level<=K.DEBUG:A.prnt('DEBUG :',msg)
68
+ def info(A,msg):
69
+ if A.level<=K.INFO:A.prnt('INFO :',msg)
70
+ def warning(A,msg):
71
+ if A.level<=K.WARNING:A.prnt('WARN :',msg)
72
+ def error(A,msg):
73
+ if A.level<=K.ERROR:A.prnt('ERROR :',msg)
74
+ A=K.getLogger(v)
75
+ K.basicConfig(level=K.INFO)
76
+ class Stubber:
77
+ def __init__(B,path=B,firmware_id=B):
78
+ C=firmware_id
79
+ try:
80
+ if os.uname().release=='1.13.0'and os.uname().version<'v1.13-103':raise q('MicroPython 1.13.0 cannot be stubbed')
81
+ except J:pass
82
+ B.info=_info();A.info('Port: {}'.format(B.info[M]));A.info('Board: {}'.format(B.info[T]));A.info('Board_ID: {}'.format(B.info[U]));F.collect()
83
+ if C:B._fwid=C.lower()
84
+ elif B.info[V]==w:B._fwid='{family}-v{version}-{port}-{board_id}'.format(**B.info).rstrip(E)
85
+ else:B._fwid='{family}-v{version}-{port}'.format(**B.info)
86
+ B._start_free=F.mem_free()
87
+ if path:
88
+ if path.endswith(G):path=path[:-1]
89
+ else:path=get_root()
90
+ B.path='{}/stubs/{}'.format(path,B.flat_fwid).replace('//',G)
91
+ try:Y(path+G)
92
+ except D:A.error('error creating stub folder {}'.format(path))
93
+ 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=H;B._json_first=I
94
+ def get_obj_attributes(L,item_instance):
95
+ H=item_instance;C=[];K=[]
96
+ for A in N(H):
97
+ if A.startswith('__')and not A in L.modules:continue
98
+ try:
99
+ D=getattr(H,A)
100
+ try:E=c(type(D)).split("'")[1]
101
+ except R:E=B
102
+ if E in{x,y,z,'bool',f,g,h}:G=1
103
+ elif E in{A0,A1}:G=2
104
+ elif E in'class':G=3
105
+ else:G=4
106
+ C.append((A,c(D),c(type(D)),D,G))
107
+ except J as I:K.append("Couldn't get attribute '{}' from object '{}', Err: {}".format(A,H,I))
108
+ except r as I:Q('MemoryError: {}'.format(I));sleep(1);reset()
109
+ C=s([A for A in C if not A[0].startswith('__')],key=lambda x:x[4]);F.collect();return C,K
110
+ def add_modules(A,modules):A.modules=s(set(A.modules)|set(modules))
111
+ def create_all_stubs(B):
112
+ A.info('Start micropython-stubber {} on {}'.format(__version__,B._fwid));B.report_start();F.collect()
113
+ for C in B.modules:B.create_one_stub(C)
114
+ B.report_end();A.info('Finally done')
115
+ def create_one_stub(C,module_name):
116
+ B=module_name
117
+ if B in C.problematic:A.warning('Skip module: {:<25} : Known problematic'.format(B));return I
118
+ if B in C.excluded:A.warning('Skip module: {:<25} : Excluded'.format(B));return I
119
+ H='{}/{}.pyi'.format(C.path,B.replace(L,G));F.collect();E=I
120
+ try:E=C.create_module_stub(B,H)
121
+ except D:return I
122
+ F.collect();return E
123
+ def create_module_stub(J,module_name,file_name=H):
124
+ E=file_name;C=module_name
125
+ if E is H:K=C.replace(L,'_')+'.pyi';E=J.path+G+K
126
+ else:K=E.split(G)[-1]
127
+ if G in C:C=C.replace(G,L)
128
+ M=H
129
+ try:M=__import__(C,H,H,'*');Q=F.mem_free();A.info('Stub module: {:<25} to file: {:<70} mem:{:>5}'.format(C,K,Q))
130
+ except P:return I
131
+ Y(E)
132
+ with O(E,i)as N:R=d(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__);N.write(S);N.write('from __future__ import annotations\nfrom typing import Any, Final, Generator\nfrom _typeshed import Incomplete\n\n');J.write_object_stub(N,M,C,B)
133
+ J.report_add(C,E)
134
+ if C not in{'os','sys','logging','gc'}:
135
+ try:del M
136
+ except(D,t):A.warning('could not del new_module')
137
+ F.collect();return W
138
+ def write_object_stub(L,fp,object_expr,obj_name,indent,in_class=0):
139
+ 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()
140
+ if M in L.problematic:A.warning('SKIPPING problematic module:{}'.format(M));return
141
+ Z,P=L.get_obj_attributes(M)
142
+ if P:A.error(P)
143
+ for(C,H,I,a,c)in Z:
144
+ if C in['classmethod','staticmethod','BaseException',N]:continue
145
+ if C[0].isdigit():A.warning('NameError: invalid name {}'.format(C));continue
146
+ if I=="<class 'type'>"and S(E)<=A6*4:
147
+ Q=B;R=C.endswith(N)or C.endswith('Error')or C in['KeyboardInterrupt','StopIteration','SystemExit']
148
+ if R:Q=N
149
+ D='\n{}class {}({}):\n'.format(E,C,Q)
150
+ if R:D+=E+' ...\n';J.write(D);continue
151
+ 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)
152
+ elif any(A in I for A in[A1,A0,'closure']):
153
+ T=V;U=B
154
+ if O>0:U='self, '
155
+ if W in I or W in H:D='{}@classmethod\n'.format(E)+'{}def {}(cls, *args, **kwargs) -> {}:\n'.format(E,C,T)
156
+ else:D='{}def {}({}*args, **kwargs) -> {}:\n'.format(E,C,U,T)
157
+ D+=E+' ...\n\n';J.write(D)
158
+ elif I=="<class 'module'>":0
159
+ elif I.startswith("<class '"):
160
+ G=I[8:-2];D=B
161
+ if G in(z,x,y,'bool','bytearray','bytes'):
162
+ if C.upper()==C:D='{0}{1}: Final[{3}] = {2}\n'.format(E,C,H,G)
163
+ else:D=X.format(E,C,H,G)
164
+ elif G in(h,g,f):b={h:'{}',g:'[]',f:'()'};D=X.format(E,C,b[G],G)
165
+ elif G in('object','set','frozenset','Pin'):D='{0}{1}: {2} ## = {4}\n'.format(E,C,G,I,H)
166
+ elif G=='generator':G='Generator';D='{0}def {1}(*args, **kwargs) -> Generator: ## = {4}\n{0} ...\n\n'.format(E,C,G,I,H)
167
+ else:
168
+ G=V
169
+ if K in H:H=H.split(K)[0]+Y
170
+ if K in H:H=H.split(K)[0]+Y
171
+ D='{0}{1}: {2} ## {3} = {4}\n'.format(E,C,G,I,H)
172
+ J.write(D)
173
+ else:J.write("# all other, type = '{0}'\n".format(I));J.write(E+C+' # type: Incomplete\n')
174
+ @property
175
+ def flat_fwid(self):
176
+ A=self._fwid;B=' .()/\\:$'
177
+ for C in B:A=A.replace(C,'_')
178
+ return A
179
+ def clean(C,path=B):
180
+ if not path:path=C.path
181
+ A.info('Clean/remove files in folder: {}'.format(path))
182
+ try:os.stat(path);E=os.listdir(path)
183
+ except(D,J):return
184
+ for F in E:
185
+ B=j.format(path,F)
186
+ try:os.remove(B)
187
+ except D:
188
+ try:C.clean(B);os.rmdir(B)
189
+ except D:pass
190
+ def report_start(B,filename=k):
191
+ G='firmware';B._json_name=j.format(B.path,filename);B._json_first=W;Y(B._json_name);A.info('Report file: {}'.format(B._json_name));F.collect()
192
+ try:
193
+ with O(B._json_name,i)as E:E.write('{');E.write(dumps({G:B.info})[1:-1]);E.write(l);E.write(dumps({v:{C:__version__},'stubtype':G})[1:-1]);E.write(l);E.write('"modules" :[\n')
194
+ except D as I:A.error(A2);B._json_name=H;raise I
195
+ def report_add(B,module_name,stub_file):
196
+ if not B._json_name:raise u(A3)
197
+ try:
198
+ with O(B._json_name,'a')as C:
199
+ if not B._json_first:C.write(l)
200
+ else:B._json_first=I
201
+ E='{{"module": "{}", "file": "{}"}}'.format(module_name,stub_file.replace('\\',G));C.write(E)
202
+ except D:A.error(A2)
203
+ def report_end(B):
204
+ if not B._json_name:raise u(A3)
205
+ with O(B._json_name,'a')as C:C.write('\n]}')
206
+ A.info('Path: {}'.format(B.path))
207
+ def Y(path):
208
+ B=E=0
209
+ while B!=-1:
210
+ B=path.find(G,E)
211
+ if B!=-1:
212
+ C=path[0]if B==0 else path[:B]
213
+ try:I=os.stat(C)
214
+ except D as F:
215
+ if F.args[0]in[A4,A5]:
216
+ try:A.debug('Create folder {}'.format(C));os.mkdir(C)
217
+ except D as H:A.error('failed to create folder {}'.format(C));raise H
218
+ E=B+1
219
+ def Z(s):
220
+ C=' on '
221
+ if not s:return B
222
+ s=s.split(C,1)[0]if C in s else s
223
+ if s.startswith('v'):
224
+ if not E in s:return B
225
+ A=s.split(E)[1];return A
226
+ if not X in s:return B
227
+ A=s.split(X)[1].split(L)[1];return A
228
+ def _info():
229
+ d='ev3-pybricks';c='pycom';b='pycopy';a='unix';Y='win32';W='arch';S='cpu';Q='ver';F='mpy';D='build'
230
+ try:L=sys.implementation[0]
231
+ except e:L=sys.implementation.name
232
+ A=n({V:L,C:B,D:B,Q:B,M:sys.platform,T:'UNKNOWN',U:B,m:B,S:B,F:B,W:B})
233
+ if A[M].startswith('pyb'):A[M]='stm32'
234
+ elif A[M]==Y:A[M]='windows'
235
+ elif A[M]=='linux':A[M]=a
236
+ try:A[C]=A8(sys.implementation.version)
237
+ except J:pass
238
+ try:
239
+ O=sys.implementation._machine if'_machine'in N(sys.implementation)else os.uname().machine;A[T]=O.strip();G=sys.implementation._build if'_build'in N(sys.implementation)else B
240
+ if G:A[T]=G.split(E)[0];A[m]=G.split(E)[1]if E in G else B
241
+ A[U]=G;A[S]=O.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
242
+ except(J,R):pass
243
+ if not A[U]:A9(A)
244
+ try:
245
+ if'uname'in N(os):
246
+ A[D]=Z(os.uname()[3])
247
+ if not A[D]:A[D]=Z(os.uname()[2])
248
+ elif C in N(sys):A[D]=Z(sys.version)
249
+ except(J,R,e):pass
250
+ if A[C]==B and sys.platform not in(a,Y):
251
+ try:f=os.uname();A[C]=f.release
252
+ except(R,J,e):pass
253
+ for(g,h,i)in[(b,b,'const'),(c,c,'FAT'),(d,'pybricks.hubs','EV3Brick')]:
254
+ try:j=__import__(h,H,H,i);A[V]=g;del j;break
255
+ except(P,t):pass
256
+ if A[V]==d:A['release']='2.0.0'
257
+ if A[V]==w:
258
+ A[C]
259
+ 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]
260
+ if F in A and A[F]:
261
+ I=int(A[F])
262
+ try:K=[H,'x86','x64','armv6','armv6m','armv7m','armv7em','armv7emsp','armv7emdp','xtensa','xtensawin','rv32imc'][I>>10]
263
+ except R:K='unknown'
264
+ if K:A[W]=K
265
+ A[F]='v{}.{}'.format(I&255,I>>8&3)
266
+ if A[D]and not A[C].endswith(X):A[C]=A[C]+X
267
+ A[Q]=f"{A[C]}-{A[D]}"if A[D]else f"{A[C]}";return A
268
+ def A8(version):
269
+ A=version;B=L.join([d(A)for A in A[:3]])
270
+ if S(A)>3 and A[3]:B+=E+A[3]
271
+ return B
272
+ def A9(info):
273
+ D=info
274
+ try:from boardname import BOARD_ID as C;A.info('Found BOARD_ID: {}'.format(C))
275
+ except P:A.warning('BOARD_ID not found');C=B
276
+ D[U]=C;D[T]=C.split(E)[0]if E in C else C;D[m]==C.split(E)[1]if E in C else B
277
+ def get_root():
278
+ try:A=os.getcwd()
279
+ except(D,J):A=L
280
+ B=A
281
+ for B in['/remote','/sd','/flash',G,A,L]:
282
+ try:C=os.stat(B);break
283
+ except D:continue
284
+ return B
285
+ def a(filename):
286
+ try:
287
+ if os.stat(filename)[0]>>14:return W
288
+ return I
289
+ except D:return I
290
+ def o():Q("-p, --path path to store the stubs in, defaults to '.'");sys.exit(1)
291
+ def read_path():
292
+ path=B
293
+ if S(sys.argv)==3:
294
+ A=sys.argv[1].lower()
295
+ if A in('--path','-p'):path=sys.argv[2]
296
+ else:o()
297
+ elif S(sys.argv)==2:o()
298
+ return path
299
+ def p():
300
+ try:A=bytes('abc',encoding='utf8');B=p.__module__;return I
301
+ except(q,J):return W
302
+ b='modulelist.done'
303
+ def AA(skip=0):
304
+ for E in A7:
305
+ B=E+'/modulelist.txt'
306
+ if not a(B):continue
307
+ try:
308
+ with O(B,encoding='utf-8')as F:
309
+ C=0
310
+ while W:
311
+ A=F.readline().strip()
312
+ if not A:break
313
+ if S(A)>0 and A[0]=='#':continue
314
+ C+=1
315
+ if C<skip:continue
316
+ yield A
317
+ break
318
+ except D:pass
319
+ def AB(done):
320
+ with O(b,i)as A:A.write(d(done)+'\n')
321
+ def AC():
322
+ A=0
323
+ try:
324
+ with O(b)as B:A=int(B.readline().strip())
325
+ except D:pass
326
+ return A
327
+ def main():
328
+ import machine as D;C=a(b)
329
+ if C:A.info('Continue from last run')
330
+ else:A.info('Starting new run')
331
+ stubber=Stubber(path=read_path());B=0
332
+ if not C:stubber.clean();stubber.report_start(k)
333
+ else:B=AC();stubber._json_name=j.format(stubber.path,k)
334
+ for E in AA(B):
335
+ try:stubber.create_one_stub(E)
336
+ except r:D.reset()
337
+ F.collect();B+=1;AB(B)
338
+ Q('All modules have been processed, Finalizing report');stubber.report_end()
339
+ if __name__=='__main__'or p():
340
+ if not a('no_auto_stubber.txt'):
341
+ Q(f"createstubs.py: {__version__}")
342
+ try:F.threshold(4096);F.enable()
343
+ except BaseException:pass
344
+ main()