micropython-stubber 1.16.2__py3-none-any.whl → 1.17.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 (55) hide show
  1. {micropython_stubber-1.16.2.dist-info → micropython_stubber-1.17.0.dist-info}/METADATA +2 -1
  2. {micropython_stubber-1.16.2.dist-info → micropython_stubber-1.17.0.dist-info}/RECORD +54 -54
  3. stubber/__init__.py +1 -1
  4. stubber/basicgit.py +27 -33
  5. stubber/board/board_info.csv +137 -103
  6. stubber/board/createstubs.py +222 -189
  7. stubber/board/createstubs_db.py +284 -214
  8. stubber/board/createstubs_db_min.py +286 -265
  9. stubber/board/createstubs_db_mpy.mpy +0 -0
  10. stubber/board/createstubs_lvgl.py +171 -113
  11. stubber/board/createstubs_lvgl_min.py +738 -275
  12. stubber/board/createstubs_lvgl_mpy.mpy +0 -0
  13. stubber/board/createstubs_mem.py +237 -174
  14. stubber/board/createstubs_mem_min.py +263 -247
  15. stubber/board/createstubs_mem_mpy.mpy +0 -0
  16. stubber/board/createstubs_min.py +242 -227
  17. stubber/board/createstubs_mpy.mpy +0 -0
  18. stubber/board/fw_info.py +135 -0
  19. stubber/board/modulelist.txt +1 -2
  20. stubber/codemod/_partials/__init__.py +1 -1
  21. stubber/codemod/_partials/db_main.py +90 -72
  22. stubber/codemod/_partials/modules_reader.py +29 -17
  23. stubber/codemod/board.py +2 -4
  24. stubber/codemod/enrich.py +1 -1
  25. stubber/commands/build_cmd.py +6 -4
  26. stubber/commands/get_docstubs_cmd.py +6 -11
  27. stubber/commands/get_frozen_cmd.py +6 -11
  28. stubber/commands/switch_cmd.py +6 -4
  29. stubber/data/board_info.csv +134 -101
  30. stubber/data/board_info.json +1357 -901
  31. stubber/freeze/freeze_manifest_2.py +2 -1
  32. stubber/freeze/get_frozen.py +28 -13
  33. stubber/minify.py +56 -43
  34. stubber/publish/candidates.py +15 -23
  35. stubber/publish/defaults.py +2 -2
  36. stubber/publish/merge_docstubs.py +5 -7
  37. stubber/publish/missing_class_methods.py +2 -2
  38. stubber/publish/pathnames.py +2 -2
  39. stubber/publish/publish.py +2 -1
  40. stubber/publish/stubpackage.py +20 -40
  41. stubber/rst/lookup.py +9 -7
  42. stubber/rst/reader.py +2 -1
  43. stubber/stubber.py +5 -6
  44. stubber/update_fallback.py +3 -1
  45. stubber/update_module_list.py +1 -1
  46. stubber/utils/__init__.py +1 -1
  47. stubber/utils/config.py +7 -9
  48. stubber/utils/post.py +1 -1
  49. stubber/utils/repos.py +10 -7
  50. stubber/utils/versions.py +48 -7
  51. stubber/variants.py +3 -3
  52. stubber/board/logging.py +0 -99
  53. {micropython_stubber-1.16.2.dist-info → micropython_stubber-1.17.0.dist-info}/LICENSE +0 -0
  54. {micropython_stubber-1.16.2.dist-info → micropython_stubber-1.17.0.dist-info}/WHEEL +0 -0
  55. {micropython_stubber-1.16.2.dist-info → micropython_stubber-1.17.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,135 @@
1
+ # %%micropython
2
+ import os
3
+ import sys
4
+
5
+
6
+ def _build(s):
7
+ # extract a build nr from a string
8
+ if not s:
9
+ return ""
10
+ if " on " in s:
11
+ s = s.split(" on ", 1)[0]
12
+ return s.split("-")[1] if "-" in s else ""
13
+
14
+
15
+ def _version_str(version: tuple): # -> str:
16
+ v_str = ".".join([str(n) for n in version[:3]])
17
+ if len(version) > 3 and version[3]:
18
+ v_str += "-" + version[3]
19
+ return v_str
20
+
21
+
22
+ def _info(): # type:() -> dict[str, str]
23
+ # sourcery skip: use-contextlib-suppress, use-fstring-for-formatting, use-named-expression
24
+ info = dict(
25
+ {
26
+ "family": sys.implementation.name,
27
+ "version": "",
28
+ "build": "",
29
+ "ver": "",
30
+ "port": "stm32" if sys.platform.startswith("pyb") else sys.platform, # port: esp32 / win32 / linux / stm32
31
+ "board": "GENERIC",
32
+ "cpu": "",
33
+ "mpy": "",
34
+ "arch": "",
35
+ }
36
+ )
37
+ try:
38
+ info["version"] = _version_str(sys.implementation.version)
39
+ except AttributeError:
40
+ pass
41
+ try:
42
+ machine = sys.implementation._machine if "_machine" in dir(sys.implementation) else os.uname().machine
43
+ info["board"] = machine.strip()
44
+ info["cpu"] = machine.split("with")[-1].strip() if "with" in machine else ""
45
+ info["mpy"] = (
46
+ sys.implementation._mpy
47
+ if "_mpy" in dir(sys.implementation)
48
+ else sys.implementation.mpy
49
+ if "mpy" in dir(sys.implementation)
50
+ else ""
51
+ )
52
+ except (AttributeError, IndexError):
53
+ pass
54
+
55
+ try:
56
+ # extract build from uname().version if available
57
+ info["build"] = _build(os.uname()[3])
58
+ if not info["build"]:
59
+ # extract build from uname().release if available
60
+ info["build"] = _build(os.uname()[2])
61
+ if not info["build"] and ";" in sys.version:
62
+ # extract build from uname().release if available
63
+ info["build"] = _build(sys.version.split(";")[1])
64
+ except (AttributeError, IndexError):
65
+ pass
66
+ # avoid build hashes
67
+ if info["build"] and len(info["build"]) > 5:
68
+ info["build"] = ""
69
+
70
+ if info["version"] == "" and sys.platform not in ("unix", "win32"):
71
+ try:
72
+ u = os.uname()
73
+ info["version"] = u.release
74
+ except (IndexError, AttributeError, TypeError):
75
+ pass
76
+ # detect families
77
+ for fam_name, mod_name, mod_thing in [
78
+ ("pycopy", "pycopy", "const"),
79
+ ("pycom", "pycom", "FAT"),
80
+ ("ev3-pybricks", "pybricks.hubs", "EV3Brick"),
81
+ ]:
82
+ try:
83
+ _t = __import__(mod_name, None, None, (mod_thing))
84
+ info["family"] = fam_name
85
+ del _t
86
+ break
87
+ except (ImportError, KeyError):
88
+ pass
89
+
90
+ if info["family"] == "ev3-pybricks":
91
+ info["release"] = "2.0.0"
92
+
93
+ if info["family"] == "micropython":
94
+ if (
95
+ info["version"]
96
+ and info["version"].endswith(".0")
97
+ and info["version"] >= "1.10.0" # versions from 1.10.0 to 1.20.0 do not have a micro .0
98
+ and info["version"] <= "1.19.9"
99
+ ):
100
+ # drop the .0 for newer releases
101
+ info["version"] = info["version"][:-2]
102
+
103
+ # spell-checker: disable
104
+ if "mpy" in info and info["mpy"]: # mpy on some v1.11+ builds
105
+ sys_mpy = int(info["mpy"])
106
+ # .mpy architecture
107
+ arch = [
108
+ None,
109
+ "x86",
110
+ "x64",
111
+ "armv6",
112
+ "armv6m",
113
+ "armv7m",
114
+ "armv7em",
115
+ "armv7emsp",
116
+ "armv7emdp",
117
+ "xtensa",
118
+ "xtensawin",
119
+ ][sys_mpy >> 10]
120
+ if arch:
121
+ info["arch"] = arch
122
+ # .mpy version.minor
123
+ info["mpy"] = "v{}.{}".format(sys_mpy & 0xFF, sys_mpy >> 8 & 3)
124
+ # simple to use version[-build] string avoiding f-strings for backward compat
125
+ info["ver"] = (
126
+ "v{version}-{build}".format(version=info["version"], build=info["build"])
127
+ if info["build"]
128
+ else "v{version}".format(version=info["version"])
129
+ )
130
+
131
+ return info
132
+
133
+
134
+ print(_info())
135
+ # del _info, _build, _version_str
@@ -1,5 +1,4 @@
1
- # list of modules to stub.
2
- # used by the memory optimised createstubs_mem.py
1
+ # list of modules to stub used by the memory optimised createstubs_mem.py
3
2
  WM8960
4
3
  _OTA
5
4
  _asyncio
@@ -15,7 +15,7 @@ def _read_partial(path: Path) -> Iterator[str]:
15
15
  Read a partial from the file at `path`
16
16
  and yield only the lines between the ###PARTIAL### and ###PARTIALEND### markers
17
17
  """
18
- lines = deque(path.read_text().splitlines(keepends=True))
18
+ lines = deque(path.read_text(encoding="utf-8").splitlines(keepends=True))
19
19
  _start = False
20
20
  _end = False
21
21
  # todo: allow processing of files that do not have the markers
@@ -3,20 +3,30 @@ This file contains the `def main()` funcion for the db variant of createstubs.py
3
3
  - type_check_only is used to avoid circular imports
4
4
  The partial is enclosed in ###PARTIAL### and ###PARTIALEND### markers
5
5
  """
6
+ # sourcery skip: require-parameter-annotation, for-append-to-extend, use-named-expression
6
7
 
7
8
  from io import TextIOWrapper
8
9
  from typing import TYPE_CHECKING, List, type_check_only
9
10
 
10
- # sourcery skip: require-parameter-annotation
11
11
  if TYPE_CHECKING:
12
+ import gc
12
13
  import logging
13
14
  import sys
14
15
 
15
- @type_check_only
16
+ class logging:
17
+ def getLogger(self, name: str) -> "logging":
18
+ ...
19
+
20
+ def info(self, msg: str) -> None:
21
+ ...
22
+
23
+ log = logging()
24
+
16
25
  class Stubber:
17
26
  path: str
18
27
  _report: List[str]
19
28
  modules = []
29
+ _json_name: str
20
30
 
21
31
  def __init__(self, path: str = "", firmware_id: str = "") -> None:
22
32
  ...
@@ -27,114 +37,122 @@ if TYPE_CHECKING:
27
37
  def create_one_stub(self, modulename: str) -> bool:
28
38
  ...
29
39
 
30
- def report(self, filename: str = "modules.json"):
40
+ def report_start(self, filename: str = "modules.json"):
31
41
  ...
32
42
 
33
- def write_json_header(self, f: TextIOWrapper):
34
- ...
35
-
36
- def write_json_node(self, f: TextIOWrapper, n, first=False):
37
- ...
38
-
39
- def write_json_end(self, f):
43
+ def report_end(self):
40
44
  ...
41
45
 
42
46
  def create_all_stubs(self):
43
47
  ...
44
48
 
45
- @type_check_only
46
49
  def read_path() -> str:
47
50
  ...
48
51
 
49
- @type_check_only
50
52
  class _gc:
51
53
  def collect(self) -> None:
52
54
  ...
53
55
 
54
56
  gc: _gc
55
- _log = logging.getLogger("stubber")
57
+ log = logging.getLogger("stubber")
58
+
59
+ def file_exists(filename: str) -> bool:
60
+ ...
56
61
 
57
62
  LIBS = [".", "lib"]
58
63
 
59
64
 
60
65
  ###PARTIAL###
61
- def main():
62
- import machine # type: ignore
66
+ SKIP_FILE = "modulelist.done"
67
+
68
+
69
+ def get_modules(skip=0):
70
+ # new
71
+ for p in LIBS:
72
+ fname = p + "/modulelist.txt"
73
+ if not file_exists(fname):
74
+ continue
75
+ try:
76
+ with open(fname) as f:
77
+ i = 0
78
+ while True:
79
+ line = f.readline().strip()
80
+ if not line:
81
+ break
82
+ if len(line) > 0 and line[0] == "#":
83
+ continue
84
+ i += 1
85
+ if i < skip:
86
+ continue
87
+ yield line
88
+ break
89
+ except OSError:
90
+ pass
63
91
 
92
+
93
+ def write_skip(done):
94
+ # write count of modules already processed to file
95
+ with open(SKIP_FILE, "w") as f:
96
+ f.write(str(done) + "\n")
97
+
98
+
99
+ def read_skip():
100
+ # read count of modules already processed from file
101
+ done = 0
64
102
  try:
65
- f = open("modulelist.done", "r+b")
66
- was_running = True
67
- print("Opened existing db")
103
+ with open(SKIP_FILE) as f:
104
+ done = int(f.readline().strip())
68
105
  except OSError:
69
- f = open("modulelist.done", "w+b")
70
- print("created new db")
71
- was_running = False
106
+ pass
107
+ return done
108
+
109
+
110
+ def main():
111
+ import machine # type: ignore
112
+
113
+ was_running = file_exists(SKIP_FILE)
114
+ if was_running:
115
+ log.info("Continue from last run")
116
+ else:
117
+ log.info("Starting new run")
118
+ # try:
119
+ # f = open("modulelist.done", "r+b")
120
+ # was_running = True
121
+ # print("Continue from last run")
122
+ # except OSError:
123
+ # f = open("modulelist.done", "w+b")
124
+ # was_running = False
72
125
  stubber = Stubber(path=read_path())
73
126
 
74
127
  # f_name = "{}/{}".format(stubber.path, "modules.json")
128
+ skip = 0
75
129
  if not was_running:
76
130
  # Only clean folder if this is a first run
77
131
  stubber.clean()
78
- # get list of modules to process
79
- get_modulelist(stubber)
80
- # remove the ones that are already done
81
- modules_done = {} # type: dict[str, str]
82
- try:
83
- with open("modulelist.done") as f:
84
- # not optimal , but works on mpremote and esp8266
85
- for line in f.read().split("\n"):
86
- line = line.strip()
87
- gc.collect()
88
- if len(line) > 0:
89
- key, value = line.split("=", 1)
90
- modules_done[key] = value
91
- except (OSError, SyntaxError):
92
- pass
93
- gc.collect()
94
- # see if we can continue from where we left off
95
- modules = [m for m in stubber.modules if m not in modules_done.keys()]
96
- gc.collect()
97
- for modulename in modules:
132
+ stubber.report_start("modules.json")
133
+ else:
134
+ skip = read_skip()
135
+ stubber._json_name = "{}/{}".format(stubber.path, "modules.json")
136
+
137
+ for modulename in get_modules(skip):
98
138
  # ------------------------------------
99
139
  # do epic shit
100
140
  # but sometimes things fail / run out of memory and reboot
101
- ok = False
102
141
  try:
103
- ok = stubber.create_one_stub(modulename)
142
+ stubber.create_one_stub(modulename)
104
143
  except MemoryError:
105
144
  # RESET AND HOPE THAT IN THE NEXT CYCLE WE PROGRESS FURTHER
106
145
  machine.reset()
107
146
  # -------------------------------------
108
147
  gc.collect()
109
- modules_done[modulename] = str(stubber._report[-1] if ok else "failed")
110
- with open("modulelist.done", "a") as f:
111
- f.write("{}={}\n".format(modulename, "ok" if ok else "failed"))
112
-
113
- # Finished processing - load all the results , and remove the failed ones
114
- if modules_done:
115
- # stubber.write_json_end(mod_fp)
116
- stubber._report = [v for _, v in modules_done.items() if v != "failed"]
117
- stubber.report()
118
-
119
-
120
- def get_modulelist(stubber):
121
- stubber.modules = [] # avoid duplicates
122
- for p in LIBS:
123
- try:
124
- with open(p + "/modulelist.txt") as f:
125
- print("DEBUG: list of modules: " + p + "/modulelist.txt")
126
- for line in f.read().split("\n"):
127
- line = line.strip()
128
- if len(line) > 0 and line[0] != "#":
129
- stubber.modules.append(line)
130
- gc.collect()
131
- break
132
- except OSError:
133
- pass
134
- if not stubber.modules:
135
- stubber.modules = ["micropython"]
136
- _log.warn("Could not find modulelist.txt, using default modules")
137
- gc.collect()
148
+ # modules_done[modulename] = str(stubber._report[-1] if ok else "failed")
149
+ # with open("modulelist.done", "a") as f:
150
+ # f.write("{}={}\n".format(modulename, "ok" if ok else "failed"))
151
+ skip += 1
152
+ write_skip(skip)
153
+
154
+ print("All modules have been processed, Finalizing report")
155
+ stubber.report_end()
138
156
 
139
157
 
140
158
  ###PARTIALEND###
@@ -30,6 +30,9 @@ if TYPE_CHECKING:
30
30
  def read_path() -> str:
31
31
  ...
32
32
 
33
+ def file_exists(f: str) -> bool:
34
+ ...
35
+
33
36
  @type_check_only
34
37
  class _gc:
35
38
  def collect(self) -> None:
@@ -41,28 +44,37 @@ if TYPE_CHECKING:
41
44
  stubber: Stubber = None # type: ignore
42
45
  LIBS: List[str] = [".", "lib"]
43
46
 
47
+
44
48
  # sourcery skip: use-named-expression
45
49
  ###PARTIAL###
46
50
  # Read stubs from modulelist in the current folder or in /libs
47
51
  # fall back to default modules
48
- stubber.modules = [] # avoid duplicates
49
- for p in LIBS:
50
- try:
51
- _1 = gc.mem_free() # type: ignore
52
- with open(p + "/modulelist.txt") as f:
53
- print("Debug: List of modules: " + p + "/modulelist.txt")
54
- line = f.readline()
55
- while line:
56
- line = line.strip()
52
+ def get_modulelist(stubber):
53
+ # new
54
+ gc.collect()
55
+ stubber.modules = [] # avoid duplicates
56
+ for p in LIBS:
57
+ fname = p + "/modulelist.txt"
58
+ if not file_exists(fname):
59
+ continue
60
+ with open(fname) as f:
61
+ # print("DEBUG: list of modules: " + p + "/modulelist.txt")
62
+ while True:
63
+ line = f.readline().strip()
64
+ if not line:
65
+ break
57
66
  if len(line) > 0 and line[0] != "#":
58
67
  stubber.modules.append(line)
59
- line = f.readline()
60
- gc.collect() # type: ignore
61
- print("Debug: Used memory to load modulelist.txt: " + str(_1 - gc.mem_free()) + " bytes") # type: ignore
68
+ gc.collect()
69
+ print("BREAK")
62
70
  break
63
- except Exception:
64
- pass
65
- if not stubber.modules:
66
- stubber.modules = ["micropython"]
67
- print("Could not find modulelist.txt, using default modules")
71
+
72
+ if not stubber.modules:
73
+ stubber.modules = ["micropython"]
74
+ # _log.warn("Could not find modulelist.txt, using default modules")
75
+ gc.collect()
76
+
77
+
78
+ stubber.modules = [] # avoid duplicates
79
+ get_modulelist(stubber)
68
80
  ###PARTIALEND###
stubber/codemod/board.py CHANGED
@@ -12,10 +12,10 @@ from libcst import matchers as m
12
12
  from libcst.codemod._codemod import Codemod # type: ignore
13
13
  from packaging.version import Version
14
14
 
15
+ from stubber import __version__
15
16
  from stubber.codemod._partials import Partial
16
17
  from stubber.codemod.modify_list import ListChangeSet, ModifyListElements
17
18
  from stubber.cst_transformer import update_module_docstr
18
- from stubber import __version__
19
19
 
20
20
  # matches on `stubber = Stubber()`
21
21
  _STUBBER_MATCHER = m.Assign(
@@ -146,9 +146,7 @@ class ModuleDocCodemod(codemod.Codemod):
146
146
  def __init__(self, context: codemod.CodemodContext, module_doc: str):
147
147
  super().__init__(context)
148
148
  if module_doc.endswith('"""\n'):
149
- generated = (
150
- f'\nThis variant was generated from createstubs.py by micropython-stubber v{Version(__version__).base_version}\n"""\n'
151
- )
149
+ generated = f'\nThis variant was generated from createstubs.py by micropython-stubber v{Version(__version__).base_version}\n"""\n'
152
150
  module_doc = module_doc[:-4] + generated
153
151
  self.module_doc = module_doc
154
152
 
stubber/codemod/enrich.py CHANGED
@@ -74,7 +74,7 @@ def enrich_file(
74
74
 
75
75
  log.debug(f"Merge {target_path} from {docstub_file}")
76
76
  # read source file
77
- old_code = target_path.read_text()
77
+ old_code = target_path.read_text(encoding="utf-8")
78
78
 
79
79
  codemod_instance = merge_docstub.MergeCommand(context, docstub_file=docstub_file)
80
80
  if not (
@@ -22,7 +22,7 @@ from stubber.utils.config import CONFIG
22
22
  multiple=True,
23
23
  default=[CONFIG.stable_version],
24
24
  show_default=True,
25
- help="multiple: ",
25
+ help="MicroPython version to build, or 'preview' for the latest preview version",
26
26
  )
27
27
  @click.option(
28
28
  "--port",
@@ -72,9 +72,11 @@ def cli_build(
72
72
  ports = list(ports)
73
73
  boards = list(boards)
74
74
 
75
- if len(versions) > 1 :
76
- raise NotImplementedError("Multiple versions are not supported yet\n See https://github.com/Josverl/micropython-stubber/issues/487")
77
-
75
+ if len(versions) > 1:
76
+ raise NotImplementedError(
77
+ "Multiple versions are not supported yet\n See https://github.com/Josverl/micropython-stubber/issues/487"
78
+ )
79
+
78
80
  # db = get_database(publish_path=CONFIG.publish_path, production=production)
79
81
  log.info(f"Build {family} {versions} {ports} {boards}")
80
82
 
@@ -39,9 +39,7 @@ from .cli import stubber_cli
39
39
  show_default=True,
40
40
  )
41
41
  # @click.option("--family", "-f", "basename", default="micropython", help="Micropython family.", show_default=True)
42
- @click.option(
43
- "--version", "--tag", default="", type=str, help="Version number to use. [default: Git tag]"
44
- )
42
+ @click.option("--version", "--tag", default="", type=str, help="Version number to use. [default: Git tag]")
45
43
  @click.option("--black/--no-black", "-b/-nb", default=True, help="Run black", show_default=True)
46
44
  @click.pass_context
47
45
  def cli_docstubs(
@@ -72,16 +70,13 @@ def cli_docstubs(
72
70
  result = fetch_repos(version, CONFIG.mpy_path, CONFIG.mpy_lib_path)
73
71
  if not result:
74
72
  return -1
73
+ # get the current checked out version
74
+ version = utils.checkedout_version(CONFIG.mpy_path)
75
75
 
76
- v_tag = git.get_local_tag(rst_path.as_posix())
77
- if not v_tag:
78
- # if we can't find a tag , bail
79
- raise ValueError("No valid Tag found")
80
- v_tag = utils.clean_version(v_tag, flat=True, drop_v=False)
81
76
  release = git.get_local_tag(rst_path.as_posix(), abbreviate=False) or ""
82
77
 
83
- dst_path = Path(target) / f"{basename}-{v_tag}-docstubs"
78
+ dst_path = Path(target) / f"{basename}-{version}-docstubs"
84
79
 
85
- log.info(f"Get docstubs for MicroPython {utils.clean_version(v_tag, drop_v=False)}")
86
- generate_from_rst(rst_path, dst_path, v_tag, release=release, suffix=".pyi",black=black)
80
+ log.info(f"Get docstubs for MicroPython {utils.clean_version(version, drop_v=False)}")
81
+ generate_from_rst(rst_path, dst_path, version, release=release, suffix=".pyi", black=black)
87
82
  log.info("::group:: Done")
@@ -36,6 +36,7 @@ from .cli import stubber_cli
36
36
  default="",
37
37
  # default=[CONFIG.stable_version],
38
38
  show_default=True,
39
+ help="The version of MicroPython to get the frozen modules for. Use 'preview' to get the latest version from the micropython repo",
39
40
  )
40
41
  @click.option(
41
42
  "--stubgen/--no-stubgen",
@@ -78,27 +79,21 @@ def cli_get_frozen(
78
79
  else:
79
80
  version = utils.clean_version(git.get_local_tag(CONFIG.mpy_path.as_posix()) or "0.0")
80
81
  if not version:
81
- log.warning(
82
- "Unable to find the micropython repo in folder : {}".format(CONFIG.mpy_path.as_posix())
83
- )
82
+ log.warning("Unable to find the micropython repo in folder : {}".format(CONFIG.mpy_path.as_posix()))
84
83
 
85
84
  log.info("MicroPython version : {}".format(version))
86
85
  # folder/{family}-{version}-frozen
87
86
  family = "micropython"
88
- stub_path = Path(stub_folder) / f"{family}-{utils.clean_version(version, flat=True)}-frozen"
87
+
88
+ stub_path = freeze_any(version=version, mpy_path=CONFIG.mpy_path, mpy_lib_path=CONFIG.mpy_lib_path)
89
89
  stub_paths.append(stub_path)
90
- freeze_any(
91
- stub_path, version=version, mpy_path=CONFIG.mpy_path, mpy_lib_path=CONFIG.mpy_lib_path
92
- )
93
90
  # Also enrich the frozen modules from the doc stubs if available
94
91
 
95
92
  # first create .pyi files so they can be enriched
96
93
  utils.do_post_processing(stub_paths, stubgen=stubgen, black=False, autoflake=False)
97
94
  family = "micropython"
98
- docstubs_path = (
99
- Path(CONFIG.stub_path)
100
- / f"{family}-{utils.clean_version(version, drop_v=False, flat=True)}-docstubs"
101
- )
95
+ _version = utils.clean_version(version, drop_v=False, flat=True)
96
+ docstubs_path = Path(CONFIG.stub_path) / f"{family}-{_version}-docstubs"
102
97
  if docstubs_path.exists():
103
98
  log.info(f"Enriching {str(stub_path)} with {docstubs_path}")
104
99
  if merged := enrich_folder(
@@ -11,6 +11,7 @@ import click
11
11
  import stubber.basicgit as git
12
12
  from stubber.utils.config import CONFIG
13
13
  from stubber.utils.repos import fetch_repos, repo_paths
14
+ from stubber.utils.versions import SET_PREVIEW, V_PREVIEW
14
15
 
15
16
  from .cli import stubber_cli
16
17
 
@@ -22,10 +23,10 @@ from .cli import stubber_cli
22
23
  # get version list from Git tags in the repo that is provided on the command line
23
24
 
24
25
  try:
25
- VERSION_LIST = git.get_tags("micropython/micropython", minver="v1.9.3") + ["latest"]
26
+ VERSION_LIST = git.get_tags("micropython/micropython", minver="v1.9.3") + [V_PREVIEW, "latest"]
26
27
  except Exception:
27
28
  # offline fallback
28
- VERSION_LIST = ["v1.91.1", "v1.20.0", "latest"]
29
+ VERSION_LIST = ["v1.91.1", "v1.20.1", "v1.21.0", "v1.22.1", "preview"]
29
30
 
30
31
 
31
32
  @stubber_cli.command(name="switch")
@@ -46,7 +47,8 @@ def cli_switch(path: Union[str, Path], tag: Optional[str] = None):
46
47
  mpy_path, mpy_lib_path = repo_paths(Path(path))
47
48
  except Exception:
48
49
  return -1
49
- if not tag:
50
- tag = "latest"
50
+ if not tag or tag in SET_PREVIEW:
51
+ tag = V_PREVIEW
52
+
51
53
  result = fetch_repos(tag, mpy_path, mpy_lib_path)
52
54
  return -1 if result else 0