micropython-stubber 1.20.4__py3-none-any.whl → 1.20.5__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 (44) hide show
  1. {micropython_stubber-1.20.4.dist-info → micropython_stubber-1.20.5.dist-info}/METADATA +4 -4
  2. {micropython_stubber-1.20.4.dist-info → micropython_stubber-1.20.5.dist-info}/RECORD +44 -39
  3. mpflash/mpflash/ask_input.py +24 -14
  4. mpflash/mpflash/bootloader/__init__.py +36 -0
  5. mpflash/mpflash/bootloader/manual.py +102 -0
  6. mpflash/mpflash/bootloader/micropython.py +10 -0
  7. mpflash/mpflash/bootloader/touch1200.py +45 -0
  8. mpflash/mpflash/cli_download.py +1 -0
  9. mpflash/mpflash/cli_flash.py +16 -9
  10. mpflash/mpflash/cli_group.py +10 -4
  11. mpflash/mpflash/cli_list.py +6 -2
  12. mpflash/mpflash/cli_main.py +5 -2
  13. mpflash/mpflash/common.py +14 -1
  14. mpflash/mpflash/config.py +17 -1
  15. mpflash/mpflash/download.py +2 -3
  16. mpflash/mpflash/downloaded.py +3 -3
  17. mpflash/mpflash/errors.py +5 -1
  18. mpflash/mpflash/flash.py +10 -27
  19. mpflash/mpflash/flash_uf2_macos.py +0 -3
  20. mpflash/mpflash/vendor/click_aliases.py +91 -0
  21. mpflash/poetry.lock +102 -137
  22. mpflash/pyproject.toml +1 -1
  23. stubber/__init__.py +1 -1
  24. stubber/board/createstubs.py +3 -4
  25. stubber/board/createstubs_db.py +4 -5
  26. stubber/board/createstubs_db_min.py +1 -1
  27. stubber/board/createstubs_db_mpy.mpy +0 -0
  28. stubber/board/createstubs_mem.py +4 -5
  29. stubber/board/createstubs_mem_min.py +1 -1
  30. stubber/board/createstubs_mem_mpy.mpy +0 -0
  31. stubber/board/createstubs_min.py +1 -1
  32. stubber/board/createstubs_mpy.mpy +0 -0
  33. stubber/bulk/mcu_stubber.py +0 -1
  34. stubber/codemod/_partials/__init__.py +0 -2
  35. stubber/publish/candidates.py +7 -28
  36. stubber/publish/enums.py +0 -6
  37. stubber/publish/package.py +15 -46
  38. stubber/publish/publish.py +1 -2
  39. stubber/rst/lookup.py +7 -7
  40. stubber/rst/reader.py +26 -27
  41. stubber/update_module_list.py +0 -2
  42. {micropython_stubber-1.20.4.dist-info → micropython_stubber-1.20.5.dist-info}/LICENSE +0 -0
  43. {micropython_stubber-1.20.4.dist-info → micropython_stubber-1.20.5.dist-info}/WHEEL +0 -0
  44. {micropython_stubber-1.20.4.dist-info → micropython_stubber-1.20.5.dist-info}/entry_points.txt +0 -0
@@ -20,7 +20,8 @@ from packaging.version import parse
20
20
  import stubber.basicgit as git
21
21
  from stubber import utils
22
22
  from stubber.publish.defaults import GENERIC, GENERIC_L, GENERIC_U
23
- from stubber.publish.enums import COMBO_STUBS, DOC_STUBS, FIRMWARE_STUBS
23
+
24
+ # from stubber.publish.enums import COMBO_STUBS
24
25
  from stubber.utils.config import CONFIG
25
26
  from stubber.utils.versions import OLDEST_VERSION, SET_PREVIEW, V_PREVIEW, clean_version, micropython_versions
26
27
 
@@ -139,7 +140,7 @@ def frozen_candidates(
139
140
  "version": version,
140
141
  "port": port,
141
142
  "board": GENERIC_L,
142
- "pkg_type": COMBO_STUBS,
143
+ # "pkg_type": COMBO_STUBS,
143
144
  }
144
145
  # if not auto_board:
145
146
  # for board in boards:
@@ -177,7 +178,7 @@ def frozen_candidates(
177
178
  "version": version,
178
179
  "port": port,
179
180
  "board": board,
180
- "pkg_type": COMBO_STUBS,
181
+ # "pkg_type": COMBO_STUBS,
181
182
  }
182
183
 
183
184
 
