micropython-stubber 1.23.1__py3-none-any.whl → 1.23.1.post1__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.
- {micropython_stubber-1.23.1.dist-info → micropython_stubber-1.23.1.post1.dist-info}/METADATA +30 -13
- {micropython_stubber-1.23.1.dist-info → micropython_stubber-1.23.1.post1.dist-info}/RECORD +60 -60
- micropython_stubber-1.23.1.post1.dist-info/entry_points.txt +5 -0
- mpflash/README.md +26 -0
- mpflash/mpflash/cli_download.py +1 -1
- mpflash/mpflash/cli_flash.py +11 -14
- mpflash/mpflash/cli_list.py +8 -2
- mpflash/mpflash/common.py +2 -1
- mpflash/mpflash/connected.py +2 -3
- mpflash/mpflash/list.py +20 -13
- mpflash/mpflash/mpremoteboard/__init__.py +50 -6
- mpflash/pyproject.toml +1 -1
- stubber/bulk/mcu_stubber.py +28 -45
- stubber/codemod/enrich.py +1 -1
- stubber/codemod/merge_docstub.py +1 -1
- stubber/commands/build_cmd.py +1 -1
- stubber/commands/cli.py +5 -11
- stubber/commands/clone_cmd.py +1 -1
- stubber/commands/config_cmd.py +1 -1
- stubber/commands/enrich_folder_cmd.py +1 -1
- stubber/commands/get_core_cmd.py +1 -1
- stubber/commands/get_docstubs_cmd.py +5 -2
- stubber/commands/get_frozen_cmd.py +5 -2
- stubber/commands/get_mcu_cmd.py +52 -11
- stubber/commands/merge_cmd.py +1 -1
- stubber/commands/publish_cmd.py +1 -1
- stubber/commands/stub_cmd.py +1 -1
- stubber/commands/variants_cmd.py +1 -1
- stubber/downloader.py +2 -1
- stubber/freeze/common.py +7 -3
- stubber/freeze/freeze_folder.py +2 -2
- stubber/freeze/freeze_manifest_2.py +19 -6
- stubber/freeze/get_frozen.py +7 -3
- stubber/get_cpython.py +15 -4
- stubber/minify.py +7 -3
- stubber/publish/candidates.py +26 -7
- stubber/publish/merge_docstubs.py +4 -2
- stubber/publish/missing_class_methods.py +4 -2
- stubber/publish/package.py +7 -3
- stubber/publish/pathnames.py +1 -1
- stubber/publish/publish.py +1 -1
- stubber/publish/pypi.py +6 -2
- stubber/publish/stubpackage.py +40 -16
- stubber/rst/classsort.py +2 -1
- stubber/rst/lookup.py +1 -0
- stubber/rst/reader.py +7 -7
- stubber/rst/report_return.py +12 -4
- stubber/rst/rst_utils.py +2 -1
- stubber/stubs_from_docs.py +1 -1
- stubber/tools/manifestfile.py +1 -1
- stubber/update_fallback.py +1 -1
- stubber/update_module_list.py +1 -1
- stubber/utils/config.py +19 -7
- stubber/utils/post.py +2 -1
- stubber/utils/repos.py +9 -3
- stubber/utils/stubmaker.py +1 -1
- stubber/utils/typed_config_toml.py +5 -2
- stubber/variants.py +1 -1
- micropython_stubber-1.23.1.dist-info/entry_points.txt +0 -3
- {micropython_stubber-1.23.1.dist-info → micropython_stubber-1.23.1.post1.dist-info}/LICENSE +0 -0
- {micropython_stubber-1.23.1.dist-info → micropython_stubber-1.23.1.post1.dist-info}/WHEEL +0 -0
@@ -8,16 +8,20 @@ from pathlib import Path
|
|
8
8
|
from typing import List, Optional, Union
|
9
9
|
|
10
10
|
import serial.tools.list_ports
|
11
|
-
from loguru import logger as log
|
12
11
|
from rich.progress import track
|
13
12
|
from tenacity import retry, stop_after_attempt, wait_fixed
|
14
13
|
|
15
14
|
from mpflash.errors import MPFlashError
|
15
|
+
from mpflash.logger import log
|
16
16
|
from mpflash.mpboard_id.board_id import find_board_id_by_description
|
17
17
|
from mpflash.mpremoteboard.runner import run
|
18
18
|
|
19
|
+
if sys.version_info >= (3, 11):
|
20
|
+
import tomllib # type: ignore
|
21
|
+
else:
|
22
|
+
import tomli as tomllib # type: ignore
|
23
|
+
|
19
24
|
###############################################################################################
|
20
|
-
# TODO : make this a bit nicer
|
21
25
|
HERE = Path(__file__).parent
|
22
26
|
|
23
27
|
OK = 0
|
@@ -52,6 +56,7 @@ class MPRemoteBoard:
|
|
52
56
|
self.mpy = ""
|
53
57
|
self.build = ""
|
54
58
|
self.location = location
|
59
|
+
self.toml = {}
|
55
60
|
if update:
|
56
61
|
self.get_mcu_info()
|
57
62
|
|
@@ -111,13 +116,14 @@ class MPRemoteBoard:
|
|
111
116
|
["run", str(HERE / "mpy_fw_info.py")],
|
112
117
|
no_info=True,
|
113
118
|
timeout=timeout,
|
119
|
+
resume=True, # Avoid restarts
|
114
120
|
)
|
115
121
|
if rc != OK:
|
116
122
|
raise ConnectionError(f"Failed to get mcu_info for {self.serialport}")
|
117
123
|
# Ok we have the info, now parse it
|
118
|
-
|
119
|
-
if
|
120
|
-
info = eval(
|
124
|
+
raw_info = result[0].strip()
|
125
|
+
if raw_info.startswith("{") and raw_info.endswith("}"):
|
126
|
+
info = eval(raw_info)
|
121
127
|
self.family = info["family"]
|
122
128
|
self.version = info["version"]
|
123
129
|
self.build = info["build"]
|
@@ -132,6 +138,43 @@ class MPRemoteBoard:
|
|
132
138
|
self.board = board_name
|
133
139
|
else:
|
134
140
|
self.board = "UNKNOWN_BOARD"
|
141
|
+
# get the board_info.toml
|
142
|
+
self.get_board_info_toml()
|
143
|
+
# now we know the board is connected
|
144
|
+
self.connected = True
|
145
|
+
|
146
|
+
@retry(stop=stop_after_attempt(RETRIES), wait=wait_fixed(0.2), reraise=True) # type: ignore ## retry_error_cls=ConnectionError,
|
147
|
+
def get_board_info_toml(self, timeout: int = 1):
|
148
|
+
"""
|
149
|
+
Reads the content of the board_info.toml file from the connected board,
|
150
|
+
and adds that to the board object.
|
151
|
+
|
152
|
+
Parameters:
|
153
|
+
- timeout (int): The timeout value in seconds.
|
154
|
+
|
155
|
+
Raises:
|
156
|
+
- ConnectionError: If failed to communicate with the serial port.
|
157
|
+
"""
|
158
|
+
try:
|
159
|
+
rc, result = self.run_command(
|
160
|
+
["cat", ":board_info.toml"],
|
161
|
+
no_info=True,
|
162
|
+
timeout=timeout,
|
163
|
+
log_errors=False,
|
164
|
+
)
|
165
|
+
except Exception as e:
|
166
|
+
raise ConnectionError(f"Failed to get board_info.toml for {self.serialport}: {e}")
|
167
|
+
# this is optional - so only parse if we got the file
|
168
|
+
self.toml = {}
|
169
|
+
if rc in [OK]: # sometimes we get an -9 ???
|
170
|
+
try:
|
171
|
+
# Ok we have the info, now parse it
|
172
|
+
self.toml = tomllib.loads("".join(result))
|
173
|
+
log.debug(f"board_info.toml: {self.toml}")
|
174
|
+
except Exception as e:
|
175
|
+
log.error(f"Failed to parse board_info.toml: {e}")
|
176
|
+
else:
|
177
|
+
log.trace(f"Failed to read board_info.toml: {result}")
|
135
178
|
|
136
179
|
def disconnect(self) -> bool:
|
137
180
|
"""
|
@@ -159,6 +202,7 @@ class MPRemoteBoard:
|
|
159
202
|
log_errors: bool = True,
|
160
203
|
no_info: bool = False,
|
161
204
|
timeout: int = 60,
|
205
|
+
resume: bool = False,
|
162
206
|
**kwargs,
|
163
207
|
):
|
164
208
|
"""
|
@@ -179,7 +223,7 @@ class MPRemoteBoard:
|
|
179
223
|
if self.serialport:
|
180
224
|
prefix += ["connect", self.serialport]
|
181
225
|
# if connected add resume to keep state between commands
|
182
|
-
if self.connected:
|
226
|
+
if self.connected or resume:
|
183
227
|
prefix += ["resume"]
|
184
228
|
cmd = prefix + cmd
|
185
229
|
log.debug(" ".join(cmd))
|
mpflash/pyproject.toml
CHANGED
stubber/bulk/mcu_stubber.py
CHANGED
@@ -11,11 +11,13 @@ from pathlib import Path
|
|
11
11
|
from tempfile import mkdtemp
|
12
12
|
from typing import List, Optional, Tuple
|
13
13
|
|
14
|
-
from loguru import logger as log
|
15
14
|
from rich.console import Console
|
16
15
|
from rich.table import Table
|
17
16
|
from tenacity import retry, stop_after_attempt, wait_fixed
|
18
17
|
|
18
|
+
from mpflash.connected import list_mcus
|
19
|
+
from mpflash.list import show_mcus
|
20
|
+
from mpflash.logger import log
|
19
21
|
from mpflash.mpremoteboard import ERROR, OK, MPRemoteBoard
|
20
22
|
from stubber import utils
|
21
23
|
from stubber.publish.merge_docstubs import merge_all_docstubs
|
@@ -250,7 +252,10 @@ def copy_boardname_to_board(mcu: MPRemoteBoard):
|
|
250
252
|
None
|
251
253
|
"""
|
252
254
|
if mcu.board:
|
253
|
-
cmd = [
|
255
|
+
cmd = [
|
256
|
+
"exec",
|
257
|
+
f"with open('lib/boardname.py', 'w') as f: f.write('BOARDNAME=\"{mcu.board}\"')",
|
258
|
+
]
|
254
259
|
log.info(f"Writing BOARDNAME='{mcu.board}' to boardname.py")
|
255
260
|
else:
|
256
261
|
cmd = ["rm", "boardname.py"]
|
@@ -284,30 +289,7 @@ def copy_scripts_to_board(mcu: MPRemoteBoard, variant: Variant, form: Form):
|
|
284
289
|
|
285
290
|
|
286
291
|
def get_stubfolder(out: List[str]):
|
287
|
-
return (
|
288
|
-
lines[-1].split("/remote/")[-1].strip() if (lines := [l for l in out if l.startswith("INFO : Path: ")]) else ""
|
289
|
-
)
|
290
|
-
|
291
|
-
|
292
|
-
def scan_boards(optimistic: bool = False) -> List[MPRemoteBoard]:
|
293
|
-
"""
|
294
|
-
This function scans for boards and returns a list of MPRemoteBoard objects.
|
295
|
-
:return: list of MPRemoteBoard objects
|
296
|
-
"""
|
297
|
-
boards = []
|
298
|
-
for mpr_port in MPRemoteBoard.connected_boards():
|
299
|
-
board = MPRemoteBoard(mpr_port)
|
300
|
-
log.debug(f"Attempt to connect to: {board.serialport}")
|
301
|
-
try:
|
302
|
-
board.get_mcu_info()
|
303
|
-
log.success(f"Detected board {board.description} {board.version}")
|
304
|
-
boards.append(board)
|
305
|
-
except Exception:
|
306
|
-
log.error(f"Failed to get mcu_info for {board.serialport}")
|
307
|
-
if optimistic:
|
308
|
-
boards.append(board)
|
309
|
-
continue
|
310
|
-
return boards
|
292
|
+
return lines[-1].split("/remote/")[-1].strip() if (lines := [l for l in out if l.startswith("INFO : Path: ")]) else ""
|
311
293
|
|
312
294
|
|
313
295
|
def set_loglevel(verbose: int) -> str:
|
@@ -347,7 +329,14 @@ def copy_to_repo(source: Path, fw: dict) -> Optional[Path]:
|
|
347
329
|
return None
|
348
330
|
|
349
331
|
|
350
|
-
def stub_connected_mcus(
|
332
|
+
def stub_connected_mcus(
|
333
|
+
variant: str,
|
334
|
+
format: str,
|
335
|
+
debug: bool,
|
336
|
+
serial: List[str],
|
337
|
+
ignore: List[str],
|
338
|
+
bluetooth: bool,
|
339
|
+
) -> int:
|
351
340
|
"""
|
352
341
|
Runs the stubber to generate stubs for connected MicroPython boards.
|
353
342
|
|
@@ -372,27 +361,19 @@ def stub_connected_mcus(variant: str, format: str, debug: bool) -> int:
|
|
372
361
|
all_built = []
|
373
362
|
|
374
363
|
# scan boards and just work with the ones that respond with understandable data
|
375
|
-
|
376
|
-
|
364
|
+
connected_mcus = list_mcus(ignore=ignore, include=serial, bluetooth=bluetooth)
|
365
|
+
# ignore boards that have the [micropython-stubber] ignore flag set
|
366
|
+
connected_mcus = [item for item in connected_mcus if not (item.toml.get("micropython-stubber", {}).get("ignore", False))]
|
367
|
+
|
368
|
+
if not connected_mcus:
|
377
369
|
log.error("No micropython boards were found")
|
378
370
|
return ERROR
|
379
371
|
|
380
|
-
|
381
|
-
table.add_column("Serial Port")
|
382
|
-
table.add_column("Port")
|
383
|
-
table.add_column("Description")
|
384
|
-
table.add_column("Version")
|
385
|
-
|
386
|
-
for b in connected_boards:
|
387
|
-
table.add_row(b.serialport, b.port, b.description, b.version)
|
388
|
-
console = Console()
|
389
|
-
console.print(table)
|
372
|
+
show_mcus(connected_mcus, refresh=False)
|
390
373
|
|
391
374
|
# scan boards and generate stubs
|
392
|
-
for board in
|
393
|
-
log.info(
|
394
|
-
f"Connecting using {board.serialport} to {board.port} {board.board} {board.version}: {board.description}"
|
395
|
-
)
|
375
|
+
for board in connected_mcus:
|
376
|
+
log.info(f"Connecting using {board.serialport} to {board.port} {board.board} {board.version}: {board.description}")
|
396
377
|
# remove the modulelist.done file before starting createstubs on each board
|
397
378
|
(temp_path / "modulelist.done").unlink(missing_ok=True)
|
398
379
|
|
@@ -428,14 +409,16 @@ def stub_connected_mcus(variant: str, format: str, debug: bool) -> int:
|
|
428
409
|
all_built.extend(built)
|
429
410
|
|
430
411
|
if all_built:
|
431
|
-
print_result_table(all_built
|
412
|
+
print_result_table(all_built)
|
432
413
|
log.success("Done")
|
433
414
|
return OK
|
434
415
|
log.error(f"Failed to generate stubs for {board.serialport}")
|
435
416
|
return ERROR
|
436
417
|
|
437
418
|
|
438
|
-
def print_result_table(all_built: List, console: Console):
|
419
|
+
def print_result_table(all_built: List, console: Optional[Console] = None):
|
420
|
+
if not console:
|
421
|
+
console = Console()
|
439
422
|
# create a rich table of the results and print it'
|
440
423
|
table = Table(title="Results")
|
441
424
|
|
stubber/codemod/enrich.py
CHANGED
@@ -8,7 +8,7 @@ from typing import Any, Dict, Optional
|
|
8
8
|
|
9
9
|
from libcst.codemod import CodemodContext, diff_code, exec_transform_with_prettyprint
|
10
10
|
from libcst.tool import _default_config # type: ignore
|
11
|
-
from
|
11
|
+
from mpflash.logger import log
|
12
12
|
|
13
13
|
import stubber.codemod.merge_docstub as merge_docstub
|
14
14
|
from stubber.utils.post import run_black
|
stubber/codemod/merge_docstub.py
CHANGED
@@ -13,7 +13,7 @@ import libcst as cst
|
|
13
13
|
from libcst.codemod import CodemodContext, VisitorBasedCodemodCommand
|
14
14
|
from libcst.codemod.visitors import AddImportsVisitor, GatherImportsVisitor, ImportItem
|
15
15
|
from libcst.helpers.module import insert_header_comments
|
16
|
-
from
|
16
|
+
from mpflash.logger import log
|
17
17
|
|
18
18
|
from stubber.cst_transformer import (
|
19
19
|
MODULE_KEY,
|
stubber/commands/build_cmd.py
CHANGED
stubber/commands/cli.py
CHANGED
@@ -4,12 +4,13 @@ command line interface - main group
|
|
4
4
|
|
5
5
|
import sys
|
6
6
|
|
7
|
+
from mpflash.vendor.click_aliases import ClickAliasedGroup
|
7
8
|
import rich_click as click
|
8
|
-
from
|
9
|
+
from mpflash.logger import log, set_loglevel as mpf_set_loglevel
|
9
10
|
from stubber import __version__
|
10
11
|
|
11
12
|
|
12
|
-
@click.group(chain=True)
|
13
|
+
@click.group(chain=True, cls=ClickAliasedGroup)
|
13
14
|
@click.version_option(package_name="micropython-stubber", prog_name="micropython-stubber✏️ ")
|
14
15
|
@click.option(
|
15
16
|
"-V",
|
@@ -41,15 +42,8 @@ def set_loglevel(verbose: int) -> str:
|
|
41
42
|
Add the handler to the logger, with the level and format string.
|
42
43
|
Return the level
|
43
44
|
"""
|
44
|
-
log.remove()
|
45
45
|
level = {0: "INFO", 1: "DEBUG", 2: "TRACE"}.get(verbose, "TRACE")
|
46
|
-
|
47
|
-
|
48
|
-
else:
|
49
|
-
format_str = "<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>"
|
50
|
-
|
51
|
-
log.add(
|
52
|
-
sys.stderr, level=level, backtrace=True, diagnose=True, colorize=True, format=format_str
|
53
|
-
)
|
46
|
+
# reuse mpflash logger
|
47
|
+
mpf_set_loglevel(level)
|
54
48
|
log.info(f"micropython-stubber {__version__}")
|
55
49
|
return level
|
stubber/commands/clone_cmd.py
CHANGED
stubber/commands/config_cmd.py
CHANGED
stubber/commands/get_core_cmd.py
CHANGED
@@ -7,7 +7,7 @@ from pathlib import Path
|
|
7
7
|
from typing import Optional
|
8
8
|
|
9
9
|
import rich_click as click
|
10
|
-
from
|
10
|
+
from mpflash.logger import log
|
11
11
|
|
12
12
|
import mpflash.basicgit as git
|
13
13
|
import stubber.utils as utils
|
@@ -22,7 +22,10 @@ from .cli import stubber_cli
|
|
22
22
|
#########################################################################################
|
23
23
|
|
24
24
|
|
25
|
-
@stubber_cli.command(
|
25
|
+
@stubber_cli.command(
|
26
|
+
name="get-docstubs",
|
27
|
+
aliases=["get-doc-stubs", "docstubs"],
|
28
|
+
)
|
26
29
|
@click.option(
|
27
30
|
"--path",
|
28
31
|
"-p",
|
@@ -7,7 +7,7 @@ from pathlib import Path
|
|
7
7
|
from typing import List, Optional
|
8
8
|
|
9
9
|
import rich_click as click
|
10
|
-
from
|
10
|
+
from mpflash.logger import log
|
11
11
|
|
12
12
|
import stubber.utils as utils
|
13
13
|
from stubber.codemod.enrich import enrich_folder
|
@@ -20,7 +20,10 @@ from .cli import stubber_cli
|
|
20
20
|
##########################################################################################
|
21
21
|
|
22
22
|
|
23
|
-
@stubber_cli.command(
|
23
|
+
@stubber_cli.command(
|
24
|
+
name="get-frozen",
|
25
|
+
aliases=["get-frozen-stubs", "frozen"],
|
26
|
+
)
|
24
27
|
@click.option(
|
25
28
|
"--stub-folder",
|
26
29
|
"-stubs",
|
stubber/commands/get_mcu_cmd.py
CHANGED
@@ -5,8 +5,9 @@
|
|
5
5
|
##########################################################################################
|
6
6
|
|
7
7
|
|
8
|
+
from typing import List
|
8
9
|
import rich_click as click
|
9
|
-
from
|
10
|
+
from mpflash.logger import log
|
10
11
|
|
11
12
|
from stubber.bulk.mcu_stubber import stub_connected_mcus
|
12
13
|
from stubber.utils.config import CONFIG
|
@@ -18,7 +19,10 @@ from .cli import stubber_cli
|
|
18
19
|
#########################################################################################
|
19
20
|
|
20
21
|
|
21
|
-
@stubber_cli.command(
|
22
|
+
@stubber_cli.command(
|
23
|
+
name="get-mcu-stubs",
|
24
|
+
aliases=["get-mcu-stubs", "mcu-stubs", "mcu"],
|
25
|
+
)
|
22
26
|
@click.option(
|
23
27
|
"--variant",
|
24
28
|
# "-v",
|
@@ -35,22 +39,50 @@ from .cli import stubber_cli
|
|
35
39
|
show_default=True,
|
36
40
|
help="Python source or pre-compiled.",
|
37
41
|
)
|
38
|
-
@click.option("--debug/--no-debug", default=False, show_default=True, help="Debug mode.")
|
39
42
|
@click.option(
|
40
|
-
"--
|
41
|
-
|
43
|
+
"--serial",
|
44
|
+
"--serial-port",
|
45
|
+
"-s",
|
46
|
+
"serial",
|
47
|
+
default=["*"],
|
48
|
+
multiple=True,
|
42
49
|
show_default=True,
|
43
|
-
help="
|
50
|
+
help="Which serial port(s) (or globs) to list. ",
|
51
|
+
metavar="SERIALPORT",
|
44
52
|
)
|
45
53
|
@click.option(
|
46
|
-
"--
|
47
|
-
|
54
|
+
"--ignore",
|
55
|
+
"-i",
|
56
|
+
is_eager=True,
|
57
|
+
help="Serial port(s) (or globs) to ignore. Defaults to MPFLASH_IGNORE.",
|
58
|
+
multiple=True,
|
59
|
+
default=[],
|
60
|
+
envvar="MPFLASH_IGNORE",
|
48
61
|
show_default=True,
|
49
|
-
|
62
|
+
metavar="SERIALPORT",
|
50
63
|
)
|
51
|
-
|
64
|
+
@click.option(
|
65
|
+
"--bluetooth/--no-bluetooth",
|
66
|
+
"-b/-nb",
|
67
|
+
is_flag=True,
|
68
|
+
default=False,
|
69
|
+
show_default=True,
|
70
|
+
help="""Include bluetooth ports in the list""",
|
71
|
+
)
|
72
|
+
@click.option("--debug/--no-debug", default=False, show_default=True, help="Debug mode.")
|
73
|
+
def cli_create_mcu_stubs(
|
74
|
+
variant: str,
|
75
|
+
format: str,
|
76
|
+
debug: bool,
|
77
|
+
serial: List[str],
|
78
|
+
ignore: List[str],
|
79
|
+
bluetooth: bool,
|
80
|
+
) -> int:
|
52
81
|
"""Run createstubs on one or more MCUs, and add the stubs to the micropython-stub repo."""
|
53
82
|
# check if all repos have been cloned
|
83
|
+
serial = list(serial)
|
84
|
+
ignore = list(ignore)
|
85
|
+
|
54
86
|
for repo in CONFIG.repos:
|
55
87
|
if not repo.exists():
|
56
88
|
log.error(
|
@@ -58,4 +90,13 @@ def cli_create_mcu_stubs(variant: str, format: str, debug: bool, reset: bool, gi
|
|
58
90
|
)
|
59
91
|
exit(1)
|
60
92
|
|
61
|
-
exit(
|
93
|
+
exit(
|
94
|
+
stub_connected_mcus(
|
95
|
+
variant=variant,
|
96
|
+
format=format,
|
97
|
+
debug=debug,
|
98
|
+
serial=serial,
|
99
|
+
ignore=ignore,
|
100
|
+
bluetooth=bluetooth,
|
101
|
+
)
|
102
|
+
)
|
stubber/commands/merge_cmd.py
CHANGED
@@ -5,7 +5,7 @@ enrich machinestubs with docstubs
|
|
5
5
|
from typing import List, Union
|
6
6
|
|
7
7
|
import rich_click as click
|
8
|
-
from
|
8
|
+
from mpflash.logger import log
|
9
9
|
|
10
10
|
from stubber.publish.merge_docstubs import merge_all_docstubs
|
11
11
|
from stubber.publish.package import GENERIC_L
|
stubber/commands/publish_cmd.py
CHANGED
stubber/commands/stub_cmd.py
CHANGED
stubber/commands/variants_cmd.py
CHANGED
stubber/downloader.py
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
"""Download files from a public github repo"""
|
2
|
+
|
2
3
|
# Copyright (c) 2020 Jos Verlinde
|
3
4
|
# MIT license
|
4
5
|
# pylint: disable= invalid-name
|
5
6
|
import os
|
6
7
|
|
7
8
|
import requests
|
8
|
-
from
|
9
|
+
from mpflash.logger import log
|
9
10
|
|
10
11
|
# # log = logging.getLogger(__name__)
|
11
12
|
# log.setLevel(level=logging.INFO)
|
stubber/freeze/common.py
CHANGED
@@ -5,7 +5,7 @@ import shutil
|
|
5
5
|
from pathlib import Path
|
6
6
|
from typing import Tuple
|
7
7
|
|
8
|
-
from
|
8
|
+
from mpflash.logger import log
|
9
9
|
|
10
10
|
from stubber.publish.defaults import GENERIC_U
|
11
11
|
|
@@ -17,7 +17,9 @@ def get_portboard(manifest_path: Path):
|
|
17
17
|
raises an ValueError if neither a port or board can be found
|
18
18
|
"""
|
19
19
|
# https://regex101.com/r/tv7JX4/1
|
20
|
-
re_pb =
|
20
|
+
re_pb = (
|
21
|
+
r".*micropython[\/\\]ports[\/\\](?P<port>[\w_-]*)([\/\\]boards[\/\\](?P<board>\w*))?[\/\\]"
|
22
|
+
)
|
21
23
|
mpy_port = mpy_board = ""
|
22
24
|
if matches := re.search(re_pb, manifest_path.absolute().as_posix()):
|
23
25
|
# port and board
|
@@ -50,7 +52,9 @@ def apply_frozen_module_fixes(freeze_path: Path, mpy_path: Path):
|
|
50
52
|
apply common fixes to the fozen modules to improve stub generation
|
51
53
|
"""
|
52
54
|
# NOTE: FIX 1 add __init__.py to umqtt
|
53
|
-
if (
|
55
|
+
if (
|
56
|
+
freeze_path / "umqtt/robust.py"
|
57
|
+
).exists(): # and not (freeze_path / "umqtt" / "__init__.py").exists():
|
54
58
|
log.debug("add missing : umqtt/__init__.py")
|
55
59
|
with open(freeze_path / "umqtt" / "__init__.py", "a") as f:
|
56
60
|
f.write("")
|
stubber/freeze/freeze_folder.py
CHANGED
@@ -6,7 +6,7 @@ import shutil
|
|
6
6
|
import warnings
|
7
7
|
from pathlib import Path # start moving from os & glob to pathlib
|
8
8
|
|
9
|
-
from
|
9
|
+
from mpflash.logger import log
|
10
10
|
from stubber.utils.repos import match_lib_with_mpy
|
11
11
|
|
12
12
|
from .. import utils
|
@@ -25,7 +25,7 @@ def freeze_folders(stub_folder: str, mpy_folder: str, lib_folder: str, version:
|
|
25
25
|
- 'ports/<port>/modules/*.py'
|
26
26
|
- 'ports/<port>/boards/<board>/modules/*.py'
|
27
27
|
"""
|
28
|
-
match_lib_with_mpy(version_tag=version, mpy_path=Path(mpy_folder),lib_path=Path(lib_folder))
|
28
|
+
match_lib_with_mpy(version_tag=version, mpy_path=Path(mpy_folder), lib_path=Path(lib_folder))
|
29
29
|
|
30
30
|
targets = []
|
31
31
|
scripts = glob.glob(mpy_folder + "/ports/**/modules/*.py", recursive=True)
|
@@ -9,7 +9,7 @@ import shutil
|
|
9
9
|
from pathlib import Path
|
10
10
|
from typing import List, Optional
|
11
11
|
|
12
|
-
from
|
12
|
+
from mpflash.logger import log
|
13
13
|
|
14
14
|
from stubber import utils
|
15
15
|
from stubber.tools.manifestfile import MODE_FREEZE, ManifestFile, ManifestFileError, ManifestOutput
|
@@ -51,7 +51,9 @@ def make_path_vars(
|
|
51
51
|
}
|
52
52
|
|
53
53
|
|
54
|
-
def freeze_one_manifest_2(
|
54
|
+
def freeze_one_manifest_2(
|
55
|
+
manifest: Path, frozen_stub_path: Path, mpy_path: Path, mpy_lib_path: Path, version: str
|
56
|
+
):
|
55
57
|
# apparently there can be multiple manifest files to a board ?
|
56
58
|
# save cwd for 'misbehaving' older esp8266 manifest files
|
57
59
|
cwd = Path.cwd()
|
@@ -61,7 +63,9 @@ def freeze_one_manifest_2(manifest: Path, frozen_stub_path: Path, mpy_path: Path
|
|
61
63
|
|
62
64
|
log.info("port-board: {}".format((port + "-" + board).rstrip("-")))
|
63
65
|
|
64
|
-
path_vars = make_path_vars(
|
66
|
+
path_vars = make_path_vars(
|
67
|
+
port=port, board=board, mpy_path=mpy_path, mpy_lib_path=mpy_lib_path
|
68
|
+
)
|
65
69
|
upy_manifest = ManifestFile(MODE_FREEZE, path_vars)
|
66
70
|
try:
|
67
71
|
# assume manifestneeds to be run from the port's folder
|
@@ -75,11 +79,18 @@ def freeze_one_manifest_2(manifest: Path, frozen_stub_path: Path, mpy_path: Path
|
|
75
79
|
# restore working directory
|
76
80
|
os.chdir(cwd)
|
77
81
|
# save the frozen files to the stubs
|
78
|
-
copy_frozen_to_stubs(
|
82
|
+
copy_frozen_to_stubs(
|
83
|
+
frozen_stub_path, port, board, upy_manifest.files(), version, mpy_path=mpy_path
|
84
|
+
)
|
79
85
|
|
80
86
|
|
81
87
|
def copy_frozen_to_stubs(
|
82
|
-
stub_path: Path,
|
88
|
+
stub_path: Path,
|
89
|
+
port: str,
|
90
|
+
board: str,
|
91
|
+
files: List[ManifestOutput],
|
92
|
+
version: str,
|
93
|
+
mpy_path: Path,
|
83
94
|
):
|
84
95
|
"""
|
85
96
|
copy the frozen files from the manifest to the stubs folder
|
@@ -110,4 +121,6 @@ def copy_frozen_to_stubs(
|
|
110
121
|
|
111
122
|
# make a module manifest
|
112
123
|
FAMILY = "micropython"
|
113
|
-
utils.make_manifest(
|
124
|
+
utils.make_manifest(
|
125
|
+
freeze_path, FAMILY, port=port, board=board, version=version, stubtype="frozen"
|
126
|
+
)
|