micropython-stubber 1.17.6__py3-none-any.whl → 1.20.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 (83) hide show
  1. {micropython_stubber-1.17.6.dist-info → micropython_stubber-1.20.0.dist-info}/METADATA +7 -6
  2. micropython_stubber-1.20.0.dist-info/RECORD +147 -0
  3. mpflash/README.md +18 -2
  4. mpflash/libusb_flash.ipynb +203 -0
  5. mpflash/mpflash/ask_input.py +234 -0
  6. mpflash/mpflash/cli_download.py +107 -0
  7. mpflash/mpflash/cli_flash.py +170 -0
  8. mpflash/mpflash/cli_group.py +40 -7
  9. mpflash/mpflash/cli_list.py +41 -0
  10. mpflash/mpflash/cli_main.py +13 -8
  11. mpflash/mpflash/common.py +33 -121
  12. mpflash/mpflash/config.py +9 -0
  13. mpflash/mpflash/{downloader.py → download.py} +110 -96
  14. mpflash/mpflash/downloaded.py +108 -0
  15. mpflash/mpflash/errors.py +5 -0
  16. mpflash/mpflash/flash.py +69 -0
  17. mpflash/mpflash/flash_esp.py +17 -23
  18. mpflash/mpflash/flash_stm32.py +16 -113
  19. mpflash/mpflash/flash_stm32_cube.py +111 -0
  20. mpflash/mpflash/flash_stm32_dfu.py +101 -0
  21. mpflash/mpflash/flash_uf2.py +8 -8
  22. mpflash/mpflash/flash_uf2_linux.py +13 -6
  23. mpflash/mpflash/flash_uf2_windows.py +24 -12
  24. mpflash/mpflash/list.py +56 -39
  25. mpflash/mpflash/logger.py +12 -13
  26. mpflash/mpflash/mpboard_id/__init__.py +96 -0
  27. mpflash/mpflash/mpboard_id/board_id.py +63 -0
  28. mpflash/mpflash/mpboard_id/board_info.csv +2213 -0
  29. mpflash/mpflash/mpboard_id/board_info.json +19910 -0
  30. mpflash/mpflash/mpremoteboard/__init__.py +209 -0
  31. mpflash/mpflash/mpremoteboard/mpy_fw_info.py +141 -0
  32. {stubber/bulk → mpflash/mpflash/mpremoteboard}/runner.py +19 -4
  33. mpflash/mpflash/vendor/dfu.py +164 -0
  34. mpflash/mpflash/vendor/pydfu.py +605 -0
  35. mpflash/mpflash/vendor/readme.md +3 -0
  36. mpflash/mpflash/vendor/versions.py +113 -0
  37. mpflash/mpflash/worklist.py +147 -0
  38. mpflash/poetry.lock +427 -610
  39. mpflash/pyproject.toml +22 -6
  40. mpflash/stm32_udev_rules.md +63 -0
  41. stubber/__init__.py +1 -1
  42. stubber/basicgit.py +1 -0
  43. stubber/board/createstubs.py +11 -4
  44. stubber/board/createstubs_db.py +11 -5
  45. stubber/board/createstubs_db_min.py +61 -58
  46. stubber/board/createstubs_db_mpy.mpy +0 -0
  47. stubber/board/createstubs_mem.py +11 -5
  48. stubber/board/createstubs_mem_min.py +56 -53
  49. stubber/board/createstubs_mem_mpy.mpy +0 -0
  50. stubber/board/createstubs_min.py +54 -51
  51. stubber/board/createstubs_mpy.mpy +0 -0
  52. stubber/board/modulelist.txt +1 -0
  53. stubber/bulk/mcu_stubber.py +9 -5
  54. stubber/codemod/_partials/db_main.py +14 -25
  55. stubber/codemod/_partials/lvgl_main.py +2 -2
  56. stubber/codemod/board.py +10 -3
  57. stubber/commands/clone_cmd.py +7 -7
  58. stubber/commands/config_cmd.py +3 -0
  59. stubber/commands/{mcu_cmd.py → get_mcu_cmd.py} +20 -3
  60. stubber/freeze/get_frozen.py +0 -2
  61. stubber/publish/candidates.py +1 -1
  62. stubber/publish/package.py +1 -1
  63. stubber/publish/pathnames.py +1 -1
  64. stubber/publish/stubpackage.py +1 -0
  65. stubber/rst/lookup.py +1 -1
  66. stubber/stubber.py +1 -9
  67. stubber/tools/manifestfile.py +5 -3
  68. stubber/update_fallback.py +104 -104
  69. stubber/utils/config.py +32 -36
  70. stubber/utils/repos.py +2 -2
  71. stubber/utils/versions.py +1 -0
  72. micropython_stubber-1.17.6.dist-info/RECORD +0 -132
  73. mpflash/mpflash/flasher.py +0 -276
  74. stubber/bulk/board_id.py +0 -40
  75. stubber/bulk/mpremoteboard.py +0 -141
  76. stubber/commands/get_lobo_cmd.py +0 -58
  77. stubber/commands/minify_cmd.py +0 -60
  78. stubber/commands/upd_fallback_cmd.py +0 -36
  79. stubber/commands/upd_module_list_cmd.py +0 -18
  80. {micropython_stubber-1.17.6.dist-info → micropython_stubber-1.20.0.dist-info}/LICENSE +0 -0
  81. {micropython_stubber-1.17.6.dist-info → micropython_stubber-1.20.0.dist-info}/WHEEL +0 -0
  82. {micropython_stubber-1.17.6.dist-info → micropython_stubber-1.20.0.dist-info}/entry_points.txt +0 -0
  83. /mpflash/mpflash/{uf2_boardid.py → flash_uf2_boardid.py} +0 -0
