micropython-stubber 1.16.3__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 (49) hide show
  1. {micropython_stubber-1.16.3.dist-info → micropython_stubber-1.17.0.dist-info}/METADATA +1 -1
  2. {micropython_stubber-1.16.3.dist-info → micropython_stubber-1.17.0.dist-info}/RECORD +48 -49
  3. stubber/__init__.py +1 -1
  4. stubber/basicgit.py +11 -13
  5. stubber/board/createstubs.py +138 -97
  6. stubber/board/createstubs_db.py +211 -239
  7. stubber/board/createstubs_db_min.py +322 -844
  8. stubber/board/createstubs_db_mpy.mpy +0 -0
  9. stubber/board/createstubs_lvgl.py +91 -137
  10. stubber/board/createstubs_lvgl_min.py +87 -129
  11. stubber/board/createstubs_lvgl_mpy.mpy +0 -0
  12. stubber/board/createstubs_mem.py +164 -199
  13. stubber/board/createstubs_mem_min.py +297 -791
  14. stubber/board/createstubs_mem_mpy.mpy +0 -0
  15. stubber/board/createstubs_min.py +286 -1009
  16. stubber/board/createstubs_mpy.mpy +0 -0
  17. stubber/board/modulelist.txt +1 -2
  18. stubber/codemod/_partials/__init__.py +1 -1
  19. stubber/codemod/_partials/db_main.py +90 -72
  20. stubber/codemod/_partials/modules_reader.py +29 -17
  21. stubber/codemod/board.py +2 -4
  22. stubber/codemod/enrich.py +1 -1
  23. stubber/commands/build_cmd.py +6 -4
  24. stubber/commands/get_docstubs_cmd.py +6 -11
  25. stubber/commands/get_frozen_cmd.py +6 -11
  26. stubber/commands/switch_cmd.py +6 -4
  27. stubber/freeze/freeze_manifest_2.py +2 -1
  28. stubber/freeze/get_frozen.py +28 -13
  29. stubber/minify.py +51 -38
  30. stubber/publish/candidates.py +15 -23
  31. stubber/publish/defaults.py +2 -2
  32. stubber/publish/merge_docstubs.py +5 -7
  33. stubber/publish/missing_class_methods.py +2 -2
  34. stubber/publish/pathnames.py +2 -2
  35. stubber/publish/publish.py +2 -1
  36. stubber/publish/stubpackage.py +20 -41
  37. stubber/rst/lookup.py +9 -7
  38. stubber/rst/reader.py +2 -1
  39. stubber/stubber.py +5 -6
  40. stubber/update_fallback.py +3 -1
  41. stubber/utils/__init__.py +1 -1
  42. stubber/utils/config.py +7 -9
  43. stubber/utils/repos.py +6 -5
  44. stubber/utils/versions.py +48 -7
  45. stubber/variants.py +3 -3
  46. stubber/board/logging.py +0 -99
  47. {micropython_stubber-1.16.3.dist-info → micropython_stubber-1.17.0.dist-info}/LICENSE +0 -0
  48. {micropython_stubber-1.16.3.dist-info → micropython_stubber-1.17.0.dist-info}/WHEEL +0 -0
  49. {micropython_stubber-1.16.3.dist-info → micropython_stubber-1.17.0.dist-info}/entry_points.txt +0 -0
stubber/minify.py CHANGED
@@ -13,6 +13,8 @@ from typing import List, Tuple, Union
13
13
  import python_minifier
14
14
  from loguru import logger as log
15
15
 
16
+ from stubber.utils.versions import SET_PREVIEW, V_PREVIEW
17
+
16
18
  # Type Aliases for minify
17
19
  StubSource = Union[Path, str, StringIO, TextIOWrapper]
18
20
  XCompileDest = Union[Path, BytesIO]
