micropython-stubber 1.20.1__py3-none-any.whl → 1.20.4__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.20.1.dist-info → micropython_stubber-1.20.4.dist-info}/METADATA +4 -3
- {micropython_stubber-1.20.1.dist-info → micropython_stubber-1.20.4.dist-info}/RECORD +58 -51
- {micropython_stubber-1.20.1.dist-info → micropython_stubber-1.20.4.dist-info}/WHEEL +1 -1
- mpflash/README.md +16 -5
- mpflash/mpflash/add_firmware.py +98 -0
- mpflash/mpflash/ask_input.py +97 -120
- mpflash/mpflash/cli_download.py +42 -25
- mpflash/mpflash/cli_flash.py +70 -32
- mpflash/mpflash/cli_group.py +17 -14
- mpflash/mpflash/cli_list.py +39 -3
- mpflash/mpflash/cli_main.py +17 -6
- mpflash/mpflash/common.py +125 -12
- mpflash/mpflash/config.py +12 -0
- mpflash/mpflash/connected.py +74 -0
- mpflash/mpflash/download.py +132 -51
- mpflash/mpflash/downloaded.py +36 -15
- mpflash/mpflash/flash.py +2 -2
- mpflash/mpflash/flash_esp.py +2 -2
- mpflash/mpflash/flash_uf2.py +14 -8
- mpflash/mpflash/flash_uf2_boardid.py +2 -1
- mpflash/mpflash/flash_uf2_linux.py +5 -16
- mpflash/mpflash/flash_uf2_macos.py +37 -0
- mpflash/mpflash/flash_uf2_windows.py +5 -5
- mpflash/mpflash/list.py +57 -57
- mpflash/mpflash/mpboard_id/__init__.py +41 -44
- mpflash/mpflash/mpboard_id/add_boards.py +255 -0
- mpflash/mpflash/mpboard_id/board.py +37 -0
- mpflash/mpflash/mpboard_id/board_id.py +54 -34
- mpflash/mpflash/mpboard_id/board_info.zip +0 -0
- mpflash/mpflash/mpboard_id/store.py +43 -0
- mpflash/mpflash/mpremoteboard/__init__.py +18 -6
- mpflash/mpflash/uf2disk.py +12 -0
- mpflash/mpflash/vendor/basicgit.py +288 -0
- mpflash/mpflash/vendor/dfu.py +1 -0
- mpflash/mpflash/vendor/versions.py +7 -3
- mpflash/mpflash/worklist.py +71 -48
- mpflash/poetry.lock +164 -138
- mpflash/pyproject.toml +18 -15
- stubber/__init__.py +1 -1
- stubber/board/createstubs.py +13 -3
- stubber/board/createstubs_db.py +5 -7
- stubber/board/createstubs_db_min.py +329 -825
- stubber/board/createstubs_db_mpy.mpy +0 -0
- stubber/board/createstubs_mem.py +6 -7
- stubber/board/createstubs_mem_min.py +304 -765
- stubber/board/createstubs_mem_mpy.mpy +0 -0
- stubber/board/createstubs_min.py +293 -975
- stubber/board/createstubs_mpy.mpy +0 -0
- stubber/board/modulelist.txt +10 -0
- stubber/commands/get_core_cmd.py +7 -6
- stubber/commands/get_docstubs_cmd.py +8 -3
- stubber/commands/get_frozen_cmd.py +5 -2
- stubber/publish/publish.py +18 -7
- stubber/update_module_list.py +2 -24
- stubber/utils/makeversionhdr.py +3 -2
- stubber/utils/versions.py +2 -1
- mpflash/mpflash/mpboard_id/board_info.csv +0 -2213
- mpflash/mpflash/mpboard_id/board_info.json +0 -19910
- {micropython_stubber-1.20.1.dist-info → micropython_stubber-1.20.4.dist-info}/LICENSE +0 -0
- {micropython_stubber-1.20.1.dist-info → micropython_stubber-1.20.4.dist-info}/entry_points.txt +0 -0
@@ -3,64 +3,84 @@ Translate board description to board designator
|
|
3
3
|
"""
|
4
4
|
|
5
5
|
import functools
|
6
|
-
import json
|
7
6
|
from pathlib import Path
|
8
7
|
from typing import Optional
|
9
8
|
|
10
9
|
from mpflash.errors import MPFlashError
|
11
|
-
from mpflash.
|
10
|
+
from mpflash.logger import log
|
11
|
+
from mpflash.mpboard_id.store import read_known_boardinfo
|
12
|
+
from mpflash.vendor.versions import clean_version, get_stable_mp_version
|
12
13
|
|
13
|
-
###############################################################################################
|
14
|
-
HERE = Path(__file__).parent
|
15
|
-
###############################################################################################
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def find_board_id_by_description(
|
16
|
+
descr: str,
|
17
|
+
short_descr: str,
|
18
|
+
*,
|
19
|
+
version: str,
|
20
|
+
board_info: Optional[Path] = None,
|
20
21
|
) -> Optional[str]:
|
21
22
|
"""Find the MicroPython BOARD_ID based on the description in the firmware"""
|
23
|
+
|
22
24
|
try:
|
23
|
-
boards =
|
25
|
+
boards = _find_board_id_by_description(
|
24
26
|
descr=descr,
|
25
27
|
short_descr=short_descr,
|
26
28
|
board_info=board_info,
|
27
|
-
version=clean_version(version),
|
29
|
+
version=clean_version(version) if version else None,
|
28
30
|
)
|
29
|
-
return boards[-1]
|
31
|
+
return boards[-1].board_id
|
30
32
|
except MPFlashError:
|
31
33
|
return "UNKNOWN_BOARD"
|
32
34
|
|
33
35
|
|
34
36
|
@functools.lru_cache(maxsize=20)
|
35
|
-
def
|
37
|
+
def _find_board_id_by_description(
|
38
|
+
*,
|
39
|
+
descr: str,
|
40
|
+
short_descr: str,
|
41
|
+
version: Optional[str] = None,
|
42
|
+
board_info: Optional[Path] = None,
|
43
|
+
):
|
36
44
|
"""
|
37
45
|
Find the MicroPython BOARD_ID based on the description in the firmware
|
38
46
|
using the pre-built board_info.json file
|
47
|
+
|
48
|
+
Parameters:
|
49
|
+
descr: str
|
50
|
+
Description of the board
|
51
|
+
short_descr: str
|
52
|
+
Short description of the board (optional)
|
53
|
+
version: str
|
54
|
+
Version of the MicroPython firmware
|
55
|
+
board_info: Path
|
56
|
+
Path to the board_info.json file (optional)
|
57
|
+
|
39
58
|
"""
|
40
|
-
|
41
|
-
|
42
|
-
if not board_info.exists():
|
43
|
-
raise FileNotFoundError(f"Board info file not found: {board_info}")
|
59
|
+
# FIXME: functional overlap with
|
60
|
+
# src\mpflash\mpflash\mpboard_id\__init__.py find_known_board
|
44
61
|
|
45
|
-
|
62
|
+
if not short_descr and " with " in descr:
|
63
|
+
short_descr = descr.split(" with ")[0]
|
46
64
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
65
|
+
candidate_boards = read_known_boardinfo(board_info)
|
66
|
+
|
67
|
+
if version:
|
68
|
+
# filter for matching version
|
69
|
+
if version in ("preview", "stable"):
|
70
|
+
# match last stable
|
71
|
+
version = get_stable_mp_version()
|
72
|
+
known_versions = sorted({b.version for b in candidate_boards})
|
73
|
+
if version not in known_versions:
|
74
|
+
# FIXME if latest stable is newer than the last version in the boardlist this will fail
|
75
|
+
log.trace(f"Version {version} not found in board info, using latest known version {known_versions[-1]}")
|
76
|
+
version = known_versions[-1]
|
77
|
+
if version_matches := [b for b in candidate_boards if b.version.startswith(version)]:
|
78
|
+
candidate_boards = version_matches
|
79
|
+
else:
|
80
|
+
raise MPFlashError(f"No board info found for version {version}")
|
81
|
+
matches = [b for b in candidate_boards if b.description == descr]
|
55
82
|
if not matches and short_descr:
|
56
|
-
matches = [b for b in
|
83
|
+
matches = [b for b in candidate_boards if b.description == short_descr]
|
57
84
|
if not matches:
|
58
85
|
raise MPFlashError(f"No board info found for description '{descr}' or '{short_descr}'")
|
59
|
-
return sorted(matches, key=lambda x: x
|
60
|
-
|
61
|
-
|
62
|
-
@functools.lru_cache(maxsize=20)
|
63
|
-
def _read_board_info(board_info):
|
64
|
-
with open(board_info, "r") as file:
|
65
|
-
info = json.load(file)
|
66
|
-
return info
|
86
|
+
return sorted(matches, key=lambda x: x.version)
|
Binary file
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import functools
|
2
|
+
import zipfile
|
3
|
+
from pathlib import Path
|
4
|
+
from typing import List, Optional
|
5
|
+
|
6
|
+
import jsons
|
7
|
+
|
8
|
+
from mpflash.mpboard_id.board import Board
|
9
|
+
|
10
|
+
###############################################################################################
|
11
|
+
HERE = Path(__file__).parent
|
12
|
+
###############################################################################################
|
13
|
+
|
14
|
+
|
15
|
+
def write_boardinfo_json(board_list: List[Board], *, folder: Path):
|
16
|
+
"""Writes the board information to a JSON file.
|
17
|
+
|
18
|
+
Args:
|
19
|
+
board_list (List[Board]): The list of Board objects.
|
20
|
+
folder (Path): The folder where the compressed JSON file will be saved.
|
21
|
+
"""
|
22
|
+
import zipfile
|
23
|
+
|
24
|
+
# create a zip file with the json file
|
25
|
+
with zipfile.ZipFile(folder / "board_info.zip", "w", compression=zipfile.ZIP_DEFLATED) as zipf:
|
26
|
+
# write the list to json file inside the zip
|
27
|
+
with zipf.open("board_info.json", "w") as fp:
|
28
|
+
fp.write(jsons.dumps(board_list, jdkwargs={"indent": 4}).encode())
|
29
|
+
|
30
|
+
|
31
|
+
@functools.lru_cache(maxsize=20)
|
32
|
+
def read_known_boardinfo(board_info: Optional[Path] = None) -> List[Board]:
|
33
|
+
|
34
|
+
if not board_info:
|
35
|
+
board_info = HERE / "board_info.zip"
|
36
|
+
if not board_info.exists():
|
37
|
+
raise FileNotFoundError(f"Board info file not found: {board_info}")
|
38
|
+
|
39
|
+
with zipfile.ZipFile(board_info, "r") as zf:
|
40
|
+
with zf.open("board_info.json", "r") as file:
|
41
|
+
info = jsons.loads(file.read().decode(encoding="utf-8"), List[Board])
|
42
|
+
|
43
|
+
return info
|
@@ -13,7 +13,7 @@ from rich.progress import track
|
|
13
13
|
from tenacity import retry, stop_after_attempt, wait_fixed
|
14
14
|
|
15
15
|
from mpflash.errors import MPFlashError
|
16
|
-
from mpflash.mpboard_id.board_id import
|
16
|
+
from mpflash.mpboard_id.board_id import find_board_id_by_description
|
17
17
|
from mpflash.mpremoteboard.runner import run
|
18
18
|
|
19
19
|
###############################################################################################
|
@@ -64,7 +64,7 @@ class MPRemoteBoard:
|
|
64
64
|
return f"MPRemoteBoard({self.serialport}, {self.family} {self.port}, {self.board}, {self.version})"
|
65
65
|
|
66
66
|
@staticmethod
|
67
|
-
def connected_boards(bluetooth: bool = False) -> List[str]:
|
67
|
+
def connected_boards(bluetooth: bool = False, description: bool = False) -> List[str]:
|
68
68
|
# TODO: rename to connected_comports
|
69
69
|
"""
|
70
70
|
Get a list of connected comports.
|
@@ -81,8 +81,19 @@ class MPRemoteBoard:
|
|
81
81
|
# filter out bluetooth ports
|
82
82
|
comports = [p for p in comports if "bluetooth" not in p.description.lower()]
|
83
83
|
comports = [p for p in comports if "BTHENUM" not in p.hwid]
|
84
|
-
|
85
|
-
|
84
|
+
if description:
|
85
|
+
output = [
|
86
|
+
f"{p.device} {(p.manufacturer + ' ') if p.manufacturer and not p.description.startswith(p.manufacturer) else ''}{p.description}"
|
87
|
+
for p in comports
|
88
|
+
]
|
89
|
+
else:
|
90
|
+
output = [p.device for p in comports]
|
91
|
+
|
92
|
+
if sys.platform == "win32":
|
93
|
+
# Windows sort of comports by number - but fallback to device name
|
94
|
+
return sorted(output, key=lambda x: int(x.split()[0][3:]) if x.split()[0][3:].isdigit() else x)
|
95
|
+
# sort by device name
|
96
|
+
return sorted(output)
|
86
97
|
|
87
98
|
@retry(stop=stop_after_attempt(RETRIES), wait=wait_fixed(1), reraise=True) # type: ignore ## retry_error_cls=ConnectionError,
|
88
99
|
def get_mcu_info(self, timeout: int = 2):
|
@@ -116,10 +127,10 @@ class MPRemoteBoard:
|
|
116
127
|
self.description = descr = info["board"]
|
117
128
|
pos = descr.rfind(" with")
|
118
129
|
short_descr = descr[:pos].strip() if pos != -1 else ""
|
119
|
-
if board_name :=
|
130
|
+
if board_name := find_board_id_by_description(descr, short_descr, version=self.version):
|
120
131
|
self.board = board_name
|
121
132
|
else:
|
122
|
-
self.board = "
|
133
|
+
self.board = "UNKNOWN_BOARD"
|
123
134
|
|
124
135
|
def disconnect(self) -> bool:
|
125
136
|
"""
|
@@ -200,6 +211,7 @@ class MPRemoteBoard:
|
|
200
211
|
transient=True,
|
201
212
|
get_time=lambda: time.time(),
|
202
213
|
show_speed=False,
|
214
|
+
refresh_per_second=1,
|
203
215
|
):
|
204
216
|
time.sleep(1)
|
205
217
|
try:
|
@@ -0,0 +1,12 @@
|
|
1
|
+
"""Info to support mounting and unmounting of UF2 drives on linux and macos"""
|
2
|
+
|
3
|
+
|
4
|
+
class UF2Disk:
|
5
|
+
"""Info to support mounting and unmounting of UF2 drives on linux"""
|
6
|
+
|
7
|
+
device_path: str
|
8
|
+
label: str
|
9
|
+
mountpoint: str
|
10
|
+
|
11
|
+
def __repr__(self):
|
12
|
+
return repr(self.__dict__)
|
@@ -0,0 +1,288 @@
|
|
1
|
+
"""
|
2
|
+
Simple Git module, where needed via powershell
|
3
|
+
|
4
|
+
Some of the functions are based on the PyGithub module
|
5
|
+
"""
|
6
|
+
|
7
|
+
import os
|
8
|
+
import subprocess
|
9
|
+
from pathlib import Path
|
10
|
+
from typing import List, Optional, Union
|
11
|
+
|
12
|
+
import cachetools.func
|
13
|
+
from github import Auth, Github
|
14
|
+
from loguru import logger as log
|
15
|
+
from packaging.version import parse
|
16
|
+
|
17
|
+
# from stubber.utils.versions import SET_PREVIEW
|
18
|
+
|
19
|
+
# Token with no permissions to avoid throttling
|
20
|
+
# https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#getting-a-higher-rate-limit
|
21
|
+
PAT_NO_ACCESS = (
|
22
|
+
"github_pat" + "_11AAHPVFQ0qAkDnSUaMKSp" + "_ZkDl5NRRwBsUN6EYg9ahp1Dvj4FDDONnXVgimxC2EtpY7Q7BUKBoQ0Jq72X"
|
23
|
+
)
|
24
|
+
PAT = os.environ.get("GITHUB_TOKEN") or PAT_NO_ACCESS
|
25
|
+
GH_CLIENT = Github(auth=Auth.Token(PAT))
|
26
|
+
|
27
|
+
|
28
|
+
def _run_local_git(
|
29
|
+
cmd: List[str],
|
30
|
+
repo: Optional[Union[Path, str]] = None,
|
31
|
+
expect_stderr=False,
|
32
|
+
capture_output=True,
|
33
|
+
echo_output=True,
|
34
|
+
):
|
35
|
+
"run a external (git) command in the repo's folder and deal with some of the errors"
|
36
|
+
try:
|
37
|
+
if repo:
|
38
|
+
if isinstance(repo, str):
|
39
|
+
repo = Path(repo)
|
40
|
+
result = subprocess.run(
|
41
|
+
cmd, capture_output=capture_output, check=True, cwd=repo.absolute().as_posix(), encoding="utf-8"
|
42
|
+
)
|
43
|
+
else:
|
44
|
+
result = subprocess.run(cmd, capture_output=capture_output, check=True, encoding="utf-8")
|
45
|
+
except (NotADirectoryError, FileNotFoundError) as e: # pragma: no cover
|
46
|
+
return None
|
47
|
+
except subprocess.CalledProcessError as e: # pragma: no cover
|
48
|
+
# add some logging for github actions
|
49
|
+
log.error(f"{str(e)} : { e.stderr}")
|
50
|
+
return None
|
51
|
+
if result.stderr and result.stderr != b"":
|
52
|
+
stderr = result.stderr
|
53
|
+
if "cloning into" in stderr.lower():
|
54
|
+
# log.info(stderr)
|
55
|
+
expect_stderr = True
|
56
|
+
if "warning" in stderr.lower():
|
57
|
+
log.warning(stderr)
|
58
|
+
expect_stderr = True
|
59
|
+
elif capture_output and echo_output: # pragma: no cover
|
60
|
+
log.info(stderr)
|
61
|
+
if not expect_stderr:
|
62
|
+
raise ChildProcessError(stderr)
|
63
|
+
|
64
|
+
if result.returncode and result.returncode < 0:
|
65
|
+
raise ChildProcessError(result.stderr)
|
66
|
+
return result
|
67
|
+
|
68
|
+
|
69
|
+
def clone(remote_repo: str, path: Path, shallow: bool = False, tag: Optional[str] = None) -> bool:
|
70
|
+
"""git clone [--depth 1] [--branch <tag_name>] <remote> <directory>"""
|
71
|
+
cmd = ["git", "clone"]
|
72
|
+
if shallow:
|
73
|
+
cmd += ["--depth", "1"]
|
74
|
+
if tag in {"preview", "latest", "master"}:
|
75
|
+
tag = None
|
76
|
+
cmd += [remote_repo, "--branch", tag, str(path)] if tag else [remote_repo, str(path)]
|
77
|
+
if result := _run_local_git(cmd, expect_stderr=True, capture_output=False):
|
78
|
+
return result.returncode == 0
|
79
|
+
else:
|
80
|
+
return False
|
81
|
+
|
82
|
+
|
83
|
+
def get_local_tag(repo: Optional[Union[str, Path]] = None, abbreviate: bool = True) -> Union[str, None]:
|
84
|
+
"""
|
85
|
+
get the most recent git version tag of a local repo
|
86
|
+
repo Path should be in the form of : repo = "./repo/micropython"
|
87
|
+
|
88
|
+
returns the tag or None
|
89
|
+
"""
|
90
|
+
if not repo:
|
91
|
+
repo = Path(".")
|
92
|
+
elif isinstance(repo, str):
|
93
|
+
repo = Path(repo)
|
94
|
+
|
95
|
+
result = _run_local_git(
|
96
|
+
# ["git", "describe", "--tags"],
|
97
|
+
["git", "describe", "--tags", "--dirty", "--always", "--match", "v[1-9].*"],
|
98
|
+
repo=repo.as_posix(),
|
99
|
+
expect_stderr=True,
|
100
|
+
)
|
101
|
+
if not result:
|
102
|
+
return None
|
103
|
+
tag: str = result.stdout
|
104
|
+
tag = tag.replace("\r", "").replace("\n", "")
|
105
|
+
if not abbreviate or "-" not in tag:
|
106
|
+
return tag
|
107
|
+
if "-preview" in tag:
|
108
|
+
tag = tag.split("-preview")[0] + "-preview"
|
109
|
+
return tag
|
110
|
+
|
111
|
+
|
112
|
+
def get_local_tags(repo: Optional[Path] = None, minver: Optional[str] = None) -> List[str]:
|
113
|
+
"""
|
114
|
+
get list of all tags of a local repo
|
115
|
+
"""
|
116
|
+
if not repo:
|
117
|
+
repo = Path(".")
|
118
|
+
|
119
|
+
result = _run_local_git(["git", "tag", "-l"], repo=repo.as_posix(), expect_stderr=True)
|
120
|
+
if not result or result.returncode != 0:
|
121
|
+
return []
|
122
|
+
tags = result.stdout.replace("\r", "").split("\n")
|
123
|
+
tags = [tag for tag in tags if tag.startswith("v")]
|
124
|
+
if minver:
|
125
|
+
tags = [tag for tag in tags if parse(tag) >= parse(minver)]
|
126
|
+
return sorted(tags)
|
127
|
+
|
128
|
+
|
129
|
+
@cachetools.func.ttl_cache(maxsize=16, ttl=60) # 60 seconds
|
130
|
+
def get_tags(repo: str, minver: Optional[str] = None) -> List[str]:
|
131
|
+
"""
|
132
|
+
Get list of tag of a repote github repo
|
133
|
+
"""
|
134
|
+
if not repo or not isinstance(repo, str) or "/" not in repo: # type: ignore
|
135
|
+
return []
|
136
|
+
try:
|
137
|
+
gh_repo = GH_CLIENT.get_repo(repo)
|
138
|
+
except ConnectionError as e:
|
139
|
+
# TODO: unable to capture the exeption
|
140
|
+
log.warning(f"Unable to get tags - {e}")
|
141
|
+
return []
|
142
|
+
tags = [tag.name for tag in gh_repo.get_tags()]
|
143
|
+
if minver:
|
144
|
+
tags = [tag for tag in tags if parse(tag) >= parse(minver)]
|
145
|
+
return sorted(tags)
|
146
|
+
|
147
|
+
|
148
|
+
def checkout_tag(tag: str, repo: Optional[Union[str, Path]] = None) -> bool:
|
149
|
+
"""
|
150
|
+
checkout a specific git tag
|
151
|
+
"""
|
152
|
+
cmd = ["git", "checkout", tag, "--quiet", "--force"]
|
153
|
+
result = _run_local_git(cmd, repo=repo, expect_stderr=True, capture_output=True)
|
154
|
+
if not result:
|
155
|
+
return False
|
156
|
+
# actually a good result
|
157
|
+
msg = {result.stdout}
|
158
|
+
if msg != {""}:
|
159
|
+
log.warning(f"git message: {msg}")
|
160
|
+
return True
|
161
|
+
|
162
|
+
|
163
|
+
def sync_submodules(repo: Optional[Union[Path, str]] = None) -> bool:
|
164
|
+
"""
|
165
|
+
make sure any submodules are in sync
|
166
|
+
"""
|
167
|
+
cmds = [
|
168
|
+
["git", "submodule", "sync", "--quiet"],
|
169
|
+
# ["git", "submodule", "update", "--quiet"],
|
170
|
+
["git", "submodule", "update", "--init", "lib/micropython-lib"],
|
171
|
+
]
|
172
|
+
for cmd in cmds:
|
173
|
+
if result := _run_local_git(cmd, repo=repo, expect_stderr=True):
|
174
|
+
# actually a good result
|
175
|
+
log.debug(result.stderr)
|
176
|
+
else:
|
177
|
+
return False
|
178
|
+
return True
|
179
|
+
|
180
|
+
|
181
|
+
def checkout_commit(commit_hash: str, repo: Optional[Union[Path, str]] = None) -> bool:
|
182
|
+
"""
|
183
|
+
Checkout a specific commit
|
184
|
+
"""
|
185
|
+
cmd = ["git", "checkout", commit_hash, "--quiet", "--force"]
|
186
|
+
result = _run_local_git(cmd, repo=repo, expect_stderr=True)
|
187
|
+
if not result:
|
188
|
+
return False
|
189
|
+
# actually a good result
|
190
|
+
log.debug(result.stderr)
|
191
|
+
return True
|
192
|
+
|
193
|
+
|
194
|
+
def switch_tag(tag: Union[str, Path], repo: Optional[Union[Path, str]] = None) -> bool:
|
195
|
+
"""
|
196
|
+
switch to the specified version tag of a local repo
|
197
|
+
repo should be in the form of : path/.git
|
198
|
+
repo = '../micropython/.git'
|
199
|
+
returns None
|
200
|
+
"""
|
201
|
+
|
202
|
+
cmd = ["git", "switch", "--detach", tag, "--quiet", "--force"]
|
203
|
+
result = _run_local_git(cmd, repo=repo, expect_stderr=True)
|
204
|
+
if not result:
|
205
|
+
return False
|
206
|
+
# actually a good result
|
207
|
+
log.debug(result.stderr)
|
208
|
+
return True
|
209
|
+
|
210
|
+
|
211
|
+
def switch_branch(branch: str, repo: Optional[Union[Path, str]] = None) -> bool:
|
212
|
+
"""
|
213
|
+
switch to the specified branch in a local repo"
|
214
|
+
repo should be in the form of : path/.git
|
215
|
+
repo = '../micropython/.git'
|
216
|
+
returns None
|
217
|
+
"""
|
218
|
+
cmd = ["git", "switch", branch, "--quiet", "--force"]
|
219
|
+
result = _run_local_git(cmd, repo=repo, expect_stderr=True)
|
220
|
+
if not result:
|
221
|
+
return False
|
222
|
+
# actually a good result
|
223
|
+
log.debug(result.stderr)
|
224
|
+
return True
|
225
|
+
|
226
|
+
|
227
|
+
def fetch(repo: Union[Path, str]) -> bool:
|
228
|
+
"""
|
229
|
+
fetches a repo
|
230
|
+
repo should be in the form of : path/.git
|
231
|
+
repo = '../micropython/.git'
|
232
|
+
returns True on success
|
233
|
+
"""
|
234
|
+
if not repo:
|
235
|
+
raise NotADirectoryError
|
236
|
+
|
237
|
+
cmd = ["git", "fetch", "--all", "--tags", "--quiet"]
|
238
|
+
result = _run_local_git(cmd, repo=repo, echo_output=False)
|
239
|
+
return result.returncode == 0 if result else False
|
240
|
+
|
241
|
+
|
242
|
+
def pull(repo: Union[Path, str], branch: str = "main") -> bool:
|
243
|
+
"""
|
244
|
+
pull a repo origin into main
|
245
|
+
repo should be in the form of : path/.git
|
246
|
+
repo = '../micropython/.git'
|
247
|
+
returns True on success
|
248
|
+
"""
|
249
|
+
if not repo:
|
250
|
+
raise NotADirectoryError
|
251
|
+
repo = Path(repo)
|
252
|
+
# first checkout HEAD
|
253
|
+
cmd = ["git", "checkout", branch, "--quiet", "--force"]
|
254
|
+
result = _run_local_git(cmd, repo=repo, expect_stderr=True)
|
255
|
+
if not result:
|
256
|
+
log.error("error during git checkout main", result)
|
257
|
+
return False
|
258
|
+
|
259
|
+
cmd = ["git", "pull", "origin", branch, "--quiet", "--autostash"]
|
260
|
+
result = _run_local_git(cmd, repo=repo, expect_stderr=True)
|
261
|
+
if not result:
|
262
|
+
log.error("error durign pull", result)
|
263
|
+
return False
|
264
|
+
return result.returncode == 0
|
265
|
+
|
266
|
+
|
267
|
+
def get_git_describe(folder: Optional[str] = None):
|
268
|
+
"""
|
269
|
+
Based on MicroPython makeversionhdr.py
|
270
|
+
returns : current git tag, commits ,commit hash : "v1.19.1-841-g3446"
|
271
|
+
"""
|
272
|
+
# Note: git describe doesn't work if no tag is available
|
273
|
+
try:
|
274
|
+
git_describe = subprocess.check_output(
|
275
|
+
["git", "describe", "--tags", "--dirty", "--always", "--match", "v[1-9].*"],
|
276
|
+
stderr=subprocess.STDOUT,
|
277
|
+
universal_newlines=True,
|
278
|
+
cwd=folder,
|
279
|
+
).strip()
|
280
|
+
except subprocess.CalledProcessError as er:
|
281
|
+
if er.returncode == 128:
|
282
|
+
# git exit code of 128 means no repository found
|
283
|
+
return None
|
284
|
+
git_describe = ""
|
285
|
+
except OSError:
|
286
|
+
return None
|
287
|
+
# format
|
288
|
+
return git_describe
|
mpflash/mpflash/vendor/dfu.py
CHANGED
@@ -9,6 +9,8 @@ from functools import lru_cache
|
|
9
9
|
from loguru import logger as log
|
10
10
|
from packaging.version import parse
|
11
11
|
|
12
|
+
from mpflash.common import GH_CLIENT
|
13
|
+
|
12
14
|
V_PREVIEW = "preview"
|
13
15
|
"Latest preview version"
|
14
16
|
|
@@ -67,12 +69,12 @@ def clean_version(
|
|
67
69
|
|
68
70
|
|
69
71
|
@lru_cache(maxsize=10)
|
70
|
-
def micropython_versions(minver: str = "v1.20"):
|
72
|
+
def micropython_versions(minver: str = "v1.20", reverse: bool = False):
|
71
73
|
"""Get the list of micropython versions from github tags"""
|
72
74
|
try:
|
73
75
|
gh_client = GH_CLIENT
|
74
76
|
repo = gh_client.get_repo("micropython/micropython")
|
75
|
-
versions = [tag.name for tag in repo.get_tags()
|
77
|
+
versions = [tag.name for tag in repo.get_tags()]
|
76
78
|
except Exception:
|
77
79
|
versions = [
|
78
80
|
"v9.99.9-preview",
|
@@ -94,7 +96,9 @@ def micropython_versions(minver: str = "v1.20"):
|
|
94
96
|
"v1.11",
|
95
97
|
"v1.10",
|
96
98
|
]
|
97
|
-
|
99
|
+
versions = [v for v in versions if parse(v) >= parse(minver)]
|
100
|
+
# remove all but the most recent (preview) version
|
101
|
+
versions = versions[:1] + [v for v in versions if "preview" not in v]
|
98
102
|
return sorted(versions)
|
99
103
|
|
100
104
|
|