stubber/codemod/board.py CHANGED
@@ -1,6 +1,7 @@
1
1
  """"
2
2
  Codemods to create the different variants of createstubs.py
3
3
  """
4
+
4
5
  from __future__ import annotations
5
6
 
6
7
  from enum import Enum
@@ -129,7 +130,9 @@ class ReadModulesCodemod(codemod.Codemod):
129
130
 
130
131
  def __init__(self, context: codemod.CodemodContext, reader_node: Optional[cst.Module] = None):
131
132
  super().__init__(context)
132
- self.modules_reader_node = reader_node or cst.parse_module(Partial.MODULES_READER.contents())
133
+ self.modules_reader_node = reader_node or cst.parse_module(
134
+ Partial.MODULES_READER.contents(), # type: ignore
135
+ )
133
136
 
134
137
  def transform_module_impl(self, tree: cst.Module) -> cst.Module:
135
138
  """Replaces static modules list with file-load method."""
@@ -213,7 +216,9 @@ class LVGLCodemod(codemod.Codemod):
213
216
  # return self.modules_transform.transform_module_impl(tree)
214
217
 
215
218
  docstr_transformer = ModuleDocCodemod(self.context, _LVGL_MODULE_DOC)
216
- def_main_tree = cst.parse_module(Partial.LVGL_MAIN.contents())
219
+ def_main_tree = cst.parse_module(
220
+ Partial.LVGL_MAIN.contents(), # type: ignore
221
+ )
217
222
 
218
223
  work_tree = docstr_transformer.transform_module_impl(tree)
219
224
  matches = m.findall(work_tree, _DEF_MAIN_MATCHER, metadata_resolver=self)
@@ -253,7 +258,9 @@ class DBCodemod(codemod.Codemod):
253
258
  def transform_module_impl(self, tree: cst.Module) -> cst.Module:
254
259
  """Generates createstubs.py db variant."""
255
260
  docstr_transformer = ModuleDocCodemod(self.context, _DB_MODULE_DOC)
256
- def_main_tree = cst.parse_module(Partial.DB_MAIN.contents())
261
+ def_main_tree = cst.parse_module(
262
+ Partial.DB_MAIN.contents(), # type: ignore
263
+ )
257
264
 
258
265
  work_tree = docstr_transformer.transform_module_impl(tree)
259
266
  matches = m.findall(work_tree, _DEF_MAIN_MATCHER, metadata_resolver=self)
@@ -31,16 +31,16 @@ def cli_clone(path: Union[str, Path], stubs: bool = False):
31
31
  dest_path = Path(path)
32
32
  if not dest_path.exists():
33
33
  os.mkdir(dest_path)
34
- # repos are relative to provided path
35
- if dest_path != CONFIG.repo_path:
34
+ if dest_path == CONFIG.repo_path:
35
+ # same as default
36
+ mpy_path = CONFIG.mpy_path
37
+ mpy_lib_path = CONFIG.mpy_lib_path
38
+ mpy_stubs_path = CONFIG.mpy_stubs_path
39
+ else:
40
+ # repos are relative to provided path
36
41
  mpy_path = dest_path / "micropython"
37
42
  mpy_lib_path = dest_path / "micropython-lib"
38
43
  mpy_stubs_path = dest_path / "micropython-stubs"
39
- else:
40
- mpy_path = CONFIG.mpy_path
41
- mpy_lib_path = CONFIG.mpy_lib_path
42
-
43
- mpy_stubs_path = CONFIG.stub_path.parent
44
44
 