@@ -189,33 +190,11 @@ def is_auto(thing: Union[None, str, List[str]]):
189
190
  return any(i in ["auto", "all"] for i in thing)
190
191
 
191
192
 
192
- def docstub_candidates(
193
- family: str = "micropython",
194
- versions: Union[str, List[str]] = V_PREVIEW,
195
- path: Path = CONFIG.stub_path,
196
- ):
197
- """
198
- Generate a list of possible documentation stub candidates for the given family and version.
199
-
200
- Note that the folders do not need to exist, with the exception of auto which will scan the stubs folder for versions of docstubs
201
- """
202
- if isinstance(versions, str):
203
- if is_auto(versions): # auto with vprefix ...
204
- versions = list(version_candidates(suffix="docstubs", prefix=family, path=path))
205
- else:
206
- versions = [versions]
207
- versions = [clean_version(v, flat=True) for v in versions]
208
-
209
- for version in versions:
210
- yield {"family": family, "version": version, "pkg_type": DOC_STUBS}
211
-
212
-
213
193
  def board_candidates(
214
194
  family: str = "micropython",
215
195
  versions: Union[str, List[str]] = V_PREVIEW,
216
196
  *,
217
197
  mpy_path: Path = CONFIG.mpy_path,
218
- pt: str = FIRMWARE_STUBS,
219
198
  ):
220
199
  """
221
200
  generate a list of possible board stub candidates for the given family and version.
@@ -236,7 +215,9 @@ def board_candidates(
236
215
  else:
237
216
  r = git.checkout_tag(repo=mpy_path, tag=version)
238
217
  if not r:
239
- log.warning(f"Incorrect version: {version} or did you forget to run `stubber clone` to get the micropython repo?")
218
+ log.warning(
219
+ f"Incorrect version: {version} or did you forget to run `stubber clone` to get the micropython repo?"
220
+ )
240
221
  return []
241
222
  ports = list_micropython_ports(family=family, mpy_path=mpy_path)
242
223
  for port in ports:
@@ -246,7 +227,6 @@ def board_candidates(
246
227
  "version": version,
247
228
  "port": port,
248
229
  "board": GENERIC_U,
249
- "pkg_type": pt,
250
230
  }
251
231
  for board in list_micropython_port_boards(family=family, mpy_path=mpy_path, port=port):
252
232
  if board not in GENERIC:
@@ -255,7 +235,6 @@ def board_candidates(
255
235
  "version": version,
256
236
  "port": port,
257
237
  "board": board,
258
- "pkg_type": pt,
259
238
  }
260
239
 
261
240
 
stubber/publish/enums.py CHANGED
@@ -22,9 +22,3 @@ class StubSource(str, Enum):
22
22
  # Always force string values
23
23
  return self.value
24
24
 
25
-
26
- ALL_TYPES = ["combo", "doc", "core", "firmware"]
27
- COMBO_STUBS = ALL_TYPES[0]
28
- DOC_STUBS = ALL_TYPES[1]
29
- CORE_STUBS = ALL_TYPES[2]
30
- FIRMWARE_STUBS = ALL_TYPES[3]
@@ -2,6 +2,7 @@
2
2
  prepare a set of stub files for publishing to PyPi
3
3
 
4
4
  """
5
+
5
6
  import sys
6
7
  from pathlib import Path
7
8
  from typing import Dict, Union
@@ -11,7 +12,7 @@ from packaging.version import parse
11
12
  from pysondb import PysonDB
12
13
 
13
14
  from stubber.publish.defaults import GENERIC, GENERIC_L, default_board
14
- from stubber.publish.enums import COMBO_STUBS, CORE_STUBS, DOC_STUBS, StubSource
15
+ from stubber.publish.enums import StubSource
15
16
  from stubber.publish.stubpackage import StubPackage, StubSources
16
17
  from stubber.utils.config import CONFIG
17
18
  from stubber.utils.versions import clean_version
@@ -21,27 +22,12 @@ log.remove()
21
22
  log.add(sys.stderr, level="INFO", backtrace=True, diagnose=True)
22
23
 
23
24
 
24
- def package_name(
25
- pkg_type: str, *, port: str = "", board: str = "", family: str = "micropython", **kwargs
26
- ) -> str:
25
+ def package_name(*, port: str = "", board: str = "", family: str = "micropython", **kwargs) -> str:
27
26
  "generate a package name for the given package type"
