micropython-stubber 1.14.1__py3-none-any.whl → 1.15.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 (50) hide show
  1. micropython_stubber-1.15.1.dist-info/METADATA +244 -0
  2. {micropython_stubber-1.14.1.dist-info → micropython_stubber-1.15.1.dist-info}/RECORD +49 -46
  3. stubber/__init__.py +1 -1
  4. stubber/basicgit.py +27 -14
  5. stubber/board/createstubs.py +34 -36
  6. stubber/board/createstubs_db.py +35 -35
  7. stubber/board/createstubs_db_min.py +195 -193
  8. stubber/board/createstubs_db_mpy.mpy +0 -0
  9. stubber/board/createstubs_info.py +73 -42
  10. stubber/board/createstubs_lvgl.py +35 -35
  11. stubber/board/createstubs_lvgl_min.py +88 -87
  12. stubber/board/createstubs_lvgl_mpy.mpy +0 -0
  13. stubber/board/createstubs_mem.py +44 -40
  14. stubber/board/createstubs_mem_min.py +179 -174
  15. stubber/board/createstubs_mem_mpy.mpy +0 -0
  16. stubber/board/createstubs_min.py +75 -74
  17. stubber/board/createstubs_mpy.mpy +0 -0
  18. stubber/board/info.py +183 -0
  19. stubber/codemod/enrich.py +28 -16
  20. stubber/commands/build_cmd.py +3 -3
  21. stubber/commands/get_core_cmd.py +17 -5
  22. stubber/commands/get_docstubs_cmd.py +23 -8
  23. stubber/commands/get_frozen_cmd.py +62 -9
  24. stubber/commands/get_lobo_cmd.py +13 -3
  25. stubber/commands/merge_cmd.py +7 -4
  26. stubber/commands/publish_cmd.py +5 -4
  27. stubber/commands/stub_cmd.py +2 -1
  28. stubber/commands/variants_cmd.py +0 -1
  29. stubber/freeze/common.py +2 -2
  30. stubber/freeze/freeze_folder.py +1 -1
  31. stubber/freeze/get_frozen.py +1 -1
  32. stubber/minify.py +43 -28
  33. stubber/publish/bump.py +1 -1
  34. stubber/publish/candidates.py +61 -17
  35. stubber/publish/defaults.py +44 -0
  36. stubber/publish/merge_docstubs.py +19 -56
  37. stubber/publish/package.py +44 -37
  38. stubber/publish/pathnames.py +51 -0
  39. stubber/publish/publish.py +5 -4
  40. stubber/publish/stubpacker.py +55 -33
  41. stubber/rst/lookup.py +7 -16
  42. stubber/rst/reader.py +39 -8
  43. stubber/stubs_from_docs.py +5 -8
  44. stubber/utils/post.py +34 -40
  45. stubber/utils/repos.py +32 -17
  46. stubber/utils/stubmaker.py +22 -14
  47. micropython_stubber-1.14.1.dist-info/METADATA +0 -217
  48. {micropython_stubber-1.14.1.dist-info → micropython_stubber-1.15.1.dist-info}/LICENSE +0 -0
  49. {micropython_stubber-1.14.1.dist-info → micropython_stubber-1.15.1.dist-info}/WHEEL +0 -0
  50. {micropython_stubber-1.14.1.dist-info → micropython_stubber-1.15.1.dist-info}/entry_points.txt +0 -0
@@ -19,7 +19,7 @@ from packaging.version import parse
19
19
 
20
20
  import stubber.basicgit as git
21
21
  from stubber.publish.enums import COMBO_STUBS, DOC_STUBS, FIRMWARE_STUBS
22
- from stubber.publish.package import GENERIC, GENERIC_L, GENERIC_U
22
+ from stubber.publish.defaults import GENERIC, GENERIC_L, GENERIC_U
23
23
  from stubber.utils.config import CONFIG
24
24
  from stubber.utils.versions import clean_version, micropython_versions
25
25
 
@@ -38,7 +38,11 @@ def subfolder_names(path: Path):
38
38
 
39
39
 
40
40
  def version_candidates(
41
- suffix: str, prefix: str = r".*", *, path: Path = CONFIG.stub_path, oldest: str = OLDEST_VERSION
41
+ suffix: str,
42
+ prefix: str = r".*",
43
+ *,
44
+ path: Path = CONFIG.stub_path,
45
+ oldest: str = OLDEST_VERSION,
42
46
  ) -> Generator[str, None, None]:
43
47
  "get a list of versions for the given family and suffix"
44
48
  if path.exists():
@@ -91,8 +95,8 @@ def list_micropython_port_boards(
91
95
  def frozen_candidates(
92
96
  family: str = "micropython",
93
97
  versions: Union[str, List[str]] = V_LATEST,
94
- ports: Union[str, List[str]] = "auto",
95
- boards: Union[str, List[str]] = "auto",
98
+ ports: Union[str, List[str]] = "all",
99
+ boards: Union[str, List[str]] = "all",
96
100
  *,
97
101
  path: Path = CONFIG.stub_path,
98
102
  ) -> Generator[Dict[str, Any], None, None]:
@@ -125,7 +129,9 @@ def frozen_candidates(
125
129
  # lookup the (frozen) micropython ports
126
130
  ports = list_frozen_ports(family, version, path=path)
127
131
  else:
128
- raise NotImplementedError(f"auto ports not implemented for family {family}") # pragma: no cover
132
+ raise NotImplementedError(
133
+ f"auto ports not implemented for family {family}"
134
+ ) # pragma: no cover
129
135
  # elif family == "pycom":
130
136
  # ports = ["esp32"]
131
137
  # elif family == "lobo":
@@ -134,7 +140,13 @@ def frozen_candidates(
134
140
  for port in ports:
135
141
  port_path = path / f"{family}-{version}-frozen" / port
136
142
  if port_path.exists():
137
- yield {"family": family, "version": version, "port": port, "board": GENERIC_L, "pkg_type": COMBO_STUBS}
143
+ yield {
144
+ "family": family,
145
+ "version": version,
146
+ "port": port,
147
+ "board": GENERIC_L,
148
+ "pkg_type": COMBO_STUBS,
149
+ }
138
150
  # if not auto_board:
139
151
  # for board in boards:
140
152
  # port_path = board_path/ "board" / board
@@ -152,7 +164,9 @@ def frozen_candidates(
152
164
 
153
165
  else:
154
166
  # raise NotImplementedError(f"auto boards not implemented for family {family}") # pragma: no cover
155
- 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
156
170
  # elif family == "pycom":
157
171
  # boards = ["wipy", "lopy", "gpy", "fipy"]
158
172
  # ---------------------------------------------------------------------------
@@ -166,12 +180,21 @@ def frozen_candidates(
166
180
  "RELEASE",
167
181
  "GENERIC_512K",
168
182
  ]:
169
- yield {"family": family, "version": version, "port": port, "board": board, "pkg_type": COMBO_STUBS}
183
+ yield {
184
+ "family": family,
185
+ "version": version,
186
+ "port": port,
187
+ "board": board,
188
+ "pkg_type": COMBO_STUBS,
189
+ }
170
190
 
171
191
 
172
192
  def is_auto(thing: Union[None, str, List[str]]):
173
193
  "Is this version/port/board specified as 'auto' ?"
174
- return isinstance(thing, str) and thing == "auto" or isinstance(thing, list) and "auto" in thing
194
+ if isinstance(thing, str):
195
+ return thing in ["auto", "all"]
196
+ if isinstance(thing, list):
197
+ return any(i in ["auto", "all"] for i in thing)
175
198
 
176
199
 
177
200
  def docstub_candidates(
@@ -182,10 +205,10 @@ def docstub_candidates(
182
205
  """
183
206
  Generate a list of possible documentation stub candidates for the given family and version.
184
207
 
185
- Note that the folders do not need to exist, with the exeption of auto which will scan the stubs folder for versions of docstubs
208
+ Note that the folders do not need to exist, with the exception of auto which will scan the stubs folder for versions of docstubs
186
209
  """
187
210
  if isinstance(versions, str):
188
- if versions == "auto": # auto with vprefix ...
211
+ if is_auto(versions): # auto with vprefix ...
189
212
  versions = list(version_candidates(suffix="docstubs", prefix=family, path=path))
190
213
  else:
191
214
  versions = [versions]
@@ -196,7 +219,11 @@ def docstub_candidates(
196
219
 
197
220
 
198
221
  def board_candidates(
199
- family: str = "micropython", versions: Union[str, List[str]] = V_LATEST, *, mpy_path: Path = CONFIG.mpy_path, pt: str = FIRMWARE_STUBS
222
+ family: str = "micropython",
223
+ versions: Union[str, List[str]] = V_LATEST,
224
+ *,
225
+ mpy_path: Path = CONFIG.mpy_path,
226
+ pt: str = FIRMWARE_STUBS,
200
227
  ):
201
228
  """
202
229
  generate a list of possible board stub candidates for the given family and version.
@@ -209,7 +236,7 @@ def board_candidates(
209
236
  versions = [clean_version(v, flat=False) for v in versions]
210
237
 
211
238
  for version in versions:
212
- # check out the micropthon repo for this version
239
+ # check out the micropython repo for this version
213
240
  if version in ["latest", "master"]:
214
241
  r = git.switch_branch(repo=mpy_path, branch="master")
215
242
  else:
@@ -219,10 +246,22 @@ def board_candidates(
219
246
  ports = list_micropython_ports(family=family, mpy_path=mpy_path)
220
247
  for port in ports:
221
248
  # Yield the generic port exactly one time
222
- yield {"family": family, "version": version, "port": port, "board": GENERIC_U, "pkg_type": pt}
249
+ yield {
250
+ "family": family,
251
+ "version": version,
252
+ "port": port,
253
+ "board": GENERIC_U,
254
+ "pkg_type": pt,
255
+ }
223
256
  for board in list_micropython_port_boards(family=family, mpy_path=mpy_path, port=port):
224
257
  if board not in GENERIC:
225
- yield {"family": family, "version": version, "port": port, "board": board, "pkg_type": pt}
258
+ yield {
259
+ "family": family,
260
+ "version": version,
261
+ "port": port,
262
+ "board": board,
263
+ "pkg_type": pt,
264
+ }
226
265
 
227
266
 
228
267
  def filter_list(
@@ -232,7 +271,7 @@ def filter_list(
232
271
  # versions: Optional[Union[List[str], str]] = None,
233
272
  ):
234
273
  """
235
- filter a list of candidates down to the ones we want, based on the ports and boars specified (case insensitive)
274
+ filter a list of candidates down to the ones we want, based on the ports and boards specified (case insensitive)
236
275
  for board also match using a 'GENERIC_' prefix, so board 's3' will match candidate 'GENERIC_S3'
237
276
  """
238
277
  worklist = [i for i in worklist if i["board"] != ""]
@@ -241,5 +280,10 @@ def filter_list(
241
280
  worklist = [i for i in worklist if i["port"].lower() in ports_]
242
281
  if boards and not is_auto(boards):
243
282
  boards_ = [i.lower() for i in boards]
244
- worklist = [i for i in worklist if i["board"].lower() in boards_ or i["board"].lower().replace("generic_", "") in boards_]
283
+ worklist = [
284
+ i
285
+ for i in worklist
286
+ if i["board"].lower() in boards_
287
+ or i["board"].lower().replace("generic_", "") in boards_
288
+ ]
245
289
  return worklist
@@ -0,0 +1,44 @@
1
+ """Build and packaging defaults for stubber"""
2
+ from typing import Dict, List
3
+ from stubber.utils.config import CONFIG
4
+ from stubber.utils.versions import clean_version
5
+
6
+ # The default board for the ports modules documented with base name only
7
+ # as the MicroPython BOARD naming convention has changed over time there are different options to try
8
+ # (newer to older)
9
+
10
+ DEFAULT_BOARDS: Dict[str, List[str]] = {
11
+ "stm32": ["PYBV11", ""],
12
+ "esp32": ["ESP32_GENERIC", "GENERIC", ""], # "GENERIC_SPIRAM",
13
+ "esp8266": ["ESP8266_GENERIC", "GENERIC", ""],
14
+ "rp2": ["RPI_PICO", "PICO", ""],
15
+ "samd": ["SEEED_WIO_TERMINAL", ""],
16
+ }
17
+
18
+ GENERIC_L = "generic"
19
+ "generic lowercase"
20
+ GENERIC_U = "GENERIC"
21
+ "GENERIC uppercase"
22
+ GENERIC = {GENERIC_L, GENERIC_U}
23
+ "GENERIC eithercase"
24
+
25
+
26
+ def default_board(port: str, version="latest") -> str: # sourcery skip: assign-if-exp
27
+ """Return the default board for the given version and port"""
28
+ ver_flat = clean_version(version, flat=True)
29
+ if port in DEFAULT_BOARDS:
30
+ for board in DEFAULT_BOARDS[port]:
31
+ base = (
32
+ f"micropython-{ver_flat}-{port}-{board}"
33
+ if board
34
+ else f"micropython-{ver_flat}-{port}"
35
+ )
36
+ # check if we have a (merged)stub for this version and port
37
+ if (CONFIG.stub_path / f"{base}-merged").exists() or (
38
+ CONFIG.stub_path / base
39
+ ).exists():
40
+ return board
41
+ # fallback to first listed board
42
+ return DEFAULT_BOARDS[port][0]
43
+ # fallback to generic
44
+ return GENERIC_U
@@ -4,45 +4,16 @@ Merge firmware stubs and docstubs into a single folder
4
4
 
5
5
  import shutil
6
6
  from pathlib import Path
7
- from typing import Dict, List, Optional, Union
7
+ from typing import List, Optional, Union
8
8
 
9
9
  from loguru import logger as log
10
10
 
11
11
  from stubber.codemod.enrich import enrich_folder
12
12
  from stubber.publish.candidates import board_candidates, filter_list
13
+ from stubber.publish.defaults import GENERIC, GENERIC_L, default_board
13
14
  from stubber.publish.missing_class_methods import add_machine_pin_call
14
- from stubber.publish.package import GENERIC, GENERIC_L
15
+ from stubber.publish.pathnames import get_base, get_board_path, get_merged_path
15
16
  from stubber.utils.config import CONFIG
16
- from stubber.utils.versions import clean_version
17
-
18
- ## Helper function
19
-
20
-
21
- def get_base(candidate: Dict[str, str], version: Optional[str] = None):
22
- if not version:
23
- version = clean_version(candidate["version"], flat=True)
24
- base = f"{candidate['family']}-{version}"
25
- return base.lower()
26
-
27
-
28
- def board_folder_name(fw: Dict, *, version: Optional[str] = None):
29
- """Return the name of the firmware folder. Can be in AnyCase."""
30
- base = get_base(fw, version=version)
31
- folder_name = (
32
- f"{base}-{fw['port']}" if fw["board"] in GENERIC else f"{base}-{fw['port']}-{fw['board']}"
33
- )
34
- # do NOT force name to lowercase
35
- # remove GENERIC Prefix
36
- folder_name = folder_name.replace("-generic_", "-").replace("-GENERIC_", "-")
37
- return folder_name
38
-
39
-
40
- def get_board_path(fw: Dict):
41
- return CONFIG.stub_path / board_folder_name(fw)
42
-
43
-
44
- def get_merged_path(fw: Dict):
45
- return CONFIG.stub_path / (board_folder_name(fw) + "-merged")
46
17
 
47
18
 
48
19
  def merge_all_docstubs(
@@ -57,7 +28,7 @@ def merge_all_docstubs(
57
28
  if versions is None:
58
29
  versions = [CONFIG.stable_version]
59
30
  if ports is None:
60
- ports = ["auto"]
31
+ ports = ["all"]
61
32
  if boards is None:
62
33
  boards = [GENERIC_L]
63
34
  if isinstance(versions, str):
@@ -69,40 +40,32 @@ def merge_all_docstubs(
69
40
 
70
41
  candidates = list(board_candidates(versions=versions, family=family))
71
42
  candidates = filter_list(candidates, ports, boards)
72
- log.info(f"checking {len(candidates)} possible board candidates")
73
-
74
- merged = 0
75
43
  if not candidates:
76
44
  log.error("No candidates found")
77
45
  return
46
+
47
+ log.info(f"checking {len(candidates)} possible board candidates")
48
+ merged = 0
78
49
  for candidate in candidates:
50
+ # use the default board for the port
51
+ if candidate["board"] in GENERIC:
52
+ candidate["board"] = default_board(
53
+ port=candidate["port"], version=candidate["version"]
54
+ )
79
55
  # check if we have board stubs of this version and port
80
56
  doc_path = CONFIG.stub_path / f"{get_base(candidate)}-docstubs"
81
- if not doc_path.exists():
82
- log.warning(f"No docstubs found for {candidate['version']}")
83
- continue
84
57
  # src and dest paths
85
58
  board_path = get_board_path(candidate)
86
59
  merged_path = get_merged_path(candidate)
87
60
 
61
+ # only continue if both folders exist
62
+ if not doc_path.exists():
63
+ log.warning(f"No docstubs found for {candidate['version']}")
64
+ continue
88
65
  if not board_path.exists():
89
- log.info(f"no firmware stubs found in {board_path}")
90
- if candidate["version"] == "latest":
91
- # for the latest we do a bit more effort to get something 'good enough'
92
- # try to get the board_path from the last released version as the basis
93
- board_path = CONFIG.stub_path / board_folder_name(candidate, version="latest")
94
- # check again
95
- if board_path.exists():
96
- log.info(f"using {board_path.name} as the basis for {merged_path.name}")
97
- else:
98
- # only continue if both folders exist
99
- log.debug(f"skipping {merged_path.name}, no firmware stubs found")
100
- continue
101
- else:
102
- # only continue if both folders exist
103
- log.debug(f"skipping {merged_path.name}, no firmware stubs found")
104
- continue
105
- log.info(f"Merge docstubs for {merged_path.name} {candidate['version']}")
66
+ log.info(f"skipping {merged_path.name}, no firmware stubs found in {board_path}")
67
+ continue
68
+ log.info(f"Merge {candidate['version']} docstubs with boardstubs to {merged_path.name}")
106
69
  result = copy_and_merge_docstubs(board_path, merged_path, doc_path)
107
70
  # Add methods from docstubs to the firmware stubs that do not exist in the firmware stubs
108
71
  # Add the __call__ method to the machine.Pin and pyb.Pin class
@@ -10,30 +10,27 @@ from loguru import logger as log
10
10
  from packaging.version import parse
11
11
  from pysondb import PysonDB
12
12
 
13
+ from stubber.publish.defaults import GENERIC, GENERIC_L, default_board
13
14
  from stubber.publish.enums import COMBO_STUBS, CORE_STUBS, DOC_STUBS, StubSource
14
15
  from stubber.publish.stubpacker import StubPackage, StubSources
15
16
  from stubber.utils.config import CONFIG
16
17
  from stubber.utils.versions import clean_version
17
18
 
18
- GENERIC_L = "generic"
19
- "generic lowercase"
20
- GENERIC_U = "GENERIC"
21
- "GENERIC uppercase"
22
- GENERIC = {GENERIC_L, GENERIC_U}
23
- "GENERIC eithercase"
24
-
25
19
  # replace std log handler with a custom one capped on INFO level
26
20
  log.remove()
27
21
  log.add(sys.stderr, level="INFO", backtrace=True, diagnose=True)
28
22
 
29
23
 
30
- def package_name(pkg_type: str, *, port: str = "", board: str = "", family: str = "micropython", **kwargs) -> str:
24
+ def package_name(
25
+ pkg_type: str, *, port: str = "", board: str = "", family: str = "micropython", **kwargs
26
+ ) -> str:
31
27
  "generate a package name for the given package type"
32
28
  if pkg_type == COMBO_STUBS:
33
29
  # # {family}-{port}-{board}-stubs
34
30
  name = f"{family}-{port}-{board}-stubs".lower()
35
31
  name = name.replace("-generic-stubs", "-stubs")
36
- name = name.replace("-generic_", "-") # @GENERIC Prefix
32
+ # Use explicit generic_ names for the stubs
33
+ # name = name.replace("-generic_", "-") # @GENERIC Prefix
37
34
  return name
38
35
  elif pkg_type == DOC_STUBS:
39
36
  return f"{family}-doc-stubs".lower()
@@ -41,10 +38,11 @@ def package_name(pkg_type: str, *, port: str = "", board: str = "", family: str
41
38
  return f"{family}-core-stubs".lower()
42
39
  # # {family}-{port}-{board}-{type}-stubs
43
40
  name = f"{family}-{port}-{board}-{pkg_type}-stubs".lower()
44
- # remove -generic- from the name
45
- name = name.replace(f"-generic-{pkg_type}-stubs", f"-{pkg_type}-stubs")
46
- # remove -genetic_ from the name
47
- name = name.replace("-generic_", "-") # @GENERIC Prefix
41
+ # 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
+ # name = name.replace("-generic_", "-") # @GENERIC Prefix
48
46
  return name
49
47
 
50
48
 
@@ -67,7 +65,7 @@ def get_package(
67
65
  mpy_version=version,
68
66
  ):
69
67
  # create package from the information retrieved from the database
70
- return StubPackage(pkg_name, version=version, json_data=package_info)
68
+ return StubPackage(pkg_name, port, board=board, version=version, json_data=package_info)
71
69
 
72
70
  log.debug(f"No package found for {pkg_name} in database, creating new package")
73
71
  return create_package(
@@ -80,7 +78,9 @@ def get_package(
80
78
  )
81
79
 
82
80
 
83
- def get_package_info(db: PysonDB, pub_path: Path, *, pkg_name: str, mpy_version: str) -> Union[Dict, None]:
81
+ def get_package_info(
82
+ db: PysonDB, pub_path: Path, *, pkg_name: str, mpy_version: str
83
+ ) -> Union[Dict, None]:
84
84
  """
85
85
  get a package's record from the json db if it can be found
86
86
  matches om the package name and version
@@ -88,7 +88,9 @@ def get_package_info(db: PysonDB, pub_path: Path, *, pkg_name: str, mpy_version:
88
88
  mpy_version: micropython/firmware version (1.18)
89
89
  """
90
90
  # find in the database
91
- recs = db.get_by_query(query=lambda x: x["mpy_version"] == mpy_version and x["name"] == pkg_name)
91
+ recs = db.get_by_query(
92
+ query=lambda x: x["mpy_version"] == mpy_version and x["name"] == pkg_name
93
+ )
92
94
  # dict to list
93
95
  recs = [{"id": key, "data": recs[key]} for key in recs]
94
96
  # sort
@@ -120,7 +122,7 @@ def create_package(
120
122
  assert port != "", "port must be specified for combo stubs"
121
123
  stubs = combo_sources(family, port, board, ver_flat)
122
124
  elif pkg_type == DOC_STUBS:
123
- stubs: StubSources = [
125
+ stubs = [
124
126
  (
125
127
  StubSource.DOC,
126
128
  Path(f"{family}-{ver_flat}-docstubs"),
@@ -132,14 +134,12 @@ def create_package(
132
134
  else:
133
135
  raise NotImplementedError(type)
134
136
 
135
- return StubPackage(pkg_name, version=mpy_version, stubs=stubs)
137
+ return StubPackage(pkg_name, port=port, board=board, version=mpy_version, stubs=stubs)
136
138
 
137
139
 
138
140
  def combo_sources(family: str, port: str, board: str, ver_flat: str) -> StubSources:
139
141
  """
140
142
  Build a source set for combo stubs
141
- -
142
-
143
143
  """
144
144
  # Use lower case for paths to avoid case sensitive issues
145
145
  port = port.lower()
@@ -149,22 +149,29 @@ def combo_sources(family: str, port: str, board: str, ver_flat: str) -> StubSour
149
149
  board_u = board_l.upper()
150
150
  board_l = board_l.replace("generic_", "") # @GENERIC Prefix
151
151
 
152
+ # StubSource.FIRMWARE,
153
+ # Path(f"{family}-{ver_flat}-{port}"),
154
+ # TODO: look for the most specific firmware stub folder that is available ?
155
+ # is it possible to prefer micropython-nrf-microbit-stubs over micropython-nrf-stubs
156
+ # that would also require the port - board - variant to be discoverable runtime
157
+
158
+ if board_l in GENERIC:
159
+ merged_path = Path(f"{family}-{ver_flat}-{port}-merged")
160
+ if not merged_path.exists():
161
+ board = default_board(port, ver_flat)
162
+ board_l = board.lower()
163
+ board_u = board
164
+ merged_path = Path(f"{family}-{ver_flat}-{port}-{board}-merged")
165
+ else:
166
+ merged_path = Path(f"{family}-{ver_flat}-{port}-{board}-merged")
167
+
168
+ # BOARD in source frozen path needs to be UPPERCASE
169
+ frozen_path = Path(f"{family}-{ver_flat}-frozen") / port / board_u.upper()
170
+ # TODO : Add version to core stubs
171
+ core_path = Path(f"{family}-core")
172
+
152
173
  return [
153
- (
154
- # StubSource.FIRMWARE,
155
- # Path(f"{family}-{ver_flat}-{port}"),
156
- # TODO: look for the most specific firmware stub folder that is available ?
157
- # is it possible to prefer micropython-nrf-microbit-stubs over micropython-nrf-stubs
158
- # that would also require the port - board - variant to be discoverable runtime
159
- StubSource.MERGED,
160
- Path(f"{family}-{ver_flat}-{port}-merged") if board_l in GENERIC else Path(f"{family}-{ver_flat}-{port}-{board_l}-merged"),
161
- ),
162
- (
163
- StubSource.FROZEN,
164
- Path(f"{family}-{ver_flat}-frozen") / port / board_u.upper(), # BOARD in source frozen path needs to be UPPERCASE
165
- ),
166
- (
167
- StubSource.CORE,
168
- Path(f"{family}-core"), # TODO : Add version to core stubs
169
- ),
174
+ (StubSource.MERGED, merged_path),
175
+ (StubSource.FROZEN, frozen_path),
176
+ (StubSource.CORE, core_path),
170
177
  ]
@@ -0,0 +1,51 @@
1
+ """
2
+ Helper functions to deal with path names and filenames for the folders in the stubs repo
3
+
4
+ """
5
+
6
+ from pathlib import Path
7
+ from typing import Dict, List, Optional
8
+
9
+ from loguru import logger as log
10
+
11
+ from stubber.publish.defaults import default_board
12
+ from stubber.publish.package import GENERIC
13
+ from stubber.utils.config import CONFIG
14
+ from stubber.utils.versions import clean_version
15
+
16
+
17
+ ## Helper functions
18
+ def get_base(candidate: Dict[str, str], version: Optional[str] = None):
19
+ if version:
20
+ version = clean_version(version, flat=True)
21
+ else:
22
+ version = clean_version(candidate["version"], flat=True)
23
+ base = f"{candidate['family']}-{version}"
24
+ return base.lower()
25
+
26
+
27
+ def board_folder_name(fw: Dict, *, version: Optional[str] = None) -> str:
28
+ """Return the name of the firmware folder. Can be in AnyCase."""
29
+ base = get_base(fw, version=version)
30
+ if fw["board"] in GENERIC:
31
+ board = default_board(fw["port"], fw["version"])
32
+ else:
33
+ board = fw["board"]
34
+ folder_name = f"{base}-{fw['port']}-{board}" if board else f"{base}-{fw['port']}"
35
+ # do NOT force name to lowercase
36
+ # remove GENERIC Prefix
37
+ # folder_name = folder_name.replace("-generic_", "-").replace("-GENERIC_", "-")
38
+ return folder_name
39
+
40
+
41
+ def get_board_path(candidate: Dict) -> Path:
42
+ board_path = CONFIG.stub_path / board_folder_name(candidate)
43
+ if candidate["version"] == "latest" and not board_path.exists():
44
+ log.debug(f"no board stubs found for {candidate['version']}, trying stable")
45
+ board_path = CONFIG.stub_path / board_folder_name(candidate, version=CONFIG.stable_version)
46
+
47
+ return board_path
48
+
49
+
50
+ def get_merged_path(fw: Dict) -> Path:
51
+ return CONFIG.stub_path / (board_folder_name(fw) + "-merged")
@@ -9,15 +9,16 @@ from loguru import logger as log
9
9
 
10
10
  from stubber.publish.candidates import board_candidates, filter_list
11
11
  from stubber.publish.database import get_database
12
+ from stubber.publish.defaults import GENERIC_U
12
13
  from stubber.publish.enums import COMBO_STUBS
13
- from stubber.publish.package import GENERIC_U, get_package
14
+ from stubber.publish.package import get_package
14
15
  from stubber.utils.config import CONFIG
15
16
 
16
17
 
17
18
  def build_multiple(
18
19
  family: str = "micropython",
19
20
  versions: List[str] = ["v1.19.1"],
20
- ports: List[str] = ["auto"],
21
+ ports: List[str] = ["all"],
21
22
  boards: List[str] = [GENERIC_U],
22
23
  production: bool = False,
23
24
  clean: bool = False,
@@ -46,7 +47,7 @@ def build_multiple(
46
47
  def publish_multiple(
47
48
  family: str = "micropython",
48
49
  versions: List[str] = ["v1.19.1"],
49
- ports: List[str] = ["auto"],
50
+ ports: List[str] = ["all"],
50
51
  boards: List[str] = [GENERIC_U],
51
52
  production: bool = False,
52
53
  clean: bool = False,
@@ -101,6 +102,6 @@ def build_worklist(
101
102
  worklist = filter_list(worklist, ports, boards)
102
103
 
103
104
  for b in boards:
104
- if not any(i for i in worklist if i["board"] == b):
105
+ if not any(i for i in worklist if i["board"].lower() == b.lower()):
105
106
  log.warning(f"Could not find any package candidate for board {b}")
106
107
  return worklist