@@ -192,7 +194,7 @@ def minify_script(source_script: StubSource, keep_report: bool = True, diff: boo
192
194
 
193
195
  source_content = ""
194
196
  if isinstance(source_script, Path):
195
- source_content = source_script.read_text()
197
+ source_content = source_script.read_text(encoding="utf-8")
196
198
  elif isinstance(source_script, (StringIO, TextIOWrapper)):
197
199
  source_content = "".join(source_script.readlines())
198
200
  elif isinstance(source_script, str): # type: ignore
@@ -202,7 +204,52 @@ def minify_script(source_script: StubSource, keep_report: bool = True, diff: boo
202
204
 
203
205
  if not source_content:
204
206
  raise ValueError("No source content")
207
+ len_1 = len(source_content)
208
+
209
+ if 0:
210
+ min_source = reduce_log_print(keep_report, diff, source_content)
211
+ else:
212
+ min_source = source_content
213
+ len_2 = len(min_source)
214
+
215
+ min_source = python_minifier.minify(
216
+ min_source,
217
+ filename=getattr(source_script, "name", None),
218
+ combine_imports=True,
219
+ remove_literal_statements=True, # no Docstrings
220
+ remove_annotations=True, # not used runtime anyways
221
+ hoist_literals=True, # remove redundant strings
222
+ rename_locals=True, # short names save memory
223
+ preserve_locals=["stubber", "path"], # names to keep
224
+ rename_globals=True, # short names save memory
225
+ # keep these globals to allow testing/mocking to work against the minified not compiled version
226
+ preserve_globals=[
227
+ "main",
228
+ "Stubber",
229
+ "read_path",
230
+ "get_root",
231
+ "_info",
232
+ "os",
233
+ "sys",
234
+ "__version__",
235
+ ],
236
+ # remove_pass=True, # no dead code
237
+ # convert_posargs_to_args=True, # Does not save any space
238
+ )
239
+ len_3 = len(min_source)
240
+ if 1:
241
+ # write to temp file for debugging
242
+ with open("tmp_minified.py", "w+") as f:
243
+ f.write(min_source)
205
244
 
245
+ log.info(f"Original length : {len_1}")
246
+ log.info(f"Reduced length : {len_2}")
247
+ log.info(f"Minified length : {len_3}")
248
+ log.info(f"Reduced by : {len_1-len_3} ")
249
+ return min_source
250
+
251
+
252
+ def reduce_log_print(keep_report, diff, source_content):
206
253
  edits: LineEdits = [
207
254
  ("keepprint", "print('Debug: "),
208
255
  ("keepprint", "print('DEBUG: "),
@@ -248,41 +295,7 @@ def minify_script(source_script: StubSource, keep_report: bool = True, diff: boo
248
295
  ] + edits
249
296
 
250
297
  content = edit_lines(source_content, edits, diff=diff)
251
-
252
- if 1:
253
- # write to temp file for debugging
254
- with open("tmp_minified.py", "w+") as f:
255
- f.write(content)
256
-
257
- # source = python_minifier.minify(
258
- # content,
259
- # filename=getattr(source_script, "name", None),
260
- # combine_imports=True,
261
- # remove_literal_statements=True, # no Docstrings
262
- # remove_annotations=True, # not used runtime anyways
263
- # hoist_literals=True, # remove redundant strings
264
- # rename_locals=True, # short names save memory
265
- # preserve_locals=["stubber", "path"], # names to keep
266
- # rename_globals=True, # short names save memory
267
- # # keep these globals to allow testing/mocking to work against the minified not compiled version
268
- # preserve_globals=[
269
- # "main",
270
- # "Stubber",
271
- # "read_path",
272
- # "get_root",
273
- # "_info",
274
- # "os",
275
- # "sys",
276
- # "__version__",
277
- # ],
278
- # # remove_pass=True, # no dead code
279
- # # convert_posargs_to_args=True, # Does not save any space
280
- # )
281
- source = content
282
- log.debug(f"Original length : {len(content)}")
283
- log.info(f"Minified length : {len(source)}")
284
- log.info(f"Reduced by : {len(content)-len(source)} ")
285
- return source
298
+ return content
286
299
 
287
300
 
288
301
  def minify(
@@ -349,7 +362,7 @@ def cross_compile(
349
362
  result = pipx_mpy_cross(version, source_file, _target)
350
363
  if result.stderr and "No matching distribution found for mpy-cross==" in result.stderr:
351
364
  log.warning(f"mpy-cross=={version} not found, using latest")
352
- result = pipx_mpy_cross("latest", source_file, _target)
365
+ result = pipx_mpy_cross(V_PREVIEW, source_file, _target)
353
366
 
354
367
  if result.returncode == 0:
355
368
  log.debug(f"mpy-cross compiled to : {_target.name}")
@@ -369,7 +382,7 @@ def pipx_mpy_cross(version: str, source_file, _target):
369
382
  """Run mpy-cross using pipx"""
370
383
 
371
384
  log.info(f"Compiling with mpy-cross version: {version}")
372
- if version == "latest":
385
+ if version in SET_PREVIEW:
373
386
  version = ""
374
387
  if version:
375
388
  version = "==" + version
@@ -10,7 +10,6 @@ what versions are available. This module provides functions to :
10
10
  - get a list of the firmware/board stubs (firmware candidates)
11
11
  """
12
12
 
13
-
14
13
  import re
15
14
  from pathlib import Path
16
15
  from typing import Any, Dict, Generator, List, Optional, Union
@@ -18,15 +17,11 @@ from typing import Any, Dict, Generator, List, Optional, Union
18
17
  from packaging.version import parse
19
18
 
20
19
  import stubber.basicgit as git
21
- from stubber.publish.enums import COMBO_STUBS, DOC_STUBS, FIRMWARE_STUBS
20
+ from stubber import utils
22
21
  from stubber.publish.defaults import GENERIC, GENERIC_L, GENERIC_U
22
+ from stubber.publish.enums import COMBO_STUBS, DOC_STUBS, FIRMWARE_STUBS
23
23
  from stubber.utils.config import CONFIG
24
- from stubber.utils.versions import clean_version, micropython_versions
25
-
26
- OLDEST_VERSION = "1.16"
27
- "This is the oldest MicroPython version to build the stubs on"
28
-
29
- V_LATEST = "latest"
24
+ from stubber.utils.versions import OLDEST_VERSION, SET_PREVIEW, V_PREVIEW, clean_version, micropython_versions
30
25
 
31
26
 
32
27
  def subfolder_names(path: Path):
@@ -50,13 +45,13 @@ def version_candidates(
50
45
  for name in subfolder_names(path):
51
46
  if match := re.match(folder_re, name):
52
47
  folder_ver = clean_version(match[1])
53
- if folder_ver == V_LATEST or parse(folder_ver) >= parse(oldest):
48
+ if folder_ver == V_PREVIEW or parse(folder_ver) >= parse(oldest):
54
49
  yield folder_ver
55
50
 
56
51
 
57
52
  def list_frozen_ports(
58
53
  family: str = "micropython",
59
- version: str = V_LATEST,
54
+ version: str = V_PREVIEW,
60
55
  path: Path = CONFIG.stub_path,
61
56
  ):
62
57
  "get list of ports with frozen stubs for a given family and version"
@@ -94,7 +89,7 @@ def list_micropython_port_boards(
94
89
 
95
90
  def frozen_candidates(
96
91
  family: str = "micropython",
97
- versions: Union[str, List[str]] = V_LATEST,
92
+ versions: Union[str, List[str]] = V_PREVIEW,
98
93
  ports: Union[str, List[str]] = "all",
99
94
  boards: Union[str, List[str]] = "all",
100
95
  *,
@@ -111,7 +106,7 @@ def frozen_candidates(
111
106
  auto_port = is_auto(ports)
112
107
  auto_board = is_auto(boards)
113
108
  if is_auto(versions):
114
- versions = list(version_candidates(suffix="frozen", prefix=family, path=path)) + [V_LATEST]
109
+ versions = list(version_candidates(suffix="frozen", prefix=family, path=path)) + [V_PREVIEW]
115
110
  else:
116
111
  versions = [versions] if isinstance(versions, str) else versions
117
112
 
@@ -129,9 +124,7 @@ def frozen_candidates(
129
124
  # lookup the (frozen) micropython ports
130
125
  ports = list_frozen_ports(family, version, path=path)
131
126
  else:
132
- raise NotImplementedError(
133
- f"auto ports not implemented for family {family}"
134
- ) # pragma: no cover
127
+ raise NotImplementedError(f"auto ports not implemented for family {family}") # pragma: no cover
135
128
  # elif family == "pycom":
136
129
  # ports = ["esp32"]
137
130
  # elif family == "lobo":
@@ -164,9 +157,7 @@ def frozen_candidates(
164
157
 
165
158
  else:
166
159
  # raise NotImplementedError(f"auto boards not implemented for family {family}") # pragma: no cover
167
- raise NotImplementedError(
168
- f"auto boards not implemented for family {family}"
169
- ) # pragma: no cover
160
+ raise NotImplementedError(f"auto boards not implemented for family {family}") # pragma: no cover
170
161
  # elif family == "pycom":
171
162
  # boards = ["wipy", "lopy", "gpy", "fipy"]
172
163
  # ---------------------------------------------------------------------------
@@ -199,7 +190,7 @@ def is_auto(thing: Union[None, str, List[str]]):
199
190
 
200
191
  def docstub_candidates(
201
192
  family: str = "micropython",
202
- versions: Union[str, List[str]] = V_LATEST,
193
+ versions: Union[str, List[str]] = V_PREVIEW,
203
194
  path: Path = CONFIG.stub_path,
204
195
  ):
205
196
  """
@@ -220,7 +211,7 @@ def docstub_candidates(
220
211
 
221
212
  def board_candidates(
222
213
  family: str = "micropython",
223
- versions: Union[str, List[str]] = V_LATEST,
214
+ versions: Union[str, List[str]] = V_PREVIEW,
224
215
  *,
225
216
  mpy_path: Path = CONFIG.mpy_path,
226
217
  pt: str = FIRMWARE_STUBS,
@@ -237,8 +228,10 @@ def board_candidates(
237
228
 
238
229
  for version in versions:
239
230
  # check out the micropython repo for this version
240
- if version in ["latest", "master"]:
231
+ if version in SET_PREVIEW:
241
232
  r = git.switch_branch(repo=mpy_path, branch="master")
233
+ # get the current checked out version
234
+ version = utils.checkedout_version(mpy_path)
242
235
  else:
243
236
  r = git.checkout_tag(repo=mpy_path, tag=version)
244
237
  if not r:
@@ -283,7 +276,6 @@ def filter_list(
283
276
  worklist = [
284
277
  i
285
278
  for i in worklist
286
- if i["board"].lower() in boards_
287
- or i["board"].lower().replace("generic_", "") in boards_
279
+ if i["board"].lower() in boards_ or i["board"].lower().replace("generic_", "") in boards_
288
280
  ]
289
281
  return worklist
@@ -2,7 +2,7 @@
2
2
  from typing import Dict, List
3
3
 
4
4
  from stubber.utils.config import CONFIG
5
- from stubber.utils.versions import clean_version
5
+ from stubber.utils.versions import V_PREVIEW, clean_version
6
6
 
7
7
  # The default board for the ports modules documented with base name only
8
8
  # as the MicroPython BOARD naming convention has changed over time there are different options to try
@@ -24,7 +24,7 @@ GENERIC = {GENERIC_L, GENERIC_U}
24
24
  "GENERIC eithercase"
25
25
 
26
26
 
27
- def default_board(port: str, version="latest") -> str: # sourcery skip: assign-if-exp
27
+ def default_board(port: str, version=V_PREVIEW) -> str: # sourcery skip: assign-if-exp
28
28
  """Return the default board for the given version and port"""
29
29
  ver_flat = clean_version(version, flat=True)
30
30
  if port in DEFAULT_BOARDS:
@@ -49,9 +49,7 @@ def merge_all_docstubs(
49
49
  for candidate in candidates:
50
50
  # use the default board for the port
51
51
  if candidate["board"] in GENERIC:
52
- candidate["board"] = default_board(
53
- port=candidate["port"], version=candidate["version"]
54
- )
52
+ candidate["board"] = default_board(port=candidate["port"], version=candidate["version"])
55
53
  # check if we have board stubs of this version and port
56
54
  doc_path = CONFIG.stub_path / f"{get_base(candidate)}-docstubs"
57
55
  # src and dest paths
@@ -120,13 +118,13 @@ def copy_and_merge_docstubs(fw_path: Path, dest_path: Path, docstub_path: Path):
120
118
  "pycopy_imphook", # is not intended to be used directly, and has an unresolved subclass
121
119
  ]:
122
120
  for suffix in [".py", ".pyi"]:
123
- if (dest_path / name).with_suffix(suffix).exists(): # type: ignore
124
- (dest_path / name).with_suffix(suffix).unlink() # type: ignore
121
+ if (dest_path / name).with_suffix(suffix).exists(): # type: ignore
122
+ (dest_path / name).with_suffix(suffix).unlink() # type: ignore
125
123
 
126
124
  # 2 - Enrich the firmware stubs with the document stubs
127
125
  result = enrich_folder(dest_path, docstub_path=docstub_path, write_back=True)
128
126
 
129
127
  # copy the docstubs manifest.json file to the package folder
130
- # if (docstub_path / "modules.json").exists():
131
- shutil.copy(docstub_path / "modules.json", dest_path / "doc_stubs.json")
128
+ if (docstub_path / "modules.json").exists():
129
+ shutil.copy(docstub_path / "modules.json", dest_path / "doc_stubs.json")
132
130
  return result
@@ -27,7 +27,7 @@ def add_machine_pin_call(merged_path: Path, version: str):
27
27
  log.error(f"no docstubs found for {version}")
28
28
  return False
29
29
  log.trace(f"Parsing {mod_path} for __call__ method")
30
- source = mod_path.read_text()
30
+ source = mod_path.read_text(encoding="utf-8")
31
31
  module = cst.parse_module(source)
32
32
 
33
33
  call_finder = CallFinder()
@@ -40,7 +40,7 @@ def add_machine_pin_call(merged_path: Path, version: str):
40
40
  # then use the CallAdder to add the __call__ method to all machine and pyb stubs
41
41
  mod_paths = [f for f in merged_path.rglob("*.*") if f.stem in {"machine", "umachine", "pyb"}]
42
42
  for mod_path in mod_paths:
43
- source = mod_path.read_text()
43
+ source = mod_path.read_text(encoding="utf-8")
44
44
  machine_module = cst.parse_module(source)
45
45
  new_module = machine_module.visit(CallAdder(call_finder.call_meth))
46
46
  mod_path.write_text(new_module.code)
@@ -11,7 +11,7 @@ from loguru import logger as log
11
11
  from stubber.publish.defaults import default_board
12
12
  from stubber.publish.package import GENERIC
13
13
  from stubber.utils.config import CONFIG
14
- from stubber.utils.versions import clean_version
14
+ from stubber.utils.versions import V_PREVIEW, clean_version
15
15
 
16
16
 
17
17
  ## Helper functions
@@ -40,7 +40,7 @@ def board_folder_name(fw: Dict, *, version: Optional[str] = None) -> str:
40
40
 
41
41
  def get_board_path(candidate: Dict) -> Path:
42
42
  board_path = CONFIG.stub_path / board_folder_name(candidate)
43
- if candidate["version"] == "latest" and not board_path.exists():
43
+ if V_PREVIEW in candidate["version"] and not board_path.exists():
44
44
  log.debug(f"no board stubs found for {candidate['version']}, trying stable")
45
45
  board_path = CONFIG.stub_path / board_folder_name(candidate, version=CONFIG.stable_version)
46
46
 
@@ -13,11 +13,12 @@ from stubber.publish.defaults import GENERIC_U
13
13
  from stubber.publish.enums import COMBO_STUBS
14
14
  from stubber.publish.package import get_package
15
15
  from stubber.utils.config import CONFIG
16
+ from stubber.utils.versions import V_PREVIEW
16
17
 
17
18
 
18
19
  def build_multiple(
19
20
  family: str = "micropython",
20
- versions: List[str] = ["v1.19.1"],
21
+ versions: List[str] = [V_PREVIEW],
21
22
  ports: List[str] = ["all"],
22
23
  boards: List[str] = [GENERIC_U],
23
24
  production: bool = False,
@@ -29,7 +29,7 @@ from stubber.publish.defaults import GENERIC_U, default_board
29
29
  from stubber.publish.enums import StubSource
30
30
  from stubber.publish.pypi import Version, get_pypi_versions
31
31
  from stubber.utils.config import CONFIG
32
- from stubber.utils.versions import clean_version
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]]
@@ -108,7 +108,7 @@ class VersionedPackage(object):
108
108
  return self._get_next_package_version(production)
109
109
 
110
110
  def is_preview(self):
111
- return self.mpy_version == "latest" or "preview" in self.mpy_version
111
+ return self.mpy_version in SET_PREVIEW or V_PREVIEW in self.mpy_version
112
112
 
113
113
  def _get_next_preview_package_version(self, production: bool = False) -> str:
114
114
  """
@@ -125,17 +125,9 @@ class VersionedPackage(object):
125
125
  parts = describe.split("-", 3)
126
126
  ver = parts[0]
127
127
  if len(parts) > 1:
128
- rc = (
129
- parts[1]
130
- if parts[1].isdigit()
131
- else parts[2]
132
- if len(parts) > 2 and parts[2].isdigit()
133
- else 1
134
- )
128
+ rc = parts[1] if parts[1].isdigit() else parts[2] if len(parts) > 2 and parts[2].isdigit() else 1
135
129
  rc = int(rc)
136
- base = (
137
- bump_version(Version(ver), minor_bump=True) if parts[1] != "preview" else Version(ver)
138
- )
130
+ base = bump_version(Version(ver), minor_bump=True) if parts[1] != V_PREVIEW else Version(ver)
139
131
  return str(bump_version(base, rc=rc))
140
132
  # raise ValueError("cannot determine next version number micropython")
141
133
 
@@ -312,9 +304,7 @@ class Builder(VersionedPackage):
312
304
  # Check if all stub source folders exist
313
305
  for stub_type, src_path in self.stub_sources:
314
306
  if not (CONFIG.stub_path / src_path).exists():
315
- raise FileNotFoundError(
316
- f"Could not find stub source folder {CONFIG.stub_path / src_path}"
317
- )
307
+ raise FileNotFoundError(f"Could not find stub source folder {CONFIG.stub_path / src_path}")
318
308
 
319
309
  # 1 - Copy the stubs to the package, directly in the package folder (no folders)
320
310
  # for stub_type, fw_path in [s for s in self.stub_sources]:
@@ -325,9 +315,7 @@ class Builder(VersionedPackage):
325
315
  self.copy_folder(stub_type, src_path)
326
316
  except OSError as e:
327
317
  if stub_type != StubSource.FROZEN:
328
- raise FileNotFoundError(
329
- f"Could not find stub source folder {src_path}"
330
- ) from e
318
+ raise FileNotFoundError(f"Could not find stub source folder {src_path}") from e
331
319
  else:
332
320
  log.debug(f"Error copying stubs from : {CONFIG.stub_path / src_path}, {e}")
333
321
  finally:
@@ -594,7 +582,7 @@ class PoetryBuilder(Builder):
594
582
  with open(_toml, "rb") as f:
595
583
  pyproject = tomllib.load(f)
596
584
  ver = pyproject["tool"]["poetry"]["version"]
597
- return str(parse(ver)) if ver != "latest" else ver
585
+ return str(parse(ver)) if ver not in SET_PREVIEW else ver
598
586
 
599
587
  @pkg_version.setter
600
588
  def pkg_version(self, version: str) -> None:
@@ -654,7 +642,7 @@ class PoetryBuilder(Builder):
654
642
  # stdout=subprocess.PIPE,
655
643
  stdout=subprocess.PIPE, # interestingly: errors on stdout , output on stderr .....
656
644
  universal_newlines=True,
657
- encoding="utf-8"
645
+ encoding="utf-8",
658
646
  )
659
647
  log.trace(f"poetry {parameters} completed")
660
648
  except (NotADirectoryError, FileNotFoundError) as e: # pragma: no cover # InvalidVersion
@@ -719,8 +707,7 @@ class PoetryBuilder(Builder):
719
707
  _pyproject = self.pyproject
720
708
  assert _pyproject is not None, "No pyproject.toml file found"
721
709
  _pyproject["tool"]["poetry"]["packages"] = [
722
- {"include": p.relative_to(self.package_path).as_posix()}
723
- for p in sorted((self.package_path).rglob("*.pyi"))
710
+ {"include": p.relative_to(self.package_path).as_posix()} for p in sorted((self.package_path).rglob("*.pyi"))
724
711
  ]
725
712
  # write out the pyproject.toml file
726
713
  self.pyproject = _pyproject
@@ -863,9 +850,7 @@ class StubPackage(PoetryBuilder):
863
850
  # check if the sources exist
864
851
  ok = self.are_package_sources_available()
865
852
  if not ok:
866
- log.debug(
867
- f"{self.package_name}: skipping as one or more source stub folders are missing"
868
- )
853
+ log.debug(f"{self.package_name}: skipping as one or more source stub folders are missing")
869
854
  self.status["error"] = "Skipped, stub folder(s) missing"
870
855
  shutil.rmtree(self.package_path.as_posix())
871
856
  self._publish = False # type: ignore
@@ -887,9 +872,7 @@ class StubPackage(PoetryBuilder):
887
872
  self,
888
873
  production: bool, # PyPI or Test-PyPi - USED TO FIND THE NEXT VERSION NUMBER
889
874
  force=False, # BUILD even if no changes
890
- ) -> (
891
- bool
892
- ): # sourcery skip: default-mutable-arg, extract-duplicate-method, require-parameter-annotation
875
+ ) -> bool: # sourcery skip: default-mutable-arg, extract-duplicate-method, require-parameter-annotation
893
876
  """
894
877
  Build a package
895
878
  look up the previous package version in the dabase
@@ -909,14 +892,14 @@ class StubPackage(PoetryBuilder):
909
892
  if not self.status["error"]:
910
893
  self.status["error"] = "Could not build/update package"
911
894
  return False
912
- # If there are changes to the package, then publish it
913
- if self.is_changed():
914
- log.info(f"Found changes to package sources: {self.package_name} {self.pkg_version} ")
915
- log.trace(f"Old hash {self.hash} != New hash {self.calculate_hash()}")
916
- elif force:
917
- log.info(f"Force build: {self.package_name} {self.pkg_version} ")
918
895
 
896
+ # If there are changes to the package, then publish it
919
897
  if self.is_changed() or force:
898
+ if force:
899
+ log.info(f"Force build: {self.package_name} {self.pkg_version} ")
900
+ else:
901
+ log.info(f"Found changes to package sources: {self.package_name} {self.pkg_version} ")
902
+ log.trace(f"Old hash {self.hash} != New hash {self.calculate_hash()}")
920
903
  # Build the distribution files
921
904
  old_ver = self.pkg_version
922
905
  self.pkg_version = self.next_package_version(production)
@@ -976,10 +959,8 @@ class StubPackage(PoetryBuilder):
976
959
  self.next_package_version(production=production)
977
960
  # Publish the package to PyPi, Test-PyPi or Github
978
961
  if self.is_changed():
979
- if self.mpy_version == "latest" and production and not force:
980
- log.warning(
981
- "version: `latest` package will only be available on Github, and not published to PyPi."
982
- )
962
+ if self.mpy_version in SET_PREVIEW and production and not force:
963
+ log.warning("version: `latest` package will only be available on Github, and not published to PyPi.")
983
964
  self.status["result"] = "Published to GitHub"
984
965
  else:
985
966
  return self.publish_distribution(dry_run, production, db)
@@ -1008,9 +989,7 @@ class StubPackage(PoetryBuilder):
1008
989
  if not dry_run:
1009
990
  pub_ok = self.poetry_publish(production=production)
1010
991
  else:
1011
- log.warning(
1012
- f"{self.package_name}: Dry run, not publishing to {'' if production else 'Test-'}PyPi"
1013
- )
992
+ log.warning(f"{self.package_name}: Dry run, not publishing to {'' if production else 'Test-'}PyPi")
1014
993
  pub_ok = True
1015
994
  if not pub_ok:
1016
995
  log.warning(f"{self.package_name}: Publish failed for {self.pkg_version}")
stubber/rst/lookup.py CHANGED
@@ -20,6 +20,7 @@ __all__ = [
20
20
 
21
21
  # all possible Types needed for the stubs - exxess types should be removed later , and otherwise won't do much harm
22
22
  TYPING_IMPORT: List[str] = [
23
+ "from __future__ import annotations",
23
24
  "from typing import IO, Any, Callable, Coroutine, Dict, Generator, Iterator, List, NoReturn, Optional, Tuple, Union, NamedTuple, TypeVar",
24
25
  "from _typeshed import Incomplete",
25
26
  ]
@@ -483,17 +484,18 @@ PARAM_FIXES = [
483
484
  # List of classes and their parent classes that should be added to the class definition
484
485
  CHILD_PARENT_CLASS = {
485
486
  # machine
486
- # "SoftSPI": "SPI", # BUG: SoftSPI is defined before SPI, so baseclass is not yet available
487
+ # SoftSPI is defined before SPI, so baseclass is not yet available - but in a .pyi that is OK
488
+ "SoftSPI": "SPI",
487
489
  "SoftI2C": "I2C",
488
490
  "Switch": "Pin",
489
491
  "Signal": "Pin",
490
492
  # uio # unclear regarding deprecation in python 3.12
491
493
  # "IOBase": "IO", # DOCME not in documentation
492
- "TextIOWrapper": "IO",
493
- "FileIO": "IO",
494
- "StringIO": "IO",
495
- "BytesIO": "IO",
496
- "BufferedWriter": "IOBase", # DOCME: not in documentation
494
+ "TextIOWrapper": "IO", # "TextIOBase, TextIO", # based on Stdlib
495
+ "FileIO": "IO", # "RawIOBase, BinaryIO", # based on Stdlib
496
+ "StringIO": "IO", # "BufferedIOBase, BinaryIO", # based on Stdlib
497
+ "BytesIO": "IO", # "BufferedIOBase, BinaryIO", # based on Stdlib
498
+ "BufferedWriter": "IOBase", # DOCME: not in documentation # "BufferedWriter": "BufferedIOBase", # based on Stdlib
497
499
  # uzlib
498
500
  # "DecompIO": "IO", # https://docs.python.org/3/library/typing.html#other-concrete-types
499
501
  # -------------------------------------------------------------------------------------
@@ -512,7 +514,7 @@ CHILD_PARENT_CLASS = {
512
514
  "namedtuple": "tuple",
513
515
  "deque": "stdlib_deque",
514
516
  # ESPNow
515
- "ESPNow": "ESPNowBase,Iterator", # causes issue with mypy
517
+ "ESPNow": "ESPNowBase,Iterator", # causes issue with mypy
516
518
  "AIOESPNow": "ESPNow",
517
519
  # array
518
520
  "array": "List",
stubber/rst/reader.py CHANGED
@@ -83,6 +83,7 @@ from stubber.rst import (
83
83
  )
84
84
  from stubber.rst.lookup import Fix
85
85
  from stubber.utils.config import CONFIG
86
+ from stubber.utils.versions import V_PREVIEW
86
87
 
87
88
  SEPERATOR = "::"
88
89
 
@@ -506,7 +507,7 @@ class RSTParser(RSTReader):
506
507
  # Add link to online documentation
507
508
  # https://docs.micropython.org/en/v1.17/library/array.html
508
509
  if "nightly" in self.source_tag:
509
- version = "latest"
510
+ version = V_PREVIEW
510
511
  else:
511
512
  version = self.source_tag.replace(
512
513
  "_", "."
stubber/stubber.py CHANGED
@@ -4,8 +4,8 @@
4
4
  """Create, Process, and Maintain stubs ✏️ for MicroPython"""
5
5
 
6
6
 
7
- from stubber.commands.cli import stubber_cli
8
7
  from stubber.commands.build_cmd import cli_build
8
+ from stubber.commands.cli import stubber_cli
9
9
  from stubber.commands.clone_cmd import cli_clone
10
10
  from stubber.commands.config_cmd import cli_config
11
11
  from stubber.commands.enrich_folder_cmd import cli_enrich_folder
@@ -22,7 +22,6 @@ from stubber.commands.upd_fallback_cmd import cli_update_fallback
22
22
  from stubber.commands.upd_module_list_cmd import cli_update_module_list
23
23
  from stubber.commands.variants_cmd import cli_variants
24
24
 
25
-
26
25
  ##########################################################################################
27
26
  if __name__ == "__main__":
28
27
  # add all commands to the CLI
@@ -33,13 +32,13 @@ if __name__ == "__main__":
33
32
  stubber_cli.add_command(cli_docstubs)
34
33
  stubber_cli.add_command(cli_get_core)
35
34
  stubber_cli.add_command(cli_get_frozen)
36
- stubber_cli.add_command(cli_get_lobo)
35
+ # stubber_cli.add_command(cli_get_lobo)
37
36
  stubber_cli.add_command(cli_stub)
38
37
  stubber_cli.add_command(cli_enrich_folder)
39
- stubber_cli.add_command(cli_minify)
38
+ # stubber_cli.add_command(cli_minify)
40
39
  stubber_cli.add_command(cli_publish)
41
40
  stubber_cli.add_command(cli_merge_docstubs)
42
- stubber_cli.add_command(cli_update_module_list)
43
- stubber_cli.add_command(cli_update_fallback)
41
+ # stubber_cli.add_command(cli_update_module_list)
42
+ # stubber_cli.add_command(cli_update_fallback)
44
43
  stubber_cli.add_command(cli_variants)
45
44
  stubber_cli()
@@ -9,6 +9,8 @@ from typing import List, Optional, Tuple
9
9
 
10
10
  from loguru import logger as log
11
11
 
12
+ from stubber.utils.versions import V_PREVIEW
13
+
12
14
  # log = logging.getLogger()
13
15
 
14
16
  RELEASED = "v1_18"
@@ -24,7 +26,7 @@ def fallback_sources(version: str, fw_version: Optional[str] = None) -> List[Tup
24
26
  """
25
27
  if not fw_version:
26
28
  fw_version = version
27
- if fw_version == "latest":
29
+ if fw_version == V_PREVIEW:
28
30
  fw_version = RELEASED
29
31
  SOURCES = [
30
32
  ("uasyncio", f"micropython-{fw_version}-esp32"),
stubber/utils/__init__.py CHANGED
@@ -2,4 +2,4 @@
2
2
  from .manifest import make_manifest, manifest
3
3
  from .post import do_post_processing
4
4
  from .stubmaker import generate_pyi_files, generate_pyi_from_file
5
- from .versions import clean_version
5
+ from .versions import checkedout_version, clean_version