45
45
  repos: List[Tuple[Path, str, str]] = [
46
46
  (mpy_path, "https://github.com/micropython/micropython.git", "master"),
@@ -1,7 +1,9 @@
1
1
  """Show the current configuration"""
2
+
2
3
  # pragma: no cover
3
4
 
4
5
  from loguru import logger as log
6
+
5
7
  from stubber.utils.config import CONFIG
6
8
 
7
9
  from .cli import stubber_cli
@@ -20,6 +22,7 @@ def cli_config():
20
22
  log.info(f"CONFIG.repo_path {CONFIG.repo_path}")
21
23
  log.info(f"CONFIG.mpy_path {CONFIG.mpy_path}")
22
24
  log.info(f"CONFIG.mpy_lib_path {CONFIG.mpy_lib_path}")
25
+ log.info(f"CONFIG.mpy_stubs_path {CONFIG.mpy_stubs_path}")
23
26
 
24
27
  log.info(f"CONFIG.stub_path {CONFIG.stub_path}")
25
28
  log.info(f"CONFIG.publish_path {CONFIG.publish_path}")
@@ -1,12 +1,16 @@
1
1
  """Deploy and run createstubs on one or more microcontrollers."""
2
+
2
3
  ##########################################################################################
3
4
  # stub
4
5
  ##########################################################################################
5
6
 
6
7
 
7
8
  import click
9
+ from loguru import logger as log
8
10
 
9
11
  from stubber.bulk.mcu_stubber import stub_connected_mcus
12
+ from stubber.utils.config import CONFIG
13
+
10
14
  from .cli import stubber_cli
11
15
 
12
16
  ##########################################################################################
@@ -32,8 +36,21 @@ from .cli import stubber_cli
32
36
  help="Python source or pre-compiled.",
33
37
  )
34
38
  @click.option("--debug/--no-debug", default=False, show_default=True, help="Debug mode.")
35
- @click.option("--reset/--no-reset", default=False, show_default=True, help="Reset the board before running createstubs.")
36
- @click.option("--github/--local", default=True, show_default=True, help="where to install the board files from. local is intended for development.")
37
- def cli_create_mcu_stubs(variant: str, format: str, debug: bool, reset:bool, github:bool) -> int:
39
+ @click.option(
40
+ "--reset/--no-reset", default=False, show_default=True, help="Reset the board before running createstubs."
41
+ )
42
+ @click.option(
43
+ "--github/--local",
44
+ default=True,
45
+ show_default=True,
46
+ help="where to install the board files from. local is intended for development.",
47
+ )
48
+ def cli_create_mcu_stubs(variant: str, format: str, debug: bool, reset: bool, github: bool) -> int:
38
49
  """Run createstubs on one or more MCUs, and add the stubs to the micropython-stub repo."""
50
+ # check if all repos have been cloned
51
+ for repo in CONFIG.repos:
52
+ if not repo.exists():
53
+ log.error(f"Repo {repo} not found, use 'stubber clone --add-stubs' to clone the repos.")
54
+ exit(1)
55
+
39
56
  exit(stub_connected_mcus(variant=variant, format=format, debug=debug))
@@ -25,9 +25,7 @@ from typing import List, Optional
25
25
  from loguru import logger as log
26
26
  from packaging.version import Version
27
27
 
28
- import stubber.basicgit as git
29
28
  from stubber import utils
30
- from stubber.codemod.add_comment import AddComment
31
29
  from stubber.freeze.freeze_folder import freeze_folders # Micropython < v1.12
32
30
  from stubber.freeze.freeze_manifest_2 import freeze_one_manifest_2
33
31
  from stubber.utils.config import CONFIG
@@ -236,7 +236,7 @@ def board_candidates(
236
236
  else:
237
237
  r = git.checkout_tag(repo=mpy_path, tag=version)
238
238
  if not r:
239
- log.warning(f"Incorrect version or did you run `stubber clone` to get the micropython repo?")
239
+ log.warning(f"Incorrect version: {version} or did you forget to run `stubber clone` to get the micropython repo?")
240
240
  return []
241
241
  ports = list_micropython_ports(family=family, mpy_path=mpy_path)
242
242
  for port in ports:
@@ -4,7 +4,7 @@ prepare a set of stub files for publishing to PyPi
4
4
  """
5
5
  import sys
6
6
  from pathlib import Path
7
- from typing import Dict, List, Tuple, Union
7
+ from typing import Dict, Union
8
8
 
9
9
  from loguru import logger as log
10
10
  from packaging.version import parse
@@ -4,7 +4,7 @@ Helper functions to deal with path names and filenames for the folders in the st
4
4
  """
5
5
 
6
6
  from pathlib import Path
7
- from typing import Dict, List, Optional
7
+ from typing import Dict, Optional
8
8
 
9
9
  from loguru import logger as log
10
10
 
@@ -790,6 +790,7 @@ class StubPackage(PoetryBuilder):
790
790
  "name": self.package_name,
791
791
  "version": self.pkg_version,
792
792
  "error": None,
793
+ "path": self.package_path.as_posix(),
793
794
  }