28
- if pkg_type == COMBO_STUBS:
29
- # # {family}-{port}-{board}-stubs
30
- name = f"{family}-{port}-{board}-stubs".lower()
31
- name = name.replace("-generic-stubs", "-stubs")
32
- # Use explicit generic_ names for the stubs
33
- # name = name.replace("-generic_", "-") # @GENERIC Prefix
34
- return name
35
- elif pkg_type == DOC_STUBS:
36
- return f"{family}-doc-stubs".lower()
37
- elif pkg_type == CORE_STUBS:
38
- return f"{family}-core-stubs".lower()
39
- # # {family}-{port}-{board}-{type}-stubs
40
- name = f"{family}-{port}-{board}-{pkg_type}-stubs".lower()
27
+ # # {family}-{port}[-{board}[-{variant}]]-stubs
28
+ name = f"{family}-{port}-{board}-stubs".lower()
29
+ name = name.replace("-generic-stubs", "-stubs")
41
30
  # Use explicit generic_ names for the stubs
42
- # # remove -generic- from the name
43
- # name = name.replace(f"-generic-{pkg_type}-stubs", f"-{pkg_type}-stubs")
44
- # # remove -genetic_ from the name
45
31
  # name = name.replace("-generic_", "-") # @GENERIC Prefix
46
32
  return name
47
33
 
