micropython-stubber 1.20.6__py3-none-any.whl → 1.23.1__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 (89) hide show
  1. {micropython_stubber-1.20.6.dist-info → micropython_stubber-1.23.1.dist-info}/METADATA +4 -3
  2. micropython_stubber-1.23.1.dist-info/RECORD +159 -0
  3. mpflash/README.md +14 -4
  4. mpflash/mpflash/add_firmware.py +1 -1
  5. mpflash/mpflash/ask_input.py +1 -1
  6. {stubber → mpflash/mpflash}/basicgit.py +3 -13
  7. mpflash/mpflash/bootloader/__init__.py +2 -37
  8. mpflash/mpflash/bootloader/activate.py +60 -0
  9. mpflash/mpflash/bootloader/detect.py +82 -0
  10. mpflash/mpflash/bootloader/manual.py +10 -11
  11. mpflash/mpflash/bootloader/micropython.py +2 -0
  12. mpflash/mpflash/bootloader/touch1200.py +13 -22
  13. mpflash/mpflash/cli_download.py +1 -1
  14. mpflash/mpflash/cli_flash.py +4 -4
  15. mpflash/mpflash/cli_group.py +18 -5
  16. mpflash/mpflash/cli_main.py +3 -5
  17. mpflash/mpflash/common.py +1 -0
  18. mpflash/mpflash/config.py +6 -9
  19. mpflash/mpflash/connected.py +9 -5
  20. mpflash/mpflash/download.py +9 -5
  21. mpflash/mpflash/downloaded.py +4 -3
  22. mpflash/mpflash/{flash.py → flash/__init__.py} +20 -17
  23. mpflash/mpflash/{flash_esp.py → flash/esp.py} +1 -1
  24. mpflash/mpflash/flash/stm32.py +19 -0
  25. mpflash/mpflash/{flash_stm32_dfu.py → flash/stm32_dfu.py} +4 -1
  26. mpflash/mpflash/{flash_uf2.py → flash/uf2/__init__.py} +44 -23
  27. mpflash/mpflash/{flash_uf2_linux.py → flash/uf2/linux.py} +15 -8
  28. mpflash/mpflash/{flash_uf2_macos.py → flash/uf2/macos.py} +13 -5
  29. mpflash/mpflash/{flash_uf2_windows.py → flash/uf2/windows.py} +16 -7
  30. mpflash/mpflash/{worklist.py → flash/worklist.py} +9 -9
  31. mpflash/mpflash/list.py +13 -3
  32. mpflash/mpflash/mpboard_id/__init__.py +1 -1
  33. mpflash/mpflash/mpboard_id/add_boards.py +3 -7
  34. mpflash/mpflash/mpboard_id/board_id.py +1 -1
  35. mpflash/mpflash/mpremoteboard/__init__.py +5 -4
  36. {stubber/utils → mpflash/mpflash}/versions.py +31 -24
  37. mpflash/poetry.lock +16 -5
  38. mpflash/pyproject.toml +8 -3
  39. stubber/__init__.py +1 -1
  40. stubber/board/createstubs.py +4 -4
  41. stubber/board/createstubs_db.py +5 -5
  42. stubber/board/createstubs_db_min.py +1 -1
  43. stubber/board/createstubs_db_mpy.mpy +0 -0
  44. stubber/board/createstubs_mem.py +5 -5
  45. stubber/board/createstubs_mem_min.py +1 -1
  46. stubber/board/createstubs_mem_mpy.mpy +0 -0
  47. stubber/board/createstubs_min.py +1 -1
  48. stubber/board/createstubs_mpy.mpy +0 -0
  49. stubber/codemod/utils.py +2 -3
  50. stubber/commands/build_cmd.py +1 -1
  51. stubber/commands/cli.py +8 -4
  52. stubber/commands/clone_cmd.py +16 -4
  53. stubber/commands/enrich_folder_cmd.py +2 -1
  54. stubber/commands/get_core_cmd.py +5 -3
  55. stubber/commands/get_docstubs_cmd.py +6 -4
  56. stubber/commands/get_frozen_cmd.py +5 -3
  57. stubber/commands/get_mcu_cmd.py +9 -4
  58. stubber/commands/merge_cmd.py +3 -3
  59. stubber/commands/publish_cmd.py +2 -3
  60. stubber/commands/stub_cmd.py +2 -1
  61. stubber/commands/switch_cmd.py +14 -6
  62. stubber/commands/variants_cmd.py +3 -3
  63. stubber/freeze/get_frozen.py +1 -1
  64. stubber/minify.py +4 -3
  65. stubber/publish/candidates.py +4 -10
  66. stubber/publish/defaults.py +4 -9
  67. stubber/publish/missing_class_methods.py +1 -1
  68. stubber/publish/package.py +1 -1
  69. stubber/publish/pathnames.py +1 -1
  70. stubber/publish/publish.py +1 -1
  71. stubber/publish/stubpackage.py +3 -5
  72. stubber/rst/reader.py +5 -13
  73. stubber/tools/manifestfile.py +71 -27
  74. stubber/tools/readme.md +3 -2
  75. stubber/update_fallback.py +1 -1
  76. stubber/utils/__init__.py +2 -1
  77. stubber/utils/config.py +3 -5
  78. stubber/utils/manifest.py +2 -4
  79. stubber/utils/repos.py +5 -12
  80. micropython_stubber-1.20.6.dist-info/RECORD +0 -159
  81. mpflash/mpflash/flash_stm32.py +0 -24
  82. mpflash/mpflash/flash_stm32_cube.py +0 -111
  83. mpflash/mpflash/vendor/versions.py +0 -119
  84. {micropython_stubber-1.20.6.dist-info → micropython_stubber-1.23.1.dist-info}/LICENSE +0 -0
  85. {micropython_stubber-1.20.6.dist-info → micropython_stubber-1.23.1.dist-info}/WHEEL +0 -0
  86. {micropython_stubber-1.20.6.dist-info → micropython_stubber-1.23.1.dist-info}/entry_points.txt +0 -0
  87. /mpflash/{mpflash/vendor/basicgit.py → basicgit.py} +0 -0
  88. /mpflash/mpflash/{flash_uf2_boardid.py → flash/uf2/boardid.py} +0 -0
  89. /mpflash/mpflash/{uf2disk.py → flash/uf2/uf2disk.py} +0 -0
