micropython-stubber 1.23.0__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.0.dist-info → micropython_stubber-1.23.1.post1.dist-info}/METADATA +32 -14
- micropython_stubber-1.23.1.post1.dist-info/RECORD +159 -0
- micropython_stubber-1.23.1.post1.dist-info/entry_points.txt +5 -0
- mpflash/README.md +40 -4
- mpflash/mpflash/add_firmware.py +1 -1
- mpflash/mpflash/ask_input.py +1 -1
- {stubber → mpflash/mpflash}/basicgit.py +3 -13
- mpflash/mpflash/bootloader/__init__.py +2 -37
- mpflash/mpflash/bootloader/activate.py +60 -0
- mpflash/mpflash/bootloader/detect.py +82 -0
- mpflash/mpflash/bootloader/manual.py +10 -11
- mpflash/mpflash/bootloader/micropython.py +2 -0
- mpflash/mpflash/bootloader/touch1200.py +13 -22
- mpflash/mpflash/cli_download.py +2 -2
- mpflash/mpflash/cli_flash.py +13 -16
- mpflash/mpflash/cli_group.py +18 -5
- mpflash/mpflash/cli_list.py +8 -2
- mpflash/mpflash/cli_main.py +3 -5
- mpflash/mpflash/common.py +3 -1
- mpflash/mpflash/config.py +2 -1
- mpflash/mpflash/connected.py +11 -8
- mpflash/mpflash/download.py +9 -5
- mpflash/mpflash/downloaded.py +1 -1
- mpflash/mpflash/{flash.py → flash/__init__.py} +3 -3
- mpflash/mpflash/{flash_esp.py → flash/esp.py} +1 -1
- mpflash/mpflash/{flash_stm32.py → flash/stm32.py} +4 -3
- mpflash/mpflash/{flash_stm32_dfu.py → flash/stm32_dfu.py} +1 -1
- mpflash/mpflash/{flash_uf2.py → flash/uf2/__init__.py} +19 -20
- mpflash/mpflash/{flash_uf2_linux.py → flash/uf2/linux.py} +12 -11
- mpflash/mpflash/{flash_uf2_macos.py → flash/uf2/macos.py} +11 -6
- mpflash/mpflash/{flash_uf2_windows.py → flash/uf2/windows.py} +11 -6
- mpflash/mpflash/{worklist.py → flash/worklist.py} +8 -9
- mpflash/mpflash/list.py +26 -9
- mpflash/mpflash/mpboard_id/__init__.py +1 -1
- mpflash/mpflash/mpboard_id/add_boards.py +3 -7
- mpflash/mpflash/mpboard_id/board_id.py +1 -1
- mpflash/mpflash/mpremoteboard/__init__.py +57 -17
- {stubber/utils → mpflash/mpflash}/versions.py +31 -24
- mpflash/poetry.lock +16 -5
- mpflash/pyproject.toml +4 -3
- stubber/__init__.py +1 -1
- stubber/board/createstubs.py +4 -4
- stubber/board/createstubs_db.py +5 -5
- stubber/board/createstubs_db_min.py +1 -1
- stubber/board/createstubs_db_mpy.mpy +0 -0
- stubber/board/createstubs_mem.py +5 -5
- stubber/board/createstubs_mem_min.py +1 -1
- stubber/board/createstubs_mem_mpy.mpy +0 -0
- stubber/board/createstubs_min.py +1 -1
- stubber/board/createstubs_mpy.mpy +0 -0
- stubber/bulk/mcu_stubber.py +28 -45
- stubber/codemod/enrich.py +1 -1
- stubber/codemod/merge_docstub.py +1 -1
- stubber/codemod/utils.py +2 -3
- stubber/commands/build_cmd.py +1 -1
- stubber/commands/cli.py +6 -12
- stubber/commands/clone_cmd.py +3 -2
- 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 +6 -3
- stubber/commands/get_frozen_cmd.py +6 -3
- stubber/commands/get_mcu_cmd.py +53 -12
- stubber/commands/merge_cmd.py +2 -3
- stubber/commands/publish_cmd.py +2 -3
- stubber/commands/stub_cmd.py +1 -1
- stubber/commands/switch_cmd.py +2 -2
- stubber/commands/variants_cmd.py +2 -3
- 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 +8 -4
- stubber/get_cpython.py +15 -4
- stubber/minify.py +11 -6
- stubber/publish/candidates.py +20 -7
- stubber/publish/defaults.py +4 -9
- stubber/publish/merge_docstubs.py +4 -2
- stubber/publish/missing_class_methods.py +5 -3
- stubber/publish/package.py +8 -4
- stubber/publish/pathnames.py +2 -2
- stubber/publish/publish.py +2 -2
- stubber/publish/pypi.py +6 -2
- stubber/publish/stubpackage.py +39 -17
- stubber/rst/classsort.py +2 -1
- stubber/rst/lookup.py +1 -0
- stubber/rst/reader.py +12 -20
- 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 -2
- stubber/update_fallback.py +2 -2
- stubber/update_module_list.py +1 -1
- stubber/utils/__init__.py +2 -1
- stubber/utils/config.py +18 -8
- stubber/utils/manifest.py +2 -4
- stubber/utils/post.py +2 -1
- stubber/utils/repos.py +4 -5
- stubber/utils/stubmaker.py +1 -1
- stubber/utils/typed_config_toml.py +5 -2
- stubber/variants.py +1 -1
- micropython_stubber-1.23.0.dist-info/RECORD +0 -159
- micropython_stubber-1.23.0.dist-info/entry_points.txt +0 -3
- mpflash/mpflash/flash_stm32_cube.py +0 -111
- mpflash/mpflash/vendor/versions.py +0 -119
- {micropython_stubber-1.23.0.dist-info → micropython_stubber-1.23.1.post1.dist-info}/LICENSE +0 -0
- {micropython_stubber-1.23.0.dist-info → micropython_stubber-1.23.1.post1.dist-info}/WHEEL +0 -0
- /mpflash/{mpflash/vendor/basicgit.py → basicgit.py} +0 -0
- /mpflash/mpflash/{flash_uf2_boardid.py → flash/uf2/boardid.py} +0 -0
- /mpflash/mpflash/{uf2disk.py → flash/uf2/uf2disk.py} +0 -0
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
|
+
)
|
stubber/freeze/get_frozen.py
CHANGED
@@ -22,14 +22,14 @@ import shutil # start moving from os & glob to pathlib
|
|
22
22
|
from pathlib import Path
|
23
23
|
from typing import List, Optional
|
24
24
|
|
25
|
-
from
|
25
|
+
from mpflash.logger import log
|
26
26
|
from packaging.version import Version
|
27
27
|
|
28
|
+
from mpflash.versions import SET_PREVIEW, V_PREVIEW
|
28
29
|
from stubber import utils
|
29
30
|
from stubber.freeze.freeze_folder import freeze_folders # Micropython < v1.12
|
30
31
|
from stubber.freeze.freeze_manifest_2 import freeze_one_manifest_2
|
31
32
|
from stubber.utils.config import CONFIG
|
32
|
-
from stubber.utils.versions import SET_PREVIEW, V_PREVIEW
|
33
33
|
|
34
34
|
FAMILY = "micropython"
|
35
35
|
|
@@ -83,7 +83,9 @@ def freeze_any(
|
|
83
83
|
frozen_stub_path = get_fsp(version, stub_folder)
|
84
84
|
log.debug("MicroPython v1.11, older or other")
|
85
85
|
# others
|
86
|
-
modules = freeze_folders(
|
86
|
+
modules = freeze_folders(
|
87
|
+
frozen_stub_path.as_posix(), mpy_path.as_posix(), mpy_lib_path.as_posix(), version
|
88
|
+
)
|
87
89
|
count = len(modules)
|
88
90
|
else:
|
89
91
|
# get the current checked out version
|
@@ -120,7 +122,9 @@ def freeze_any(
|
|
120
122
|
|
121
123
|
def get_fsp(version: str, stub_folder: Optional[Path] = None) -> Path:
|
122
124
|
if not stub_folder:
|
123
|
-
frozen_stub_path =
|
125
|
+
frozen_stub_path = (
|
126
|
+
CONFIG.stub_path / f"{FAMILY}-{utils.clean_version(version, flat=True)}-frozen"
|
127
|
+
)
|
124
128
|
frozen_stub_path = frozen_stub_path.absolute()
|
125
129
|
else:
|
126
130
|
frozen_stub_path: Path = Path(stub_folder).absolute()
|
stubber/get_cpython.py
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
Download or update the MicroPython compatibility modules from pycopy and stores them in the all_stubs folder
|
3
3
|
The all_stubs folder should be mapped/symlinked to the micropython_stubs/stubs repo/folder
|
4
4
|
"""
|
5
|
+
|
5
6
|
# pragma: no cover
|
6
7
|
import json
|
7
8
|
import os
|
@@ -12,7 +13,7 @@ import tempfile
|
|
12
13
|
from pathlib import Path
|
13
14
|
from typing import Optional, Union
|
14
15
|
|
15
|
-
from
|
16
|
+
from mpflash.logger import log
|
16
17
|
|
17
18
|
from . import __version__
|
18
19
|
|
@@ -22,7 +23,9 @@ from .utils.config import CONFIG
|
|
22
23
|
# # log = logging.getLogger(__name__)
|
23
24
|
|
24
25
|
|
25
|
-
def get_core(
|
26
|
+
def get_core(
|
27
|
+
requirements: str, stub_path: Optional[Union[str, Path]] = None, family: str = "core"
|
28
|
+
):
|
26
29
|
"Download MicroPython compatibility modules"
|
27
30
|
if not stub_path:
|
28
31
|
stub_path = CONFIG.stub_path / "cpython-core" # pragma: no cover
|
@@ -71,7 +74,9 @@ def get_core(requirements: str, stub_path: Optional[Union[str, Path]] = None, fa
|
|
71
74
|
|
72
75
|
except OSError as err: # pragma: no cover
|
73
76
|
log.error(
|
74
|
-
"An error occurred while trying to run pip to download the MicroPython compatibility modules from PyPi: {}".format(
|
77
|
+
"An error occurred while trying to run pip to download the MicroPython compatibility modules from PyPi: {}".format(
|
78
|
+
err
|
79
|
+
)
|
75
80
|
)
|
76
81
|
|
77
82
|
# copy *.py files in build folder to stub_path
|
@@ -86,7 +91,13 @@ def get_core(requirements: str, stub_path: Optional[Union[str, Path]] = None, fa
|
|
86
91
|
log.exception(err)
|
87
92
|
|
88
93
|
# build modules.json
|
89
|
-
mod_manifest = utils.manifest(
|
94
|
+
mod_manifest = utils.manifest(
|
95
|
+
family="cpython-core",
|
96
|
+
port=family,
|
97
|
+
version=__version__,
|
98
|
+
stubtype="core",
|
99
|
+
platform="cpython",
|
100
|
+
)
|
90
101
|
mod_manifest["modules"] += modlist
|
91
102
|
|
92
103
|
if mod_manifest and len(modlist):
|
stubber/minify.py
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
Processing for createstubs.py
|
3
3
|
Minimizes and cross-compiles a MicroPyton file.
|
4
4
|
"""
|
5
|
+
|
5
6
|
import itertools
|
6
7
|
import subprocess
|
7
8
|
import tempfile
|
@@ -10,14 +11,14 @@ from io import BytesIO, IOBase, StringIO, TextIOWrapper
|
|
10
11
|
from pathlib import Path
|
11
12
|
from typing import List, Tuple, Union
|
12
13
|
|
13
|
-
try:
|
14
|
+
try:
|
14
15
|
import python_minifier
|
15
16
|
except ImportError:
|
16
17
|
python_minifier = None
|
17
18
|
|
18
|
-
from
|
19
|
+
from mpflash.logger import log
|
19
20
|
|
20
|
-
from
|
21
|
+
from mpflash.versions import SET_PREVIEW, V_PREVIEW
|
21
22
|
|
22
23
|
# Type Aliases for minify
|
23
24
|
StubSource = Union[Path, str, StringIO, TextIOWrapper]
|
@@ -204,7 +205,9 @@ def minify_script(source_script: StubSource, keep_report: bool = True, diff: boo
|
|
204
205
|
elif isinstance(source_script, str): # type: ignore
|
205
206
|
source_content = source_script
|
206
207
|
else:
|
207
|
-
raise TypeError(
|
208
|
+
raise TypeError(
|
209
|
+
f"source_script must be str, Path, or file-like object, not {type(source_script)}"
|
210
|
+
)
|
208
211
|
|
209
212
|
if not source_content:
|
210
213
|
raise ValueError("No source content")
|
@@ -243,7 +246,7 @@ def minify_script(source_script: StubSource, keep_report: bool = True, diff: boo
|
|
243
246
|
],
|
244
247
|
# remove_pass=True, # no dead code
|
245
248
|
# convert_posargs_to_args=True, # Does not save any space
|
246
|
-
|
249
|
+
)
|
247
250
|
len_3 = len(min_source)
|
248
251
|
if 1:
|
249
252
|
# write to temp file for debugging
|
@@ -399,7 +402,9 @@ def pipx_mpy_cross(version: str, source_file, _target):
|
|
399
402
|
# Add params
|
400
403
|
cmd += ["-O2", str(source_file), "-o", str(_target), "-s", "createstubs.py"]
|
401
404
|
log.trace(" ".join(cmd))
|
402
|
-
result = subprocess.run(
|
405
|
+
result = subprocess.run(
|
406
|
+
cmd, capture_output=True, text=True, encoding="utf-8"
|
407
|
+
) # Specify the encoding
|
403
408
|
return result
|
404
409
|
|
405
410
|
|
stubber/publish/candidates.py
CHANGED
@@ -14,16 +14,22 @@ import re
|
|
14
14
|
from pathlib import Path
|
15
15
|
from typing import Any, Dict, Generator, List, Optional, Union
|
16
16
|
|
17
|
-
from
|
17
|
+
from mpflash.logger import log
|
18
18
|
from packaging.version import parse
|
19
19
|
|
20
|
-
import
|
20
|
+
import mpflash.basicgit as git
|
21
|
+
from mpflash.versions import (
|
22
|
+
OLDEST_VERSION,
|
23
|
+
SET_PREVIEW,
|
24
|
+
V_PREVIEW,
|
25
|
+
clean_version,
|
26
|
+
micropython_versions,
|
27
|
+
)
|
21
28
|
from stubber import utils
|
22
29
|
from stubber.publish.defaults import GENERIC, GENERIC_L, GENERIC_U
|
23
30
|
|
24
31
|
# from stubber.publish.enums import COMBO_STUBS
|
25
32
|
from stubber.utils.config import CONFIG
|
26
|
-
from stubber.utils.versions import OLDEST_VERSION, SET_PREVIEW, V_PREVIEW, clean_version, micropython_versions
|
27
33
|
|
28
34
|
|
29
35
|
def subfolder_names(path: Path):
|
@@ -108,7 +114,9 @@ def frozen_candidates(
|
|
108
114
|
auto_port = is_auto(ports)
|
109
115
|
auto_board = is_auto(boards)
|
110
116
|
if is_auto(versions):
|
111
|
-
versions = list(version_candidates(suffix="frozen", prefix=family, path=path)) + [
|
117
|
+
versions = list(version_candidates(suffix="frozen", prefix=family, path=path)) + [
|
118
|
+
V_PREVIEW
|
119
|
+
]
|
112
120
|
else:
|
113
121
|
versions = [versions] if isinstance(versions, str) else versions
|
114
122
|
|
@@ -126,7 +134,9 @@ def frozen_candidates(
|
|
126
134
|
# lookup the (frozen) micropython ports
|
127
135
|
ports = list_frozen_ports(family, version, path=path)
|
128
136
|
else:
|
129
|
-
raise NotImplementedError(
|
137
|
+
raise NotImplementedError(
|
138
|
+
f"auto ports not implemented for family {family}"
|
139
|
+
) # pragma: no cover
|
130
140
|
# elif family == "pycom":
|
131
141
|
# ports = ["esp32"]
|
132
142
|
# elif family == "lobo":
|
@@ -159,7 +169,9 @@ def frozen_candidates(
|
|
159
169
|
|
160
170
|
else:
|
161
171
|
# raise NotImplementedError(f"auto boards not implemented for family {family}") # pragma: no cover
|
162
|
-
raise NotImplementedError(
|
172
|
+
raise NotImplementedError(
|
173
|
+
f"auto boards not implemented for family {family}"
|
174
|
+
) # pragma: no cover
|
163
175
|
# elif family == "pycom":
|
164
176
|
# boards = ["wipy", "lopy", "gpy", "fipy"]
|
165
177
|
# ---------------------------------------------------------------------------
|
@@ -257,6 +269,7 @@ def filter_list(
|
|
257
269
|
worklist = [
|
258
270
|
i
|
259
271
|
for i in worklist
|
260
|
-
if i["board"].lower() in boards_
|
272
|
+
if i["board"].lower() in boards_
|
273
|
+
or i["board"].lower().replace("generic_", "") in boards_
|
261
274
|
]
|
262
275
|
return worklist
|
stubber/publish/defaults.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
"""Build and packaging defaults for stubber"""
|
2
|
+
|
2
3
|
from typing import Dict, List
|
3
4
|
|
5
|
+
from mpflash.versions import V_PREVIEW, clean_version
|
4
6
|
from stubber.utils.config import CONFIG
|
5
|
-
from stubber.utils.versions import V_PREVIEW, clean_version
|
6
7
|
|
7
8
|
# The default board for the ports modules documented with base name only
|
8
9
|
# as the MicroPython BOARD naming convention has changed over time there are different options to try
|
@@ -29,15 +30,9 @@ def default_board(port: str, version=V_PREVIEW) -> str: # sourcery skip: assign
|
|
29
30
|
ver_flat = clean_version(version, flat=True)
|
30
31
|
if port in DEFAULT_BOARDS:
|
31
32
|
for board in DEFAULT_BOARDS[port]:
|
32
|
-
base =
|
33
|
-
f"micropython-{ver_flat}-{port}-{board}"
|
34
|
-
if board
|
35
|
-
else f"micropython-{ver_flat}-{port}"
|
36
|
-
)
|
33
|
+
base = f"micropython-{ver_flat}-{port}-{board}" if board else f"micropython-{ver_flat}-{port}"
|
37
34
|
# check if we have a (merged)stub for this version and port
|
38
|
-
if (CONFIG.stub_path / f"{base}-merged").exists() or (
|
39
|
-
CONFIG.stub_path / base
|
40
|
-
).exists():
|
35
|
+
if (CONFIG.stub_path / f"{base}-merged").exists() or (CONFIG.stub_path / base).exists():
|
41
36
|
return board
|
42
37
|
# fallback to first listed board
|
43
38
|
return DEFAULT_BOARDS[port][0]
|
@@ -6,7 +6,7 @@ import shutil
|
|
6
6
|
from pathlib import Path
|
7
7
|
from typing import List, Optional, Union
|
8
8
|
|
9
|
-
from
|
9
|
+
from mpflash.logger import log
|
10
10
|
|
11
11
|
from stubber.codemod.enrich import enrich_folder
|
12
12
|
from stubber.publish.candidates import board_candidates, filter_list
|
@@ -49,7 +49,9 @@ 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(
|
52
|
+
candidate["board"] = default_board(
|
53
|
+
port=candidate["port"], version=candidate["version"]
|
54
|
+
)
|
53
55
|
# check if we have MCU stubs of this version and port
|
54
56
|
doc_path = CONFIG.stub_path / f"{get_base(candidate)}-docstubs"
|
55
57
|
# src and dest paths
|
@@ -6,12 +6,12 @@ Add missing methods to classes in the stubs that are documented in the docstubs
|
|
6
6
|
from pathlib import Path
|
7
7
|
|
8
8
|
import libcst as cst
|
9
|
-
from
|
9
|
+
from mpflash.logger import log
|
10
10
|
|
11
|
+
from mpflash.versions import clean_version
|
11
12
|
from stubber.codemod.add_method import CallAdder, CallFinder
|
12
13
|
from stubber.utils.config import CONFIG
|
13
14
|
from stubber.utils.post import run_black
|
14
|
-
from stubber.utils.versions import clean_version
|
15
15
|
|
16
16
|
|
17
17
|
def add_machine_pin_call(merged_path: Path, version: str):
|
@@ -23,7 +23,9 @@ def add_machine_pin_call(merged_path: Path, version: str):
|
|
23
23
|
# and to avoid having to parse the file twice
|
24
24
|
|
25
25
|
# first find the __call__ method in the default stubs
|
26
|
-
mod_path =
|
26
|
+
mod_path = (
|
27
|
+
CONFIG.stub_path / f"micropython-{clean_version(version, flat=True)}-docstubs/machine.pyi"
|
28
|
+
)
|
27
29
|
if not mod_path.exists():
|
28
30
|
log.error(f"no docstubs found for {version}")
|
29
31
|
return False
|
stubber/publish/package.py
CHANGED
@@ -7,15 +7,15 @@ import sys
|
|
7
7
|
from pathlib import Path
|
8
8
|
from typing import Dict, Union
|
9
9
|
|
10
|
-
from
|
10
|
+
from mpflash.logger import log
|
11
11
|
from packaging.version import parse
|
12
12
|
from pysondb import PysonDB
|
13
13
|
|
14
|
+
from mpflash.versions import clean_version
|
14
15
|
from stubber.publish.defaults import GENERIC, GENERIC_L, default_board
|
15
16
|
from stubber.publish.enums import StubSource
|
16
17
|
from stubber.publish.stubpackage import StubPackage, StubSources
|
17
18
|
from stubber.utils.config import CONFIG
|
18
|
-
from stubber.utils.versions import clean_version
|
19
19
|
|
20
20
|
# replace std log handler with a custom one capped on INFO level
|
21
21
|
log.remove()
|
@@ -62,7 +62,9 @@ def get_package(
|
|
62
62
|
)
|
63
63
|
|
64
64
|
|
65
|
-
def get_package_info(
|
65
|
+
def get_package_info(
|
66
|
+
db: PysonDB, pub_path: Path, *, pkg_name: str, mpy_version: str
|
67
|
+
) -> Union[Dict, None]:
|
66
68
|
"""
|
67
69
|
get a package's record from the json db if it can be found
|
68
70
|
matches om the package name and version
|
@@ -70,7 +72,9 @@ def get_package_info(db: PysonDB, pub_path: Path, *, pkg_name: str, mpy_version:
|
|
70
72
|
mpy_version: micropython/firmware version (1.18)
|
71
73
|
"""
|
72
74
|
# find in the database
|
73
|
-
recs = db.get_by_query(
|
75
|
+
recs = db.get_by_query(
|
76
|
+
query=lambda x: x["mpy_version"] == mpy_version and x["name"] == pkg_name
|
77
|
+
)
|
74
78
|
# dict to list
|
75
79
|
recs = [{"id": key, "data": recs[key]} for key in recs]
|
76
80
|
# sort
|
stubber/publish/pathnames.py
CHANGED
@@ -6,12 +6,12 @@ Helper functions to deal with path names and filenames for the folders in the st
|
|
6
6
|
from pathlib import Path
|
7
7
|
from typing import Dict, Optional
|
8
8
|
|
9
|
-
from
|
9
|
+
from mpflash.logger import log
|
10
10
|
|
11
|
+
from mpflash.versions import V_PREVIEW, clean_version
|
11
12
|
from stubber.publish.defaults import default_board
|
12
13
|
from stubber.publish.package import GENERIC
|
13
14
|
from stubber.utils.config import CONFIG
|
14
|
-
from stubber.utils.versions import V_PREVIEW, clean_version
|
15
15
|
|
16
16
|
|
17
17
|
## Helper functions
|
stubber/publish/publish.py
CHANGED
@@ -6,14 +6,14 @@ prepare a set of stub files for publishing to PyPi
|
|
6
6
|
|
7
7
|
from typing import Any, Dict, List, Optional, Union
|
8
8
|
|
9
|
-
from
|
9
|
+
from mpflash.logger import log
|
10
10
|
|
11
|
+
from mpflash.versions import V_PREVIEW
|
11
12
|
from stubber.publish.candidates import board_candidates, filter_list
|
12
13
|
from stubber.publish.database import get_database
|
13
14
|
from stubber.publish.defaults import GENERIC_U
|
14
15
|
from stubber.publish.package import get_package
|
15
16
|
from stubber.utils.config import CONFIG
|
16
|
-
from stubber.utils.versions import V_PREVIEW
|
17
17
|
|
18
18
|
|
19
19
|
def build_multiple(
|
stubber/publish/pypi.py
CHANGED
@@ -7,7 +7,7 @@ from typing import Optional
|
|
7
7
|
|
8
8
|
from packaging.version import Version, parse
|
9
9
|
from pypi_simple import PyPISimple, NoSuchProjectError
|
10
|
-
from
|
10
|
+
from mpflash.logger import log
|
11
11
|
|
12
12
|
|
13
13
|
def get_pypi_versions(package_name: str, base: Optional[Version] = None, production: bool = True):
|
@@ -28,7 +28,11 @@ def get_pypi_versions(package_name: str, base: Optional[Version] = None, product
|
|
28
28
|
if not package_info:
|
29
29
|
return []
|
30
30
|
|
31
|
-
versions = [
|
31
|
+
versions = [
|
32
|
+
parse(pkg.version)
|
33
|
+
for pkg in package_info.packages
|
34
|
+
if pkg.package_type == "wheel" and pkg.version
|
35
|
+
]
|
32
36
|
# print(versions)
|
33
37
|
|
34
38
|
if base:
|
stubber/publish/stubpackage.py
CHANGED
@@ -5,31 +5,32 @@ import json
|
|
5
5
|
import shutil
|
6
6
|
import subprocess
|
7
7
|
from pathlib import Path
|
8
|
+
import sys
|
8
9
|
from typing import Any, Dict, List, Optional, Tuple, Union
|
9
10
|
|
10
11
|
import tenacity
|
11
12
|
|
12
|
-
from
|
13
|
+
from mpflash.basicgit import get_git_describe
|
13
14
|
from stubber.publish.helpers import get_module_docstring
|
14
15
|
|
15
|
-
|
16
|
-
import tomllib
|
17
|
-
|
18
|
-
import tomli as tomllib
|
16
|
+
if sys.version_info >= (3, 11):
|
17
|
+
import tomllib # type: ignore
|
18
|
+
else:
|
19
|
+
import tomli as tomllib # type: ignore
|
19
20
|
|
20
21
|
from typing import NewType
|
21
22
|
|
22
23
|
import tomli_w
|
23
|
-
from
|
24
|
+
from mpflash.logger import log
|
24
25
|
from packaging.version import Version, parse
|
25
26
|
from pysondb import PysonDB
|
26
27
|
|
28
|
+
from mpflash.versions import SET_PREVIEW, V_PREVIEW, clean_version
|
27
29
|
from stubber.publish.bump import bump_version
|
28
30
|
from stubber.publish.defaults import GENERIC_U, default_board
|
29
31
|
from stubber.publish.enums import StubSource
|
30
32
|
from stubber.publish.pypi import Version, get_pypi_versions
|
31
33
|
from stubber.utils.config import CONFIG
|
32
|
-
from stubber.utils.versions import SET_PREVIEW, V_PREVIEW, clean_version
|
33
34
|
|
34
35
|
Status = NewType("Status", Dict[str, Union[str, None]])
|
35
36
|
StubSources = List[Tuple[StubSource, Path]]
|
@@ -125,9 +126,15 @@ class VersionedPackage(object):
|
|
125
126
|
parts = describe.split("-", 3)
|
126
127
|
ver = parts[0]
|
127
128
|
if len(parts) > 1:
|
128
|
-
rc =
|
129
|
+
rc = (
|
130
|
+
parts[1]
|
131
|
+
if parts[1].isdigit()
|
132
|
+
else parts[2] if len(parts) > 2 and parts[2].isdigit() else 1
|
133
|
+
)
|
129
134
|
rc = int(rc)
|
130
|
-
base =
|
135
|
+
base = (
|
136
|
+
bump_version(Version(ver), minor_bump=True) if parts[1] != V_PREVIEW else Version(ver)
|
137
|
+
)
|
131
138
|
return str(bump_version(base, rc=rc))
|
132
139
|
# raise ValueError("cannot determine next version number micropython")
|
133
140
|
|
@@ -304,7 +311,9 @@ class Builder(VersionedPackage):
|
|
304
311
|
# Check if all stub source folders exist
|
305
312
|
for stub_type, src_path in self.stub_sources:
|
306
313
|
if not (CONFIG.stub_path / src_path).exists():
|
307
|
-
raise FileNotFoundError(
|
314
|
+
raise FileNotFoundError(
|
315
|
+
f"Could not find stub source folder {CONFIG.stub_path / src_path}"
|
316
|
+
)
|
308
317
|
|
309
318
|
# 1 - Copy the stubs to the package, directly in the package folder (no folders)
|
310
319
|
# for stub_type, fw_path in [s for s in self.stub_sources]:
|
@@ -315,7 +324,9 @@ class Builder(VersionedPackage):
|
|
315
324
|
self.copy_folder(stub_type, src_path)
|
316
325
|
except OSError as e:
|
317
326
|
if stub_type != StubSource.FROZEN:
|
318
|
-
raise FileNotFoundError(
|
327
|
+
raise FileNotFoundError(
|
328
|
+
f"Could not find stub source folder {src_path}"
|
329
|
+
) from e
|
319
330
|
else:
|
320
331
|
log.debug(f"Error copying stubs from : {CONFIG.stub_path / src_path}, {e}")
|
321
332
|
finally:
|
@@ -707,7 +718,8 @@ class PoetryBuilder(Builder):
|
|
707
718
|
_pyproject = self.pyproject
|
708
719
|
assert _pyproject is not None, "No pyproject.toml file found"
|
709
720
|
_pyproject["tool"]["poetry"]["packages"] = [
|
710
|
-
{"include": p.relative_to(self.package_path).as_posix()}
|
721
|
+
{"include": p.relative_to(self.package_path).as_posix()}
|
722
|
+
for p in sorted((self.package_path).rglob("*.pyi"))
|
711
723
|
]
|
712
724
|
# write out the pyproject.toml file
|
713
725
|
self.pyproject = _pyproject
|
@@ -851,7 +863,9 @@ class StubPackage(PoetryBuilder):
|
|
851
863
|
# check if the sources exist
|
852
864
|
ok = self.are_package_sources_available()
|
853
865
|
if not ok:
|
854
|
-
log.debug(
|
866
|
+
log.debug(
|
867
|
+
f"{self.package_name}: skipping as one or more source stub folders are missing"
|
868
|
+
)
|
855
869
|
self.status["error"] = "Skipped, stub folder(s) missing"
|
856
870
|
shutil.rmtree(self.package_path.as_posix())
|
857
871
|
self._publish = False # type: ignore
|
@@ -873,7 +887,9 @@ class StubPackage(PoetryBuilder):
|
|
873
887
|
self,
|
874
888
|
production: bool, # PyPI or Test-PyPi - USED TO FIND THE NEXT VERSION NUMBER
|
875
889
|
force=False, # BUILD even if no changes
|
876
|
-
) ->
|
890
|
+
) -> (
|
891
|
+
bool
|
892
|
+
): # sourcery skip: default-mutable-arg, extract-duplicate-method, require-parameter-annotation
|
877
893
|
"""
|
878
894
|
Build a package
|
879
895
|
look up the previous package version in the dabase
|
@@ -899,7 +915,9 @@ class StubPackage(PoetryBuilder):
|
|
899
915
|
if force:
|
900
916
|
log.info(f"Force build: {self.package_name} {self.pkg_version} ")
|
901
917
|
else:
|
902
|
-
log.info(
|
918
|
+
log.info(
|
919
|
+
f"Found changes to package sources: {self.package_name} {self.pkg_version} "
|
920
|
+
)
|
903
921
|
log.trace(f"Old hash {self.hash} != New hash {self.calculate_hash()}")
|
904
922
|
# Build the distribution files
|
905
923
|
old_ver = self.pkg_version
|
@@ -961,7 +979,9 @@ class StubPackage(PoetryBuilder):
|
|
961
979
|
# Publish the package to PyPi, Test-PyPi or Github
|
962
980
|
if self.is_changed():
|
963
981
|
if self.mpy_version in SET_PREVIEW and production and not force:
|
964
|
-
log.warning(
|
982
|
+
log.warning(
|
983
|
+
"version: `latest` package will only be available on Github, and not published to PyPi."
|
984
|
+
)
|
965
985
|
self.status["result"] = "Published to GitHub"
|
966
986
|
else:
|
967
987
|
return self.publish_distribution(dry_run, production, db)
|
@@ -990,7 +1010,9 @@ class StubPackage(PoetryBuilder):
|
|
990
1010
|
if not dry_run:
|
991
1011
|
pub_ok = self.poetry_publish(production=production)
|
992
1012
|
else:
|
993
|
-
log.warning(
|
1013
|
+
log.warning(
|
1014
|
+
f"{self.package_name}: Dry run, not publishing to {'' if production else 'Test-'}PyPi"
|
1015
|
+
)
|
994
1016
|
pub_ok = True
|
995
1017
|
if not pub_ok:
|
996
1018
|
log.warning(f"{self.package_name}: Publish failed for {self.pkg_version}")
|
stubber/rst/classsort.py
CHANGED
@@ -4,10 +4,11 @@ note that this does not take multiple inheritance into account
|
|
4
4
|
ref : https://stackoverflow.com/questions/34964878/python-generate-a-dictionarytree-from-a-list-of-tuples/35049729#35049729
|
5
5
|
with modification
|
6
6
|
"""
|
7
|
+
|
7
8
|
import re
|
8
9
|
from typing import List
|
9
10
|
|
10
|
-
from
|
11
|
+
from mpflash.logger import log
|
11
12
|
|
12
13
|
__all__ = ["sort_classes"]
|
13
14
|
RE_CLASS = re.compile(r"class\s+(?P<class>\w+)(\((?P<parent>\w*)\))?")
|
stubber/rst/lookup.py
CHANGED
@@ -247,6 +247,7 @@ MODULE_GLUE = {
|
|
247
247
|
#
|
248
248
|
# "builtins": ["from stdlib.builtins import *"], # integrate STDLIB
|
249
249
|
# "machine": ["from network import AbstractNIC"], # NIC is an abstract class, although not defined or used as such
|
250
|
+
"espnow": ["from _espnow import ESPNowBase"], # ESPNowBase is an undocumented base class
|
250
251
|
}
|
251
252
|
|
252
253
|
|