794
795
  )
795
796
  super().__init__(
stubber/rst/lookup.py CHANGED
@@ -3,7 +3,7 @@ Lookup tables for the rst documentation stubber
3
3
  """
4
4
 
5
5
  from dataclasses import dataclass
6
- from typing import Dict, List, Optional, Tuple
6
+ from typing import List, Optional, Tuple
7
7
 
8
8
  # These are shown to import
9
9
  __all__ = [
stubber/stubber.py CHANGED
@@ -12,16 +12,12 @@ from stubber.commands.enrich_folder_cmd import cli_enrich_folder
12
12
  from stubber.commands.get_core_cmd import cli_get_core
13
13
  from stubber.commands.get_docstubs_cmd import cli_docstubs
14
14
  from stubber.commands.get_frozen_cmd import cli_get_frozen
15
- # from stubber.commands.get_lobo_cmd import cli_get_lobo
16
15
  from stubber.commands.merge_cmd import cli_merge_docstubs
17
- # from stubber.commands.minify_cmd import cli_minify
18
16
  from stubber.commands.publish_cmd import cli_publish
19
17
  from stubber.commands.stub_cmd import cli_stub
20
18
  from stubber.commands.switch_cmd import cli_switch
21
- # from stubber.commands.upd_fallback_cmd import cli_update_fallback
22
- # from stubber.commands.upd_module_list_cmd import cli_update_module_list
23
19
  from stubber.commands.variants_cmd import cli_variants
24
- from stubber.commands.mcu_cmd import cli_create_mcu_stubs
20
+ from stubber.commands.get_mcu_cmd import cli_create_mcu_stubs
25
21
 
26
22
  ##########################################################################################
27
23
  if __name__ == "__main__":
@@ -33,14 +29,10 @@ if __name__ == "__main__":
33
29
  stubber_cli.add_command(cli_docstubs)
34
30
  stubber_cli.add_command(cli_get_core)
35
31
  stubber_cli.add_command(cli_get_frozen)
36
- # stubber_cli.add_command(cli_get_lobo)
37
32
  stubber_cli.add_command(cli_stub)
38
33
  stubber_cli.add_command(cli_enrich_folder)
39
- # stubber_cli.add_command(cli_minify)
40
34
  stubber_cli.add_command(cli_publish)
41
35
  stubber_cli.add_command(cli_merge_docstubs)
42
- # stubber_cli.add_command(cli_update_module_list)
43
- # stubber_cli.add_command(cli_update_fallback)
44
36
  stubber_cli.add_command(cli_variants)
45
37
  stubber_cli.add_command(cli_create_mcu_stubs)
46
38
  stubber_cli()
@@ -26,10 +26,10 @@
26
26
  # THE SOFTWARE.
27
27
 
28
28
  from __future__ import print_function
29
+
29
30
  import contextlib
30
31
  import os
31
32
  import sys
32
- import glob
33
33
  import tempfile
34
34
  from collections import namedtuple
35
35
 
@@ -270,7 +270,9 @@ class ManifestFile:
270
270
  raise ManifestFileError("Expected .py file")
271
271
  kind = KIND_COMPILE_AS_MPY
272
272
 
273
- self._manifest_files.append(ManifestOutput(FILE_TYPE_LOCAL, full_path, target_path, timestamp, kind, self._metadata[-1], opt))
273
+ self._manifest_files.append(
274
+ ManifestOutput(FILE_TYPE_LOCAL, full_path, target_path, timestamp, kind, self._metadata[-1], opt)
275
+ )
274
276
 
275
277
  def _search(self, base_path, package_path, files, exts, kind, opt=None, strict=False):
276
278
  base_path = self._resolve_path(base_path)
@@ -411,7 +413,7 @@ class ManifestFile:
411
413
 
412
414
  for lib_dir in lib_dirs:
413
415
  # Search for {lib_dir}/**/{name}/manifest.py.
414
- for root, dirnames, filenames in os.walk(os.path.join(self._path_vars["MPY_LIB_DIR"], lib_dir)):
416
+ for root, _, filenames in os.walk(os.path.join(self._path_vars["MPY_LIB_DIR"], lib_dir)):
415
417
  if os.path.basename(root) == name and "manifest.py" in filenames:
416
418
  self.include(root, is_require=True, **kwargs)
417
419
  return
@@ -1,117 +1,117 @@
1
- """build/update the fallback 'catch-all' stubfolder"""
1
+ # """build/update the fallback 'catch-all' stubfolder"""
2
2
 
3
- import os
4
- import shutil
5
- from distutils.dir_util import copy_tree
6
- from distutils.errors import DistutilsFileError
7
- from pathlib import Path
8
- from typing import List, Optional, Tuple
3
+ # import os
4
+ # import shutil
5
+ # from distutils.dir_util import copy_tree
6
+ # from distutils.errors import DistutilsFileError
7
+ # from pathlib import Path
8
+ # from typing import List, Optional, Tuple
9
9
 
10
- from loguru import logger as log
10
+ # from loguru import logger as log
11
11
 
12
- from stubber.utils.versions import V_PREVIEW
12
+ # from stubber.utils.versions import V_PREVIEW
13
13
 
14
- # log = logging.getLogger()
14
+ # # log = logging.getLogger()
15
15
 
16
- RELEASED = "v1_18"
16
+ # RELEASED = "v1_18"
17
17
 
18
18
 
19
- def fallback_sources(version: str, fw_version: Optional[str] = None) -> List[Tuple[str, str]]:
20
- # sourcery skip: inline-immediately-returned-variable
21
- """
22
- list of sources to build/update the fallback 'catch-all' stubfolder
23
- version : the version to use
24
- fw_version : version to source the MCU stubs from. Defaults to the version used , but can be lower
19
+ # def fallback_sources(version: str, fw_version: Optional[str] = None) -> List[Tuple[str, str]]:
20
+ # # sourcery skip: inline-immediately-returned-variable
21
+ # """
22
+ # list of sources to build/update the fallback 'catch-all' stubfolder
23
+ # version : the version to use
24
+ # fw_version : version to source the MCU stubs from. Defaults to the version used , but can be lower
25
25
 
26
- """
27
- if not fw_version:
28
- fw_version = version
29
- if fw_version == V_PREVIEW:
30
- fw_version = RELEASED
31
- SOURCES = [
32
- ("uasyncio", f"micropython-{fw_version}-esp32"),
33
- ("umqtt", f"micropython-{fw_version}-esp32"),
34
- ("_onewire.py*", f"micropython-{fw_version}-esp32"),
35
- ("_uasyncio.py*", f"micropython-{fw_version}-esp32"),
36
- ("array.py*", f"micropython-{fw_version}-esp32"),
37
- ("binascii.py*", f"micropython-{fw_version}-esp32"),
38
- ("hashlib.py*", f"micropython-{fw_version}-esp32"),
39
- ("machine.py*", f"micropython-{fw_version}-esp32"),
40
- ("micropython.py*", f"micropython-{version}-docstubs"), # esp32"),
41
- ("network.pyi", f"micropython-{version}-docstubs"), # esp32"),
42
- ("struct.py*", f"micropython-{fw_version}-esp32"),
43
- ("uarray.py*", f"micropython-{fw_version}-esp32"),
44
- ("ubinascii.py*", f"micropython-{fw_version}-esp32"),
45
- ("uctypes.py*", f"micropython-{fw_version}-esp32"),
46
- ("uerrno.py*", f"micropython-{fw_version}-esp32"),
47
- ("uhashlib.py*", f"micropython-{fw_version}-esp32"),
48
- ("uio.py*", f"micropython-{fw_version}-esp32"),
49
- ("ujson.py*", f"micropython-{fw_version}-esp32"),
50
- ("uselect.py*", f"micropython-{fw_version}-esp32"),
51
- ("usocket.py*", f"micropython-{fw_version}-esp32"),
52
- ("ussl.py*", f"micropython-{fw_version}-esp32"),
53
- ("ustruct.py*", f"micropython-{fw_version}-esp32"),
54
- ("sys.py*", f"micropython-{fw_version}-esp32"),
55
- ("usys.py*", f"micropython-{fw_version}-esp32"),
56
- ("uzlib.py*", f"micropython-{fw_version}-esp32"),
57
- ("bluetooth.py*", f"micropython-{version}-docstubs"),
58
- # esp
59
- ("esp.py*", f"micropython-{version}-docstubs"), # 8266 fw stub has most functions
60
- ("esp32.py*", f"micropython-{version}-docstubs"), # esp32"),
61
- # pyboard == stm32
62
- ("pyb.py*", f"micropython-{fw_version}-stm32"),
63
- ("framebuf.py*", f"micropython-{fw_version}-stm32"),
64
- # rp2
65
- ("_rp2.py*", f"micropython-{fw_version}-rp2"),
66
- # stdlib
67
- ("os.py*", f"micropython-{fw_version}-esp32"), # -> stdlib
68
- ("uos.py*", f"micropython-{fw_version}-esp32"),
69
- ("time.py*", f"micropython-{fw_version}-esp32"), # -> stdlib
70
- ("utime.py*", f"micropython-{fw_version}-esp32"),
71
- ]
72
- return SOURCES
26
+ # """
27
+ # if not fw_version:
28
+ # fw_version = version
29
+ # if fw_version == V_PREVIEW:
30
+ # fw_version = RELEASED
31
+ # SOURCES = [
32
+ # ("uasyncio", f"micropython-{fw_version}-esp32"),
33
+ # ("umqtt", f"micropython-{fw_version}-esp32"),
34
+ # ("_onewire.py*", f"micropython-{fw_version}-esp32"),
35
+ # ("_uasyncio.py*", f"micropython-{fw_version}-esp32"),
36
+ # ("array.py*", f"micropython-{fw_version}-esp32"),
37
+ # ("binascii.py*", f"micropython-{fw_version}-esp32"),
38
+ # ("hashlib.py*", f"micropython-{fw_version}-esp32"),
39
+ # ("machine.py*", f"micropython-{fw_version}-esp32"),
40
+ # ("micropython.py*", f"micropython-{version}-docstubs"), # esp32"),
41
+ # ("network.pyi", f"micropython-{version}-docstubs"), # esp32"),
42
+ # ("struct.py*", f"micropython-{fw_version}-esp32"),
43
+ # ("uarray.py*", f"micropython-{fw_version}-esp32"),
44
+ # ("ubinascii.py*", f"micropython-{fw_version}-esp32"),
45
+ # ("uctypes.py*", f"micropython-{fw_version}-esp32"),
46
+ # ("uerrno.py*", f"micropython-{fw_version}-esp32"),
47
+ # ("uhashlib.py*", f"micropython-{fw_version}-esp32"),
48
+ # ("uio.py*", f"micropython-{fw_version}-esp32"),
49
+ # ("ujson.py*", f"micropython-{fw_version}-esp32"),
50
+ # ("uselect.py*", f"micropython-{fw_version}-esp32"),
51
+ # ("usocket.py*", f"micropython-{fw_version}-esp32"),
52
+ # ("ussl.py*", f"micropython-{fw_version}-esp32"),
53
+ # ("ustruct.py*", f"micropython-{fw_version}-esp32"),
54
+ # ("sys.py*", f"micropython-{fw_version}-esp32"),
55
+ # ("usys.py*", f"micropython-{fw_version}-esp32"),
56
+ # ("uzlib.py*", f"micropython-{fw_version}-esp32"),
57
+ # ("bluetooth.py*", f"micropython-{version}-docstubs"),
58
+ # # esp
59
+ # ("esp.py*", f"micropython-{version}-docstubs"), # 8266 fw stub has most functions
60
+ # ("esp32.py*", f"micropython-{version}-docstubs"), # esp32"),
61
+ # # pyboard == stm32
62
+ # ("pyb.py*", f"micropython-{fw_version}-stm32"),
63
+ # ("framebuf.py*", f"micropython-{fw_version}-stm32"),
64
+ # # rp2
65
+ # ("_rp2.py*", f"micropython-{fw_version}-rp2"),
66
+ # # stdlib
67
+ # ("os.py*", f"micropython-{fw_version}-esp32"), # -> stdlib
68
+ # ("uos.py*", f"micropython-{fw_version}-esp32"),
69
+ # ("time.py*", f"micropython-{fw_version}-esp32"), # -> stdlib
70
+ # ("utime.py*", f"micropython-{fw_version}-esp32"),
71
+ # ]
72
+ # return SOURCES
73
73
 
74
74
 
75
- def update_fallback(stubpath: Path, fallback_path: Path, version: str = RELEASED):
76
- "update the fallback stubs from the defined sources"
77
- # remove all *.py/.pyi files
78
- if not fallback_path.exists():
79
- os.makedirs(fallback_path)
80
- else:
81
- oldstubs = list(fallback_path.rglob("*.py")) + list(fallback_path.rglob("*.pyi"))
82
- log.debug(f"deleting {len(oldstubs)} stubs from {fallback_path.as_posix()}")
83
- for f in oldstubs:
84
- try:
85
- os.remove(f)
86
- except OSError as e:
87
- log.warning(e)
88
- added = 0
89
- for name, source in fallback_sources(version):
90
- if "." not in name:
91
- # copy folder
92
- log.debug(f"add {source} folder")
93
- try:
94
- copy_tree(
95
- (stubpath / source / name).as_posix(),
96
- (fallback_path / name).as_posix(),
97
- )
98
- added += 1
99
- except DistutilsFileError:
100
- log.warning(f"{(stubpath / source / name).as_posix()} not found")
101
- else:
102
- # copy file(s)
103
- log.debug(f"add {source}")
104
- for f in (stubpath / source).glob(name):
105
- shutil.copyfile(f, fallback_path / f.name)
106
- added += 1
107
- return added
75
+ # def update_fallback(stubpath: Path, fallback_path: Path, version: str = RELEASED):
76
+ # "update the fallback stubs from the defined sources"
77
+ # # remove all *.py/.pyi files
78
+ # if not fallback_path.exists():
79
+ # os.makedirs(fallback_path)
80
+ # else:
81
+ # oldstubs = list(fallback_path.rglob("*.py")) + list(fallback_path.rglob("*.pyi"))
82
+ # log.debug(f"deleting {len(oldstubs)} stubs from {fallback_path.as_posix()}")
83
+ # for f in oldstubs:
84
+ # try:
85
+ # os.remove(f)
86
+ # except OSError as e:
87
+ # log.warning(e)
88
+ # added = 0
89
+ # for name, source in fallback_sources(version):
90
+ # if "." not in name:
91
+ # # copy folder
92
+ # log.debug(f"add {source} folder")
93
+ # try:
94
+ # copy_tree(
95
+ # (stubpath / source / name).as_posix(),
96
+ # (fallback_path / name).as_posix(),
97
+ # )
98
+ # added += 1
99
+ # except DistutilsFileError:
100
+ # log.warning(f"{(stubpath / source / name).as_posix()} not found")
101
+ # else:
102
+ # # copy file(s)
103
+ # log.debug(f"add {source}")
104
+ # for f in (stubpath / source).glob(name):
105
+ # shutil.copyfile(f, fallback_path / f.name)
106
+ # added += 1
107
+ # return added
108
108
 
109
109
 
110
- if __name__ == "__main__":
111
- from stubber.utils.config import CONFIG
110
+ # if __name__ == "__main__":
111
+ # from stubber.utils.config import CONFIG
112
112
 
113
- update_fallback(
114
- CONFIG.stub_path,
115
- CONFIG.fallback_path,
116
- version=RELEASED,
117
- )
113
+ # update_fallback(
114
+ # CONFIG.stub_path,
115
+ # CONFIG.fallback_path,
116
+ # version=RELEASED,
117
+ # )
stubber/utils/config.py CHANGED
@@ -1,6 +1,7 @@
1
1
  """stubber configuration"""
2
2
 
3
3
  from pathlib import Path
4
+ from typing import List
4
5
 
5
6
  from loguru import logger as log
6
7
  from typedconfig.config import Config, key, section
@@ -15,43 +16,25 @@ from .typed_config_toml import TomlConfigSource
15
16
  @section("micropython-stubber")
16
17
  class StubberConfig(Config):
17
18
  "stubber configuration class"
18
- stub_path = key(key_name="stub-path", cast=Path, required=False, default=Path("./stubs"))
19
- "a Path to the stubs directory"
20
19
  # relative to stubs folder
21
- fallback_path = key(key_name="fallback-path", cast=Path, required=False, default=Path("typings/fallback"))
20
+ fallback_path: Path = key(key_name="fallback-path", cast=Path, required=False, default=Path("typings/fallback"))
22
21
  "a Path to the fallback stubs directory"
23
22
 
24
23
  # ------------------------------------------------------------------------------------------
25
24
  # micropython and micropython-lib are relative to ./repo folder
26
- repo_path = key(key_name="repo-path", cast=Path, required=False, default=Path("./repos"))
25
+ repo_path: Path = key(key_name="repo-path", cast=Path, required=False, default=Path("./repos"))
27
26
  "a Path to the repo directory"
28
27
 
29
- mpy_path = key(key_name="mpy-path", cast=Path, required=False, default=Path("micropython"))
28
+ mpy_path: Path = key(key_name="mpy-path", cast=Path, required=False, default=Path("micropython"))
30
29
  "a Path to the micropython folder in the repos directory"
31
30
 
32
- mpy_lib_path = key(key_name="mpy-lib-path", cast=Path, required=False, default=Path("micropython-lib"))
31
+ mpy_lib_path: Path = key(key_name="mpy-lib-path", cast=Path, required=False, default=Path("micropython-lib"))
33
32
  "a Path to the micropython-lib folder in the repos directory"
34
33
 
35
- # mpy_stubs_repo_path = key(key_name="mpy-stubs-repo-path", cast=Path, required=False, default=Path("./micropython-stubs"))
36
- # "a Path to the micropython-stubs folder in the repos directory"
34
+ mpy_stubs_path: Path = key(key_name="mpy-stubs-path", cast=Path, required=False, default=Path("micropython-stubs"))
35
+ "a Path to the micropython-stubs folder in the repos directory (or current directory)"
37
36
 
38
- publish_path = key(
39
- key_name="publish-path",
40
- cast=Path,
41
- required=False,
42
- default=Path("./repos/micropython-stubs/publish"),
43
- )
44
- "A Path to the folder where all stub publication artifacts are stored"
45
-
46
- template_path = key(
47
- key_name="template-path",
48
- cast=Path,
49
- required=False,
50
- default=Path("./repos/micropython-stubs/publish/template"),
51
- )
52
- "a Path to the publication folder that has the template files"
53
-
54
- stable_version = key(key_name="stable-version", cast=str, required=False, default="1.20.0")
37
+ stable_version: str = key(key_name="stable-version", cast=str, required=False, default="1.20.0")
55
38
 
56
39
  "last published stable"
57
40
 
@@ -66,25 +49,38 @@ class StubberConfig(Config):
66
49
  BLOCKED_PORTS = ["minimal", "bare-arm"]
67
50
  "ports that should be ignored as a source of stubs"
68
51
 
69
- # def __init__(self):
70
- # super().__init__()
71
- # self.update_versions()
52
+ @property
53
+ def repos(self) -> List[Path]:
54
+ "return the repo paths"
55
+ return [self.mpy_path, self.mpy_lib_path, self.mpy_stubs_path]
56
+
57
+ @property
58
+ def stub_path(self) -> Path:
59
+ "return the stubs path in the microypthon-stubs repo"
60
+ return self.mpy_stubs_path / "stubs"
61
+
62
+ @property
63
+ def publish_path(self) -> Path:
64
+ "return the stubs path in the microypthon-stubs repo"
65
+ return self.mpy_stubs_path / "publish"
72
66
 
73
- # def update_versions(self):
74
- # try:
75
- # self.ALL_VERSIONS = git.get_tags(self.mpy_path, minver="v1.17")
76
- # except Exception:
77
- # self.ALL_VERSIONS = ["1.17", "1.18", "1.19", "1.19.1"]
78
- # self.STABLE_VERSION = self.ALL_VERSIONS[-1]
67
+ @property
68
+ def template_path(self) -> Path:
69
+ "return the stubs path in the microypthon-stubs repo"
70
+ return self.mpy_stubs_path / "publish" / "template"
79
71
 
80
72
  def post_read_hook(self) -> dict:
81
73
  config_updates = {}
82
74
  # relative to stubs
83
- config_updates.update(fallback_path=self.stub_path / self.fallback_path)
75
+ # config_updates.update(fallback_path=self.stub_path / self.fallback_path)
84
76
 
85
77
  # relative to repo path
86
78
  config_updates.update(mpy_path=self.repo_path / self.mpy_path)
87
79
  config_updates.update(mpy_lib_path=self.repo_path / self.mpy_lib_path)
80
+ if self.mpy_stubs_path.is_absolute() or self.mpy_stubs_path == Path("."):
81
+ config_updates.update(mpy_stubs_path=self.mpy_stubs_path)
82
+ else:
83
+ config_updates.update(mpy_stubs_path=self.repo_path / self.mpy_stubs_path)
88
84
  # read the versions from the git tags
89
85
  all_versions = []
90
86
  try:
@@ -107,7 +103,7 @@ def readconfig(filename: str = "pyproject.toml", prefix: str = "tool.", must_exi
107
103
  while not (path / filename).exists():
108
104
  path = path.parent
109
105
  if path == path.parent:
110
- log.info(f"Could not find config file: {filename}")
106
+ log.trace(f"Could not find config file: {filename}")
111
107
  use_toml = False
112
108
  break
113
109
 
stubber/utils/repos.py CHANGED
@@ -107,9 +107,9 @@ def fetch_repos(tag: str, mpy_path: Path, mpy_lib_path: Path):
107
107
  git.fetch(mpy_path)
108
108
  git.fetch(mpy_lib_path)
109
109
  try:
110
- git.fetch(CONFIG.stub_path.parent)
110
+ git.fetch(CONFIG.mpy_stubs_path)
111
111
  except Exception:
112
- log.trace("no stubs repo found : {CONFIG.stub_path.parent}")
112
+ log.trace("no stubs repo found : {CONFIG.mpy_stubs_path}")
113
113
 
114
114
  if not tag:
115
115
  tag = V_PREVIEW
stubber/utils/versions.py CHANGED
@@ -3,6 +3,7 @@
3
3
  from pathlib import Path
4
4
 
5
5
  from github import Github
6
+ from loguru import logger as log
6
7
  from packaging.version import parse
7
8
 
8
9
  import stubber.basicgit as git