@@ -5,7 +5,7 @@
5
5
  ##########################################################################################
6
6
 
7
7
 
8
- import click
8
+ import rich_click as click
9
9
  from loguru import logger as log
10
10
 
11
11
  from stubber.bulk.mcu_stubber import stub_connected_mcus
@@ -21,7 +21,7 @@ from .cli import stubber_cli
21
21
  @stubber_cli.command(name="get-mcu-stubs")
22
22
  @click.option(
23
23
  "--variant",
24
- "-v",
24
+ # "-v",
25
25
  type=click.Choice(["Full", "Mem", "DB"], case_sensitive=False),
26
26
  default="DB",
27
27
  show_default=True,
@@ -37,7 +37,10 @@ from .cli import stubber_cli
37
37
  )
38
38
  @click.option("--debug/--no-debug", default=False, show_default=True, help="Debug mode.")
39
39
  @click.option(
40
- "--reset/--no-reset", default=False, show_default=True, help="Reset the board before running createstubs."
40
+ "--reset/--no-reset",
41
+ default=False,
42
+ show_default=True,
43
+ help="Reset the board before running createstubs.",
41
44
  )
42
45
  @click.option(
43
46
  "--github/--local",
@@ -50,7 +53,9 @@ def cli_create_mcu_stubs(variant: str, format: str, debug: bool, reset: bool, gi
50
53
  # check if all repos have been cloned
51
54
  for repo in CONFIG.repos:
52
55
  if not repo.exists():
53
- log.error(f"Repo {repo} not found, use 'stubber clone --add-stubs' to clone the repos.")
56
+ log.error(
57
+ f"Repo {repo} not found, use 'stubber clone --add-stubs' to clone the repos."
58
+ )
54
59
  exit(1)
55
60
 
56
61
  exit(stub_connected_mcus(variant=variant, format=format, debug=debug))
@@ -1,9 +1,10 @@
1
1
  """
2
2
  enrich machinestubs with docstubs
3
3
  """
4
+
4
5
  from typing import List, Union
5
6
 
6
- import click
7
+ import rich_click as click
7
8
  from loguru import logger as log
8
9
 
9
10
  from stubber.publish.merge_docstubs import merge_all_docstubs
@@ -17,8 +18,7 @@ from .cli import stubber_cli
17
18
  @click.option("--family", default="micropython", type=str, show_default=True)
18
19
  @click.option(
19
20
  "--version",
20
- "--Version",
21
- "-V",
21
+ "-v",
22
22
  "versions",
23
23
  multiple=True,
24
24
  default=["all"],
@@ -4,7 +4,7 @@ Commandline interface to publish stubs.
4
4
 
5
5
  from typing import List, Union
6
6
 
7
- import click
7
+ import rich_click as click
8
8
  from loguru import logger as log
9
9
  from tabulate import tabulate
10
10
 
@@ -18,8 +18,7 @@ from stubber.utils.config import CONFIG
18
18
  @click.option("--family", default="micropython", type=str, show_default=True)
19
19
  @click.option(
20
20
  "--version",
21
- "--Version",
22
- "-V",
21
+ "-v",
23
22
  "versions",
24
23
  multiple=True,
25
24
  default=[CONFIG.stable_version],
@@ -1,4 +1,5 @@
1
1
  """Create or update .pyi type hint files."""
2
+
2
3
  ##########################################################################################
3
4
  # stub
4
5
  ##########################################################################################
@@ -7,7 +8,7 @@ from loguru import logger as log
7
8
  from pathlib import Path
8
9
  from typing import Union
9
10
 
10
- import click
11
+ import rich_click as click
11
12
  from stubber.utils import generate_pyi_files
12
13
  from stubber.utils.post import do_post_processing
13
14
 
@@ -2,16 +2,15 @@
2
2
  switch to a specific version of the micropython repos
3
3
  """
4
4
 
5
-
6
5
  from pathlib import Path
7
6
  from typing import Optional, Union
8
7
 
9
- import click
8
+ import rich_click as click
10
9
 
11
- import stubber.basicgit as git
10
+ import mpflash.basicgit as git
12
11
  from stubber.utils.config import CONFIG
13
12
  from stubber.utils.repos import fetch_repos, repo_paths
14
- from stubber.utils.versions import SET_PREVIEW, V_PREVIEW
13
+ from mpflash.versions import SET_PREVIEW, V_PREVIEW
15
14
 
16
15
  from .cli import stubber_cli
17
16
 
@@ -23,7 +22,11 @@ from .cli import stubber_cli
23
22
  # get version list from Git tags in the repo that is provided on the command line
24
23
 
25
24
  try:
26
- VERSION_LIST = git.get_tags("micropython/micropython", minver="v1.9.3") + [V_PREVIEW, "latest", "stable"]
25
+ VERSION_LIST = git.get_tags("micropython/micropython", minver="v1.9.3") + [
26
+ V_PREVIEW,
27
+ "latest",
28
+ "stable",
29
+ ]
27
30
  except Exception:
28
31
  # offline fallback
29
32
  VERSION_LIST = ["v1.91.1", "v1.20.1", "v1.21.0", "v1.22.1", "preview", "stable"]
@@ -31,7 +34,12 @@ except Exception:
31
34
 
32
35
  @stubber_cli.command(name="switch")
33
36
  @click.argument("tag", required=False, type=click.Choice(VERSION_LIST, case_sensitive=False))
34
- @click.option("--path", "-p", default=CONFIG.repo_path.as_posix(), type=click.Path(file_okay=False, dir_okay=True))
37
+ @click.option(
38
+ "--path",
39
+ "-p",
40
+ default=CONFIG.repo_path.as_posix(),
41
+ type=click.Path(file_okay=False, dir_okay=True),
42
+ )
35
43
  def cli_switch(path: Union[str, Path], tag: Optional[str] = None):
36
44
  """
37
45
  Switch to a specific version of the micropython repos.
@@ -1,7 +1,8 @@
1
1
  """Create all variant of createstubs*.py."""
2
+
2
3
  from pathlib import Path
3
4
 
4
- import click
5
+ import rich_click as click
5
6
  from loguru import logger as log
6
7
  from stubber.utils.config import CONFIG
7
8
  from stubber.variants import create_variants
@@ -12,8 +13,7 @@ from .cli import stubber_cli
12
13
 
13
14
  @click.option(
14
15
  "--version",
15
- "--Version",
16
- "-V",
16
+ "-v",
17
17
  "version",
18
18
  default=CONFIG.stable_version,
19
19
  show_default=True,
@@ -25,11 +25,11 @@ from typing import List, Optional
25
25
  from loguru import logger as log
26
26
  from packaging.version import Version
27
27
 
28
+ from mpflash.versions import SET_PREVIEW, V_PREVIEW
28
29
  from stubber import utils
29
30
  from stubber.freeze.freeze_folder import freeze_folders # Micropython < v1.12
30
31
  from stubber.freeze.freeze_manifest_2 import freeze_one_manifest_2
31
32
  from stubber.utils.config import CONFIG
32
- from stubber.utils.versions import SET_PREVIEW, V_PREVIEW
33
33
 
34
34
  FAMILY = "micropython"
35
35
 
stubber/minify.py CHANGED
@@ -2,6 +2,7 @@
2
2
  Processing for createstubs.py
3
3
  Minimizes and cross-compiles a MicroPyton file.
4
4
  """
5
+
5
6
  import itertools
6
7
  import subprocess
7
8
  import tempfile
@@ -10,14 +11,14 @@ from io import BytesIO, IOBase, StringIO, TextIOWrapper
10
11
  from pathlib import Path
11
12
  from typing import List, Tuple, Union
12
13
 
13
- try:
14
+ try:
14
15
  import python_minifier
15
16
  except ImportError:
16
17
  python_minifier = None
17
18
 
18
19
  from loguru import logger as log
19
20
 
20
- from stubber.utils.versions import SET_PREVIEW, V_PREVIEW
21
+ from mpflash.versions import SET_PREVIEW, V_PREVIEW
21
22
 
22
23
  # Type Aliases for minify
23
24
  StubSource = Union[Path, str, StringIO, TextIOWrapper]
@@ -243,7 +244,7 @@ def minify_script(source_script: StubSource, keep_report: bool = True, diff: boo
243
244
  ],
244
245
  # remove_pass=True, # no dead code
245
246
  # convert_posargs_to_args=True, # Does not save any space
246
- )
247
+ )
247
248
  len_3 = len(min_source)
248
249
  if 1:
249
250
  # write to temp file for debugging
@@ -17,13 +17,13 @@ from typing import Any, Dict, Generator, List, Optional, Union
17
17
  from loguru import logger as log
18
18
  from packaging.version import parse
19
19
 
20
- import stubber.basicgit as git
20
+ import mpflash.basicgit as git
21
+ from mpflash.versions import OLDEST_VERSION, SET_PREVIEW, V_PREVIEW, clean_version, micropython_versions
21
22
  from stubber import utils
22
23
  from stubber.publish.defaults import GENERIC, GENERIC_L, GENERIC_U
23
24
 
24
25
  # from stubber.publish.enums import COMBO_STUBS
25
26
  from stubber.utils.config import CONFIG
26
- from stubber.utils.versions import OLDEST_VERSION, SET_PREVIEW, V_PREVIEW, clean_version, micropython_versions
27
27
 
28
28
 
29
29
  def subfolder_names(path: Path):
@@ -215,9 +215,7 @@ def board_candidates(
215
215
  else:
216
216
  r = git.checkout_tag(repo=mpy_path, tag=version)
217
217
  if not r:
218
- log.warning(
219
- f"Incorrect version: {version} or did you forget to run `stubber clone` to get the micropython repo?"
220
- )
218
+ log.warning(f"Incorrect version: {version} or did you forget to run `stubber clone` to get the micropython repo?")
221
219
  return []
222
220
  ports = list_micropython_ports(family=family, mpy_path=mpy_path)
223
221
  for port in ports:
@@ -254,9 +252,5 @@ def filter_list(
254
252
  worklist = [i for i in worklist if i["port"].lower() in ports_]
255
253
  if boards and not is_auto(boards):
256
254
  boards_ = [i.lower() for i in boards]
257
- worklist = [
258
- i
259
- for i in worklist
260
- if i["board"].lower() in boards_ or i["board"].lower().replace("generic_", "") in boards_
261
- ]
255
+ worklist = [i for i in worklist if i["board"].lower() in boards_ or i["board"].lower().replace("generic_", "") in boards_]
262
256
  return worklist
@@ -1,8 +1,9 @@
1
1
  """Build and packaging defaults for stubber"""
2
+
2
3
  from typing import Dict, List
3
4
 
5
+ from mpflash.versions import V_PREVIEW, clean_version
4
6
  from stubber.utils.config import CONFIG
5
- from stubber.utils.versions import V_PREVIEW, clean_version
6
7
 
7
8
  # The default board for the ports modules documented with base name only
8
9
  # as the MicroPython BOARD naming convention has changed over time there are different options to try
@@ -29,15 +30,9 @@ def default_board(port: str, version=V_PREVIEW) -> str: # sourcery skip: assign
29
30
  ver_flat = clean_version(version, flat=True)
30
31
  if port in DEFAULT_BOARDS:
31
32
  for board in DEFAULT_BOARDS[port]:
32
- base = (
33
- f"micropython-{ver_flat}-{port}-{board}"
34
- if board
35
- else f"micropython-{ver_flat}-{port}"
36
- )
33
+ base = f"micropython-{ver_flat}-{port}-{board}" if board else f"micropython-{ver_flat}-{port}"
37
34
  # check if we have a (merged)stub for this version and port
38
- if (CONFIG.stub_path / f"{base}-merged").exists() or (
39
- CONFIG.stub_path / base
40
- ).exists():
35
+ if (CONFIG.stub_path / f"{base}-merged").exists() or (CONFIG.stub_path / base).exists():
41
36
  return board
42
37
  # fallback to first listed board
43
38
  return DEFAULT_BOARDS[port][0]
@@ -8,10 +8,10 @@ from pathlib import Path
8
8
  import libcst as cst
9
9
  from loguru import logger as log
10
10
 
11
+ from mpflash.versions import clean_version
11
12
  from stubber.codemod.add_method import CallAdder, CallFinder
12
13
  from stubber.utils.config import CONFIG
13
14
  from stubber.utils.post import run_black
14
- from stubber.utils.versions import clean_version
15
15
 
16
16
 
17
17
  def add_machine_pin_call(merged_path: Path, version: str):
@@ -11,11 +11,11 @@ from loguru import logger as log
11
11
  from packaging.version import parse
12
12
  from pysondb import PysonDB
13
13
 
14
+ from mpflash.versions import clean_version
14
15
  from stubber.publish.defaults import GENERIC, GENERIC_L, default_board
15
16
  from stubber.publish.enums import StubSource
16
17
  from stubber.publish.stubpackage import StubPackage, StubSources
17
18
  from stubber.utils.config import CONFIG
18
- from stubber.utils.versions import clean_version
19
19
 
20
20
  # replace std log handler with a custom one capped on INFO level
21
21
  log.remove()
@@ -8,10 +8,10 @@ from typing import Dict, Optional
8
8
 
9
9
  from loguru import logger as log
10
10
 
11
+ from mpflash.versions import V_PREVIEW, clean_version
11
12
  from stubber.publish.defaults import default_board
12
13
  from stubber.publish.package import GENERIC
13
14
  from stubber.utils.config import CONFIG
14
- from stubber.utils.versions import V_PREVIEW, clean_version
15
15
 
16
16
 
17
17
  ## Helper functions
@@ -8,12 +8,12 @@ from typing import Any, Dict, List, Optional, Union
8
8
 
9
9
  from loguru import logger as log
10
10
 
11
+ from mpflash.versions import V_PREVIEW
11
12
  from stubber.publish.candidates import board_candidates, filter_list
12
13
  from stubber.publish.database import get_database
13
14
  from stubber.publish.defaults import GENERIC_U
14
15
  from stubber.publish.package import get_package
15
16
  from stubber.utils.config import CONFIG
16
- from stubber.utils.versions import V_PREVIEW
17
17
 
18
18
 
19
19
  def build_multiple(
@@ -9,7 +9,7 @@ from typing import Any, Dict, List, Optional, Tuple, Union
9
9
 
10
10
  import tenacity
11
11
 
12
- from stubber.basicgit import get_git_describe
12
+ from mpflash.basicgit import get_git_describe
13
13
  from stubber.publish.helpers import get_module_docstring
14
14
 
15
15
  try:
@@ -24,12 +24,12 @@ from loguru import logger as log
24
24
  from packaging.version import Version, parse
25
25
  from pysondb import PysonDB
26
26
 
27
+ from mpflash.versions import SET_PREVIEW, V_PREVIEW, clean_version
27
28
  from stubber.publish.bump import bump_version
28
29
  from stubber.publish.defaults import GENERIC_U, default_board
29
30
  from stubber.publish.enums import StubSource
30
31
  from stubber.publish.pypi import Version, get_pypi_versions
31
32
  from stubber.utils.config import CONFIG
32
- from stubber.utils.versions import SET_PREVIEW, V_PREVIEW, clean_version
33
33
 
34
34
  Status = NewType("Status", Dict[str, Union[str, None]])
35
35
  StubSources = List[Tuple[StubSource, Path]]
@@ -906,9 +906,7 @@ class StubPackage(PoetryBuilder):
906
906
  self.pkg_version = self.next_package_version(production)
907
907
  self.status["version"] = self.pkg_version
908
908
  # to get the next version
909
- log.debug(
910
- f"{self.package_name}: bump version for {old_ver} to {self.pkg_version } {'production' if production else 'test'}"
911
- )
909
+ log.debug(f"{self.package_name}: bump version for {old_ver} to {self.pkg_version } {'production' if production else 'test'}")
912
910
  self.write_package_json()
913
911
  log.trace(f"New hash: {self.package_name} {self.pkg_version} {self.hash}")
914
912
  if self.poetry_build():
stubber/rst/reader.py CHANGED
@@ -69,6 +69,7 @@ from typing import List, Optional, Tuple
69
69
 
70
70
  from loguru import logger as log
71
71
 
72
+ from mpflash.versions import V_PREVIEW
72
73
  from stubber.rst import (
73
74
  CHILD_PARENT_CLASS,
74
75
  MODULE_GLUE,
@@ -82,7 +83,6 @@ from stubber.rst import (
82
83
  )
83
84
  from stubber.rst.lookup import Fix
84
85
  from stubber.utils.config import CONFIG
85
- from stubber.utils.versions import V_PREVIEW
86
86
 
87
87
  SEPERATOR = "::"
88
88
 
@@ -369,9 +369,7 @@ class RSTParser(RSTReader):
369
369
  PARAM_RE_FIXES = [
370
370
  Fix(r"\[angle, time=0\]", "[angle], time=0", is_re=True), # fix: method:: Servo.angle([angle, time=0])
371
371
  Fix(r"\[speed, time=0\]", "[speed], time=0", is_re=True), # fix: .. method:: Servo.speed([speed, time=0])
372
- Fix(
373
- r"\[service_id, key=None, \*, \.\.\.\]", "[service_id], [key], *, ...", is_re=True
374
- ), # fix: network - AbstractNIC.connect
372
+ Fix(r"\[service_id, key=None, \*, \.\.\.\]", "[service_id], [key], *, ...", is_re=True), # fix: network - AbstractNIC.connect
375
373
  ]
376
374
 
377
375
  def __init__(self, v_tag: str) -> None:
@@ -497,9 +495,7 @@ class RSTParser(RSTReader):
497
495
  version = V_PREVIEW
498
496
  else:
499
497
  version = self.source_tag.replace("_", ".") # TODO Use clean_version(self.source_tag)
500
- docstr[0] = (
501
- f"{docstr[0]}.\n\nMicroPython module: https://docs.micropython.org/en/{version}/library/{module_name}.html"
502
- )
498
+ docstr[0] = f"{docstr[0]}.\n\nMicroPython module: https://docs.micropython.org/en/{version}/library/{module_name}.html"
503
499
 
504
500
  self.output_dict.name = module_name
505
501
  self.output_dict.add_comment(f"# source version: {self.source_tag}")
@@ -637,9 +633,7 @@ class RSTParser(RSTReader):
637
633
  params = self.fix_parameters(params, f"{class_name}.{name}")
638
634
 
639
635
  # parse return type from docstring
640
- ret_type = return_type_from_context(
641
- docstring=docstr, signature=f"{class_name}.{name}", module=self.current_module
642
- )
636
+ ret_type = return_type_from_context(docstring=docstr, signature=f"{class_name}.{name}", module=self.current_module)
643
637
  # methods have 4 flavours
644
638
  # - __init__ (self, <params>) -> None:
645
639
  # - classmethod (cls, <params>) -> <ret_type>:
@@ -759,9 +753,7 @@ class RSTParser(RSTReader):
759
753
 
760
754
  # deal with documentation wildcards
761
755
  for name in names:
762
- r_type = return_type_from_context(
763
- docstring=docstr, signature=name, module=self.current_module, literal=True
764
- )
756
+ r_type = return_type_from_context(docstring=docstr, signature=name, module=self.current_module, literal=True)
765
757
  if r_type in ["None"]: # None does not make sense
766
758
  r_type = "Incomplete" # Default to Incomplete/ Unknown / int
767
759
  name = self.strip_prefixes(name)
@@ -26,7 +26,6 @@
26
26
  # THE SOFTWARE.
27
27
 
28
28
  from __future__ import print_function
29
-
30
29
  import contextlib
31
30
  import os
32
31
  import sys
@@ -62,6 +61,9 @@ FILE_TYPE_LOCAL = 1
62
61
  # URL to file. (TODO)
63
62
  FILE_TYPE_HTTP = 2
64
63
 
64
+ # Default list of libraries in micropython-lib to search for library packages.
65
+ BASE_LIBRARY_NAMES = ("micropython", "python-stdlib", "python-ecosys")
66
+
65
67
 
66
68
  class ManifestFileError(Exception):
67
69
  pass
@@ -106,7 +108,7 @@ class ManifestPackageMetadata:
106
108
  self.stdlib = False
107
109
 
108
110
  # Allows a python-ecosys package to be annotated with the
109
- # corresponding name in PyPI. e.g. micropython-lib/urequests is based
111
+ # corresponding name in PyPI. e.g. micropython-lib/requests is based
110
112
  # on pypi/requests.
111
113
  self.pypi = None
112
114
  # For a micropython package, this is the name that we will publish it
@@ -143,7 +145,7 @@ class ManifestPackageMetadata:
143
145
 
144
146
  self.description = description
145
147
  self.version = version
146
- self.license = version
148
+ self.license = license
147
149
  self.author = author
148
150
  self.pypi = pypi
149
151
  self.pypi_publish = pypi_publish
@@ -194,6 +196,14 @@ class ManifestFile:
194
196
  self._visited = set()
195
197
  # Stack of metadata for each level.
196
198
  self._metadata = [ManifestPackageMetadata()]
199
+ # Registered external libraries.
200
+ self._libraries = {}
201
+ # List of directories to search for packages.
202
+ self._library_dirs = []
203
+ # Add default micropython-lib libraries if $(MPY_LIB_DIR) has been specified.
204
+ if self._path_vars["MPY_LIB_DIR"]:
205
+ for lib in BASE_LIBRARY_NAMES:
206
+ self.add_library(lib, os.path.join("$(MPY_LIB_DIR)", lib))
197
207
 
198
208
  def _resolve_path(self, path):
199
209
  # Convert path to an absolute path, applying variable substitutions.
@@ -208,6 +218,7 @@ class ManifestFile:
208
218
  "metadata": self.metadata,
209
219
  "include": self.include,
210
220
  "require": self.require,
221
+ "add_library": self.add_library,
211
222
  "package": self.package,
212
223
  "module": self.module,
213
224
  "options": IncludeOptions(**kwargs),
@@ -271,13 +282,15 @@ class ManifestFile:
271
282
  kind = KIND_COMPILE_AS_MPY
272
283
 
273
284
  self._manifest_files.append(
274
- ManifestOutput(FILE_TYPE_LOCAL, full_path, target_path, timestamp, kind, self._metadata[-1], opt)
285
+ ManifestOutput(
286
+ FILE_TYPE_LOCAL, full_path, target_path, timestamp, kind, self._metadata[-1], opt
287
+ )
275
288
  )
276
289
 
277
290
  def _search(self, base_path, package_path, files, exts, kind, opt=None, strict=False):
278
291
  base_path = self._resolve_path(base_path)
279
292
 
280
- if files:
293
+ if files is not None:
281
294
  # Use explicit list of files (relative to package_path).
282
295
  for file in files:
283
296
  if package_path:
@@ -386,14 +399,23 @@ class ManifestFile:
386
399
  if is_require:
387
400
  self._metadata.pop()
388
401
 
389
- def require(self, name, version=None, unix_ffi=False, pypi=None, **kwargs):
390
- """
391
- Require a module by name from micropython-lib.
402
+ def _require_from_path(self, library_path, name, version, extra_kwargs):
403
+ for root, dirnames, filenames in os.walk(library_path):
404
+ if os.path.basename(root) == name and "manifest.py" in filenames:
405
+ self.include(root, is_require=True, **extra_kwargs)
406
+ return True
407
+ return False
392
408
 
393
- Optionally specify unix_ffi=True to use a module from the unix-ffi directory.
409
+ def require(self, name, version=None, pypi=None, library=None, **kwargs):
410
+ """
411
+ Require a package by name from micropython-lib.
394
412
 
395
413
  Optionally specify pipy="package-name" to indicate that this should
396
414
  use the named package from PyPI when building for CPython.
415
+
416
+ Optionally specify library="name" to reference a package from a
417
+ library that has been previously registered with add_library(). Otherwise
418
+ the list of library paths will be used.
397
419
  """
398
420
  self._metadata[-1].check_initialised(self._mode)
399
421
 
@@ -404,24 +426,41 @@ class ManifestFile:
404
426
  self._pypi_dependencies.append(pypi)
405
427
  return
406
428
 
407
- if self._path_vars["MPY_LIB_DIR"]:
408
- lib_dirs = ["micropython", "python-stdlib", "python-ecosys"]
409
- if unix_ffi:
410
- # Search unix-ffi only if unix_ffi=True, and make unix-ffi modules
411
- # take precedence.
412
- lib_dirs = ["unix-ffi"] + lib_dirs
413
-
414
- for lib_dir in lib_dirs:
415
- # Search for {lib_dir}/**/{name}/manifest.py.
416
- for root, _, filenames in os.walk(os.path.join(self._path_vars["MPY_LIB_DIR"], lib_dir)):
417
- if os.path.basename(root) == name and "manifest.py" in filenames:
418
- self.include(root, is_require=True, **kwargs)
419
- return
420
-
421
- raise ValueError("Library not found in local micropython-lib: {}".format(name))
422
- else:
423
- # TODO: HTTP request to obtain URLs from manifest.json.
424
- raise ValueError("micropython-lib not available for require('{}').", name)
429
+ if library is not None:
430
+ # Find package in external library.
431
+ if library not in self._libraries:
432
+ raise ValueError("Unknown library '{}' for require('{}').".format(library, name))
433
+ library_path = self._libraries[library]
434
+ # Search for {library_path}/**/{name}/manifest.py.
435
+ if self._require_from_path(library_path, name, version, kwargs):
436
+ return
437
+ raise ValueError(
438
+ "Package '{}' not found in external library '{}' ({}).".format(
439
+ name, library, library_path
440
+ )
441
+ )
442
+
443
+ for lib_dir in self._library_dirs:
444
+ # Search for {lib_dir}/**/{name}/manifest.py.
445
+ if self._require_from_path(lib_dir, name, version, kwargs):
446
+ return
447
+
448
+ raise ValueError("Package '{}' not found in any known library.".format(name))
449
+
450
+ def add_library(self, library, library_path, prepend=False):
451
+ """
452
+ Register the path to an external named library.
453
+
454
+ The path will be automatically searched when using require(). By default the
455
+ added library is added to the end of the list of libraries to search. Pass
456
+ `prepend=True` to add it to the start of the list.
457
+
458
+ Additionally, the added library can be explicitly requested by using
459
+ `require("name", library="library")`.
460
+ """
461
+ library_path = self._resolve_path(library_path)
462
+ self._libraries[library] = library_path
463
+ self._library_dirs.insert(0 if prepend else len(self._library_dirs), library_path)
425
464
 
426
465
  def package(self, package_path, files=None, base_path=".", opt=None):
427
466
  """
@@ -563,6 +602,9 @@ def main():
563
602
  default=os.path.join(os.path.dirname(__file__), "../lib/micropython-lib"),
564
603
  help="path to micropython-lib repo",
565
604
  )
605
+ cmd_parser.add_argument(
606
+ "--unix-ffi", action="store_true", help="prepend unix-ffi to the library path"
607
+ )
566
608
  cmd_parser.add_argument("--port", default=None, help="path to port dir")
567
609
  cmd_parser.add_argument("--board", default=None, help="path to board dir")
568
610
  cmd_parser.add_argument(
@@ -592,6 +634,8 @@ def main():
592
634
  exit(1)
593
635
 
594
636
  m = ManifestFile(mode, path_vars)
637
+ if args.unix_ffi:
638
+ m.add_library("unix-ffi", os.path.join("$(MPY_LIB_DIR)", "unix-ffi"), prepend=True)
595
639
  for manifest_file in args.files:
596
640
  try:
597
641
  m.execute(manifest_file)
stubber/tools/readme.md CHANGED
@@ -2,5 +2,6 @@ tools vendored from micropython
2
2
 
3
3
  - manifestfile.py
4
4
  - Micropython manifest file parser
5
- - Micropython 1.19.1
6
- - https://github.com/micropython/micropython/blob/master/tools/manifestfile.py
5
+ - https://github.com/micropython/micropython/blob/master/tools/manifestfile.py
6
+ - v1.23.0
7
+ - https://raw.githubusercontent.com/micropython/micropython/v1.23.0/tools/manifestfile.py
@@ -9,7 +9,7 @@
9
9
 
10
10
  # from loguru import logger as log
11
11
 
12
- # from stubber.utils.versions import V_PREVIEW
12
+ # from mpflash.versions import V_PREVIEW
13
13
 
14
14
  # # log = logging.getLogger()
15
15
 
stubber/utils/__init__.py CHANGED
@@ -1,5 +1,6 @@
1
1
  # type: ignore
2
+ from mpflash.versions import checkedout_version, clean_version
3
+
2
4
  from .manifest import make_manifest, manifest
3
5
  from .post import do_post_processing
4
6
  from .stubmaker import generate_pyi_files, generate_pyi_from_file
5
- from .versions import checkedout_version, clean_version
stubber/utils/config.py CHANGED
@@ -7,8 +7,8 @@ from loguru import logger as log
7
7
  from typedconfig.config import Config, key, section
8
8
  from typedconfig.source import EnvironmentConfigSource
9
9
 
10
- import stubber.basicgit as git
11
- from stubber.utils.versions import V_PREVIEW
10
+ import mpflash.basicgit as git
11
+ from mpflash.versions import V_PREVIEW
12
12
 
13
13
  from .typed_config_toml import TomlConfigSource
14
14
 
@@ -113,9 +113,7 @@ def readconfig(filename: str = "pyproject.toml", prefix: str = "tool.", must_exi
113
113
  # add provider sources to the config
114
114
  config.add_source(EnvironmentConfigSource())
115
115
  if use_toml:
116
- config.add_source(
117
- TomlConfigSource(filename, prefix=prefix, must_exist=must_exist)
118
- ) # ,"tools.micropython-stubber"))
116
+ config.add_source(TomlConfigSource(filename, prefix=prefix, must_exist=must_exist)) # ,"tools.micropython-stubber"))
119
117
  config.read()
120
118
  return config
121
119