@@ -49,14 +35,13 @@ def package_name(
49
35
  def get_package(
50
36
  db: PysonDB,
51
37
  *,
52
- pkg_type: str,
53
38
  version: str,
54
39
  port: str,
55
40
  board: str = GENERIC_L,
56
41
  family: str = "micropython",
57
42
  ) -> StubPackage:
58
43
  """Get the package from the database or create a new one if it does not exist."""
59
- pkg_name = package_name(pkg_type, port=port, board=board, family=family)
44
+ pkg_name = package_name(port=port, board=board, family=family)
60
45
  version = clean_version(version, drop_v=True)
61
46
  if package_info := get_package_info(
62
47
  db,
@@ -74,13 +59,10 @@ def get_package(
74
59
  port=port,
75
60
  board=board,
76
61
  family=family,
77
- pkg_type=pkg_type,
78
62
  )
79
63
 
80
64
 
81
- def get_package_info(
82
- db: PysonDB, pub_path: Path, *, pkg_name: str, mpy_version: str
83
- ) -> Union[Dict, None]:
65
+ def get_package_info(db: PysonDB, pub_path: Path, *, pkg_name: str, mpy_version: str) -> Union[Dict, None]:
84
66
  """
85
67
  get a package's record from the json db if it can be found
86
68
  matches om the package name and version
@@ -88,9 +70,7 @@ def get_package_info(
88
70
  mpy_version: micropython/firmware version (1.18)
89
71
  """
90
72
  # find in the database
91
- recs = db.get_by_query(
92
- query=lambda x: x["mpy_version"] == mpy_version and x["name"] == pkg_name
93
- )
73
+ recs = db.get_by_query(query=lambda x: x["mpy_version"] == mpy_version and x["name"] == pkg_name)
94
74
  # dict to list
95
75
  recs = [{"id": key, "data": recs[key]} for key in recs]
96
76
  # sort
@@ -108,32 +88,21 @@ def create_package(
108
88
  pkg_name: str,
109
89
  mpy_version: str,
110
90
  *,
111
- port: str = "",
91
+ port: str,
112
92
  board: str = "",
113
93
  family: str = "micropython",
114
- pkg_type: str = COMBO_STUBS,
94
+ # pkg_type: str = COMBO_STUBS,
115
95
  ) -> StubPackage: # sourcery skip: merge-duplicate-blocks, remove-redundant-if
116
96
  """
117
97
  create and initialize a package with the correct sources
118
98
  """
119
99
  ver_flat = clean_version(mpy_version, flat=True)
120
100
  stubs: StubSources = []
121
- if pkg_type == COMBO_STUBS:
122
- assert port != "", "port must be specified for combo stubs"
123
- stubs = combo_sources(family, port, board, ver_flat)
124
- elif pkg_type == DOC_STUBS:
125
- stubs = [
126
- (
127
- StubSource.DOC,
128
- Path(f"{family}-{ver_flat}-docstubs"),
129
- ),
130
- ]
131
- elif pkg_type == CORE_STUBS:
132
- # TODO add core stubs
133
- raise NotImplementedError(type)
134
- else:
135
- raise NotImplementedError(type)
101
+ # if pkg_type != COMBO_STUBS:
102
+ # raise ValueError("Not Supported")
136
103
 
104
+ assert port != "", "port must be specified for combo stubs"
105
+ stubs = combo_sources(family, port, board, ver_flat)
137
106
  return StubPackage(pkg_name, port=port, board=board, version=mpy_version, stubs=stubs)
138
107
 
139
108
 
@@ -11,7 +11,6 @@ from loguru import logger as log
11
11
  from stubber.publish.candidates import board_candidates, filter_list
12
12
  from stubber.publish.database import get_database
13
13
  from stubber.publish.defaults import GENERIC_U
14
- from stubber.publish.enums import COMBO_STUBS
15
14
  from stubber.publish.package import get_package
16
15
  from stubber.utils.config import CONFIG
17
16
  from stubber.utils.versions import V_PREVIEW
@@ -110,7 +109,7 @@ def build_worklist(
110
109
  if family != "micropython":
111
110
  return []
112
111
  # get all the candidates
113
- worklist = list(board_candidates(family=family, versions=versions, pt=COMBO_STUBS))
112
+ worklist = list(board_candidates(family=family, versions=versions))
114
113
  worklist = filter_list(worklist, ports, boards)
115
114
 
116
115
  for b in boards:
stubber/rst/lookup.py CHANGED
@@ -254,7 +254,7 @@ PARAM_FIXES = [
254
254
  Fix("\\*", "*"), # change weirdly written wildcards \* --> *
255
255
  Fix(r"\**", "*"), # change weirdly written wildcards \* --> *
256
256
  Fix(r"/*", "*"), # change weirdly written wildcards \* --> *
257
- # ("**", "*"), # change weirdly written wildcards \* --> *
257
+ Fix(r"/)", ")"), # strange terminator in machine.USBDevice `USBDevice.active(self, [value] /)`
258
258
  Fix("'param'", "param"), # loose notation in documentation
259
259
  # illegal keywords
260
260
  Fix(
@@ -484,17 +484,17 @@ PARAM_FIXES = [
484
484
  # List of classes and their parent classes that should be added to the class definition
485
485
  CHILD_PARENT_CLASS = {
486
486
  # machine
487
- # SoftSPI is defined before SPI, so baseclass is not yet available - but in a .pyi that is OK
488
- "SoftSPI": "SPI",
487
+ # SoftSPI is defined before SPI, so baseclass is not yet available - but in a .pyi that is OK
488
+ "SoftSPI": "SPI",
489
489
  "SoftI2C": "I2C",
490
490
  "Switch": "Pin",
491
491
  "Signal": "Pin",
492
492
  # uio # unclear regarding deprecation in python 3.12
493
493
  # "IOBase": "IO", # 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
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
498
  "BufferedWriter": "IOBase", # DOCME: not in documentation # "BufferedWriter": "BufferedIOBase", # based on Stdlib
499
499
  # uzlib
500
500
  # "DecompIO": "IO", # https://docs.python.org/3/library/typing.html#other-concrete-types
stubber/rst/reader.py CHANGED
@@ -63,7 +63,6 @@ Note: black on python 3.7 does not like some function defs
63
63
 
64
64
  """
65
65
 
66
-
67
66
  import re
68
67
  from pathlib import Path
69
68
  from typing import List, Optional, Tuple
@@ -150,11 +149,7 @@ class FileReadWriter:
150
149
  """
151
150
  append = 0
152
151
  newline = self.rst_text[self.line_no]
153
- while (
154
- not self.is_balanced(newline)
155
- and self.line_no >= 0
156
- and (self.line_no + append + 1) <= self.max_line
157
- ):
152
+ while not self.is_balanced(newline) and self.line_no >= 0 and (self.line_no + append + 1) <= self.max_line:
158
153
  append += 1
159
154
  # concat the lines
160
155
  newline += self.rst_text[self.line_no + append]
@@ -225,9 +220,7 @@ class RSTReader(FileReadWriter):
225
220
  "stop at heading"
226
221
  u_line = self.rst_text[min(self.line_no + 1, self.max_line - 1)].rstrip()
227
222
  # Heading ---, ==, ~~~
228
- underlined = (
229
- u_line.startswith("---") or u_line.startswith("===") or u_line.startswith("~~~")
230
- )
223
+ underlined = u_line.startswith("---") or u_line.startswith("===") or u_line.startswith("~~~")
231
224
  if underlined and self.line_no > 0:
232
225
  # check if previous line is a heading
233
226
  line = self.rst_text[self.line_no].strip()
@@ -374,12 +367,8 @@ class RSTParser(RSTReader):
374
367
  target = ".py" # py/pyi
375
368
  # TODO: Move to lookup.py
376
369
  PARAM_RE_FIXES = [
377
- Fix(
378
- r"\[angle, time=0\]", "[angle], time=0", is_re=True
379
- ), # fix: method:: Servo.angle([angle, time=0])
380
- Fix(
381
- r"\[speed, time=0\]", "[speed], time=0", is_re=True
382
- ), # fix: .. method:: Servo.speed([speed, time=0])
370
+ Fix(r"\[angle, time=0\]", "[angle], time=0", is_re=True), # fix: method:: Servo.angle([angle, time=0])
371
+ Fix(r"\[speed, time=0\]", "[speed], time=0", is_re=True), # fix: .. method:: Servo.speed([speed, time=0])
383
372
  Fix(
384
373
  r"\[service_id, key=None, \*, \.\.\.\]", "[service_id], [key], *, ...", is_re=True
385
374
  ), # fix: network - AbstractNIC.connect
@@ -446,9 +435,7 @@ class RSTParser(RSTReader):
446
435
  def apply_fix(fix: Fix, params: str, name: str = ""):
447
436
  if fix.name and fix.name != name:
448
437
  return params
449
- return (
450
- re.sub(fix.from_, fix.to, params) if fix.is_re else params.replace(fix.from_, fix.to)
451
- )
438
+ return re.sub(fix.from_, fix.to, params) if fix.is_re else params.replace(fix.from_, fix.to)
452
439
 
453
440
  def create_update_class(self, name: str, params: str, docstr: List[str]):
454
441
  # a bit of a hack: assume no classes in classes or functions in function
@@ -509,12 +496,10 @@ class RSTParser(RSTReader):
509
496
  if "nightly" in self.source_tag:
510
497
  version = V_PREVIEW
511
498
  else:
512
- version = self.source_tag.replace(
513
- "_", "."
514
- ) # TODO Use clean_version(self.source_tag)
515
- docstr[
516
- 0
517
- ] = f"{docstr[0]}.\n\nMicroPython module: https://docs.micropython.org/en/{version}/library/{module_name}.html"
499
+ 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
+ )
518
503
 
519
504
  self.output_dict.name = module_name
520
505
  self.output_dict.add_comment(f"# source version: {self.source_tag}")
@@ -546,9 +531,7 @@ class RSTParser(RSTReader):
546
531
 
547
532
  for this_function in function_names:
548
533
  # Parse return type from docstring
549
- ret_type = return_type_from_context(
550
- docstring=docstr, signature=this_function, module=self.current_module
551
- )
534
+ ret_type = return_type_from_context(docstring=docstr, signature=this_function, module=self.current_module)
552
535
 
553
536
  # defaults
554
537
  name = params = ""
@@ -663,6 +646,8 @@ class RSTParser(RSTReader):
663
646
  # - staticmethod ( <params>) -> <ret_type>:
664
647
  # - all other methods (self, <params>) -> <ret_type>:
665
648
  if name == "__init__":
649
+ # avoid params starting with `self ,`
650
+ params = self.lstrip_self(params)
666
651
  method = FunctionSourceDict(
667
652
  name=f"def {name}",
668
653
  indent=parent_class.indent + 4,
@@ -688,6 +673,8 @@ class RSTParser(RSTReader):
688
673
  is_async=is_async,
689
674
  )
690
675
  else: # just plain method
676
+ # avoid params starting with `self ,`
677
+ params = self.lstrip_self(params)
691
678
  method = FunctionSourceDict(
692
679
  name=f"def {name}",
693
680
  indent=parent_class.indent + 4,
@@ -695,8 +682,20 @@ class RSTParser(RSTReader):
695
682
  docstr=docstr,
696
683
  is_async=is_async,
697
684
  )
685
+
698
686
  parent_class += method
699
687
 
688
+ def lstrip_self(self, params):
689
+ """
690
+ To avoid duplicate selfs,
691
+ Remove `self,` from the start of the parameters
692
+ """
693
+ if params.startswith("self,"):
694
+ params = params[6:]
695
+ elif params.startswith("self ,"):
696
+ params = params[7:]
697
+ return params
698
+
700
699
  def parse_exception(self):
701
700
  log.trace(f"# {self.line.rstrip()}")
702
701
  name = self.line.split(SEPERATOR)[1].strip()
@@ -10,8 +10,6 @@ for this :
10
10
  - write updates to:
11
11
  - board/modulelist.txt
12
12
  - board/createstubs.py
13
-
14
- - TODO: remove the frozen modules from this list
15
13
  """
16
14
 
17
15
  from pathlib import Path