micropython-stubber 1.23.2__py3-none-any.whl → 1.24.0__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.2.dist-info → micropython_stubber-1.24.0.dist-info}/METADATA +30 -12
- {micropython_stubber-1.23.2.dist-info → micropython_stubber-1.24.0.dist-info}/RECORD +69 -66
- {micropython_stubber-1.23.2.dist-info → micropython_stubber-1.24.0.dist-info}/WHEEL +1 -1
- mpflash/README.md +2 -2
- mpflash/mpflash/basicgit.py +49 -9
- mpflash/mpflash/common.py +23 -16
- mpflash/mpflash/downloaded.py +10 -2
- mpflash/mpflash/mpboard_id/__init__.py +9 -4
- mpflash/mpflash/mpboard_id/add_boards.py +25 -14
- mpflash/mpflash/mpboard_id/board.py +2 -2
- mpflash/mpflash/mpboard_id/board_id.py +10 -6
- mpflash/mpflash/mpboard_id/board_info.zip +0 -0
- mpflash/mpflash/mpboard_id/store.py +8 -3
- mpflash/mpflash/mpremoteboard/__init__.py +13 -8
- mpflash/mpflash/mpremoteboard/mpy_fw_info.py +27 -16
- mpflash/mpflash/vendor/board_database.py +185 -0
- mpflash/mpflash/vendor/readme.md +10 -1
- mpflash/mpflash/versions.py +28 -40
- mpflash/poetry.lock +1605 -601
- mpflash/pyproject.toml +4 -3
- stubber/__init__.py +1 -1
- stubber/board/createstubs.py +51 -27
- stubber/board/createstubs_db.py +36 -28
- stubber/board/createstubs_db_min.py +171 -165
- stubber/board/createstubs_db_mpy.mpy +0 -0
- stubber/board/createstubs_mem.py +36 -28
- stubber/board/createstubs_mem_min.py +184 -178
- stubber/board/createstubs_mem_mpy.mpy +0 -0
- stubber/board/createstubs_min.py +102 -94
- stubber/board/createstubs_mpy.mpy +0 -0
- stubber/board/modulelist.txt +16 -0
- stubber/codemod/enrich.py +297 -88
- stubber/codemod/merge_docstub.py +250 -65
- stubber/codemod/test_enrich.py +87 -0
- stubber/codemod/visitors/typevars.py +200 -0
- stubber/commands/build_cmd.py +16 -3
- stubber/commands/clone_cmd.py +3 -3
- stubber/commands/config_cmd.py +4 -2
- stubber/commands/enrich_folder_cmd.py +33 -21
- stubber/commands/get_core_cmd.py +1 -2
- stubber/commands/get_docstubs_cmd.py +60 -6
- stubber/commands/get_frozen_cmd.py +15 -12
- stubber/commands/get_mcu_cmd.py +3 -3
- stubber/commands/merge_cmd.py +1 -2
- stubber/commands/publish_cmd.py +19 -4
- stubber/commands/stub_cmd.py +3 -3
- stubber/commands/switch_cmd.py +3 -5
- stubber/commands/variants_cmd.py +3 -3
- stubber/cst_transformer.py +52 -17
- stubber/freeze/common.py +27 -11
- stubber/freeze/freeze_manifest_2.py +8 -1
- stubber/freeze/get_frozen.py +4 -1
- stubber/merge_config.py +111 -0
- stubber/minify.py +1 -2
- stubber/publish/database.py +51 -10
- stubber/publish/merge_docstubs.py +33 -16
- stubber/publish/package.py +32 -18
- stubber/publish/publish.py +8 -8
- stubber/publish/stubpackage.py +110 -47
- stubber/rst/lookup.py +205 -43
- stubber/rst/reader.py +106 -59
- stubber/rst/rst_utils.py +24 -11
- stubber/stubber.py +1 -1
- stubber/stubs_from_docs.py +31 -13
- stubber/update_module_list.py +2 -2
- stubber/utils/config.py +33 -13
- stubber/utils/post.py +9 -6
- stubber/publish/missing_class_methods.py +0 -51
- {micropython_stubber-1.23.2.dist-info → micropython_stubber-1.24.0.dist-info}/LICENSE +0 -0
- {micropython_stubber-1.23.2.dist-info → micropython_stubber-1.24.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,200 @@
|
|
1
|
+
"""
|
2
|
+
Gather all TypeVar and TypeAlias assignments in a module.
|
3
|
+
"""
|
4
|
+
|
5
|
+
from typing import List, Tuple, Union
|
6
|
+
|
7
|
+
import libcst
|
8
|
+
import libcst.matchers as m
|
9
|
+
from libcst import SimpleStatementLine
|
10
|
+
from libcst.codemod._context import CodemodContext
|
11
|
+
from libcst.codemod._visitor import ContextAwareTransformer, ContextAwareVisitor
|
12
|
+
from libcst.codemod.visitors._add_imports import _skip_first
|
13
|
+
from mpflash.logger import log
|
14
|
+
|
15
|
+
_mod = libcst.parse_module("") # Debugging aid : _mod.code_for_node(node)
|
16
|
+
_code = _mod.code_for_node # Debugging aid : _code(node)
|
17
|
+
|
18
|
+
|
19
|
+
class GatherTypeVarsVisitor(ContextAwareVisitor):
|
20
|
+
"""
|
21
|
+
A class for tracking visited TypeVars and TypeAliases.
|
22
|
+
"""
|
23
|
+
|
24
|
+
def __init__(self, context: CodemodContext) -> None:
|
25
|
+
super().__init__(context)
|
26
|
+
# Track all of the TypeVar assignments found in this transform
|
27
|
+
self.all_typealias_or_vars: List[Union[libcst.Assign, libcst.AnnAssign]] = []
|
28
|
+
|
29
|
+
def visit_Assign(self, node: libcst.Assign) -> None:
|
30
|
+
"""
|
31
|
+
Find all TypeVar assignments in the module.
|
32
|
+
format: T = TypeVar("T", int, float, str, bytes, Tuple)
|
33
|
+
"""
|
34
|
+
# is this a TypeVar assignment?
|
35
|
+
# needs to be more robust
|
36
|
+
if isinstance(node.value, libcst.Call) and node.value.func.value == "TypeVar": # type: ignore
|
37
|
+
self.all_typealias_or_vars.append(node)
|
38
|
+
|
39
|
+
def visit_AnnAssign(self, node: libcst.AnnAssign) -> None:
|
40
|
+
""" "
|
41
|
+
Find all TypeAlias assignments in the module.
|
42
|
+
format: T: TypeAlias = str
|
43
|
+
"""
|
44
|
+
if (
|
45
|
+
isinstance(node.annotation.annotation, libcst.Name)
|
46
|
+
and node.annotation.annotation.value == "TypeAlias"
|
47
|
+
):
|
48
|
+
self.all_typealias_or_vars.append(node)
|
49
|
+
|
50
|
+
|
51
|
+
def is_TypeAlias(statement) -> bool:
|
52
|
+
"Just the body of a simple statement" ""
|
53
|
+
return m.matches(
|
54
|
+
statement,
|
55
|
+
m.AnnAssign(annotation=m.Annotation(annotation=m.Name(value="TypeAlias"))),
|
56
|
+
)
|
57
|
+
|
58
|
+
|
59
|
+
def is_TypeVar(statement):
|
60
|
+
"Just the body of a simple statement" ""
|
61
|
+
r = m.matches(
|
62
|
+
statement,
|
63
|
+
m.Assign(value=m.Call(func=m.Name(value="TypeVar"))),
|
64
|
+
)
|
65
|
+
# m.SimpleStatementLine(body=[m.Assign(value=m.Call(func=m.Name(value="TypeVar")))]),
|
66
|
+
return r
|
67
|
+
|
68
|
+
|
69
|
+
class AddTypeVarsVisitor(ContextAwareTransformer):
|
70
|
+
"""
|
71
|
+
Visitor loosly based on AddImportsVisitor
|
72
|
+
"""
|
73
|
+
|
74
|
+
CONTEXT_KEY = "AddTypeVarsVisitor"
|
75
|
+
|
76
|
+
def __init__(self, context: CodemodContext) -> None:
|
77
|
+
super().__init__(context)
|
78
|
+
self.new_typealias_or_vars: List[Union[libcst.Assign, libcst.AnnAssign]] = (
|
79
|
+
context.scratch.get(self.CONTEXT_KEY, [])
|
80
|
+
)
|
81
|
+
|
82
|
+
self.all_typealias_or_vars: List[Union[libcst.Assign, libcst.AnnAssign]] = []
|
83
|
+
|
84
|
+
@classmethod
|
85
|
+
def add_typevar(cls, context: CodemodContext, node: libcst.Assign):
|
86
|
+
new_typealias_or_vars = context.scratch.get(cls.CONTEXT_KEY, [])
|
87
|
+
new_typealias_or_vars.append(node)
|
88
|
+
context.scratch[cls.CONTEXT_KEY] = new_typealias_or_vars
|
89
|
+
# add the typevar to the module
|
90
|
+
|
91
|
+
def leave_Module(
|
92
|
+
self,
|
93
|
+
original_node: libcst.Module,
|
94
|
+
updated_node: libcst.Module,
|
95
|
+
) -> libcst.Module:
|
96
|
+
|
97
|
+
if not self.new_typealias_or_vars:
|
98
|
+
return updated_node
|
99
|
+
|
100
|
+
# split the module into 3 parts
|
101
|
+
# before and after the insertions point , and a list of the TV and TA statements
|
102
|
+
(
|
103
|
+
statements_before,
|
104
|
+
statements_after,
|
105
|
+
tv_ta_statements,
|
106
|
+
) = self._split_module(original_node, updated_node)
|
107
|
+
|
108
|
+
# TODO: avoid duplication of TypeVars and TypeAliases
|
109
|
+
statements_to_add = []
|
110
|
+
for new_tvta in self.new_typealias_or_vars:
|
111
|
+
existing = False
|
112
|
+
for existing_line in tv_ta_statements:
|
113
|
+
try:
|
114
|
+
existing_tv = existing_line.body[0] # type: ignore
|
115
|
+
except (TypeError, IndexError):
|
116
|
+
# catch 'SimpleStatementLine' object is not subscriptable when the statement is not a simple statement
|
117
|
+
log.error("TypeVar or TypeAlias statement is not a simple statement")
|
118
|
+
continue
|
119
|
+
|
120
|
+
# same type and same target?
|
121
|
+
if (
|
122
|
+
is_TypeAlias(new_tvta)
|
123
|
+
and is_TypeAlias(existing_tv)
|
124
|
+
and new_tvta.target.value == existing_tv.target.value # type: ignore
|
125
|
+
):
|
126
|
+
existing = True
|
127
|
+
break
|
128
|
+
|
129
|
+
# same type and same targets?
|
130
|
+
if (
|
131
|
+
is_TypeVar(new_tvta)
|
132
|
+
and is_TypeVar(existing_tv)
|
133
|
+
and new_tvta.targets[0].children[0].value == existing_tv.targets[0].children[0].value # type: ignore
|
134
|
+
):
|
135
|
+
existing = True
|
136
|
+
break
|
137
|
+
|
138
|
+
if not existing:
|
139
|
+
statements_to_add.append(SimpleStatementLine(body=[new_tvta]))
|
140
|
+
|
141
|
+
body = (
|
142
|
+
*statements_before,
|
143
|
+
*statements_to_add,
|
144
|
+
*statements_after,
|
145
|
+
)
|
146
|
+
|
147
|
+
return updated_node.with_changes(body=body)
|
148
|
+
|
149
|
+
def _split_module(
|
150
|
+
self,
|
151
|
+
orig_module: libcst.Module,
|
152
|
+
updated_module: libcst.Module,
|
153
|
+
) -> Tuple[
|
154
|
+
List[Union[libcst.SimpleStatementLine, libcst.BaseCompoundStatement]],
|
155
|
+
List[Union[libcst.SimpleStatementLine, libcst.BaseCompoundStatement]],
|
156
|
+
List[Union[libcst.SimpleStatementLine, libcst.BaseCompoundStatement]],
|
157
|
+
]:
|
158
|
+
"""
|
159
|
+
Split the module into 3 parts:
|
160
|
+
- before any TypeAlias or TypeVar statements
|
161
|
+
- the TypeAlias and TypeVar statements
|
162
|
+
- the rest of the module after the TypeAlias and TypeVar statements
|
163
|
+
"""
|
164
|
+
last_import = first_tv_ta = last_tv_ta = -1
|
165
|
+
start = 0
|
166
|
+
if _skip_first(orig_module):
|
167
|
+
start = 1
|
168
|
+
|
169
|
+
for i, statement in enumerate(orig_module.body[start:]):
|
170
|
+
# todo: optimize to avoid multiple parses
|
171
|
+
is_imp = m.matches(
|
172
|
+
statement, m.SimpleStatementLine(body=[m.ImportFrom() | m.Import()])
|
173
|
+
)
|
174
|
+
if is_imp:
|
175
|
+
last_import = i + start
|
176
|
+
is_ta = m.matches(
|
177
|
+
statement,
|
178
|
+
m.SimpleStatementLine(
|
179
|
+
body=[
|
180
|
+
m.AnnAssign(annotation=m.Annotation(annotation=m.Name(value="TypeAlias")))
|
181
|
+
]
|
182
|
+
),
|
183
|
+
)
|
184
|
+
is_tv = m.matches(
|
185
|
+
statement,
|
186
|
+
m.SimpleStatementLine(body=[m.Assign(value=m.Call(func=m.Name(value="TypeVar")))]),
|
187
|
+
)
|
188
|
+
if is_tv or is_ta:
|
189
|
+
if first_tv_ta == -1:
|
190
|
+
first_tv_ta = i + start
|
191
|
+
last_tv_ta = i + start
|
192
|
+
# insert as high as possible, but after the last import and last TypeVar/TypeAlias statement
|
193
|
+
insert_after = max(start, last_import + 1, last_tv_ta + 1)
|
194
|
+
assert insert_after != -1, "insert_after must be != -1"
|
195
|
+
#
|
196
|
+
first = list(updated_module.body[:insert_after])
|
197
|
+
last = list(updated_module.body[insert_after:])
|
198
|
+
ta_statements = list(updated_module.body[first_tv_ta : last_tv_ta + 1])
|
199
|
+
|
200
|
+
return (first, last, ta_statements)
|
stubber/commands/build_cmd.py
CHANGED
@@ -4,7 +4,8 @@ from typing import List, Union
|
|
4
4
|
|
5
5
|
import rich_click as click
|
6
6
|
from mpflash.logger import log
|
7
|
-
from
|
7
|
+
from rich.console import Console
|
8
|
+
from rich.table import Table
|
8
9
|
|
9
10
|
from stubber.commands.cli import stubber_cli
|
10
11
|
from stubber.publish.defaults import GENERIC_U
|
@@ -77,7 +78,6 @@ def cli_build(
|
|
77
78
|
"Multiple versions are not supported yet\n See https://github.com/Josverl/micropython-stubber/issues/487"
|
78
79
|
)
|
79
80
|
|
80
|
-
# db = get_database(publish_path=CONFIG.publish_path, production=production)
|
81
81
|
log.info(f"Build {family} {versions} {ports} {boards}")
|
82
82
|
|
83
83
|
results = build_multiple(
|
@@ -91,4 +91,17 @@ def cli_build(
|
|
91
91
|
)
|
92
92
|
# log the number of results with no error
|
93
93
|
log.info(f"Built {len([r for r in results if not r['error']])} stub packages")
|
94
|
-
|
94
|
+
console = Console()
|
95
|
+
if not results:
|
96
|
+
console.print("No results to publish")
|
97
|
+
return
|
98
|
+
table = Table(title="Build Results", show_header=True, header_style="bold magenta")
|
99
|
+
|
100
|
+
for key in results[0].keys():
|
101
|
+
table.add_column(key)
|
102
|
+
|
103
|
+
for result in results:
|
104
|
+
if result["result"] != "-":
|
105
|
+
table.add_row(*[str(result[key]) for key in result.keys()])
|
106
|
+
|
107
|
+
console.print(table)
|
stubber/commands/clone_cmd.py
CHANGED
@@ -7,12 +7,12 @@ import os
|
|
7
7
|
from pathlib import Path
|
8
8
|
from typing import List, Tuple, Union
|
9
9
|
|
10
|
-
import rich_click as click
|
11
10
|
import mpflash.basicgit as git
|
11
|
+
import rich_click as click
|
12
12
|
from mpflash.logger import log
|
13
|
-
from stubber.utils.config import CONFIG
|
14
13
|
|
15
|
-
from .cli import stubber_cli
|
14
|
+
from stubber.commands.cli import stubber_cli
|
15
|
+
from stubber.utils.config import CONFIG
|
16
16
|
|
17
17
|
##########################################################################################
|
18
18
|
# log = logging.getLogger("stubber")
|
stubber/commands/config_cmd.py
CHANGED
@@ -4,10 +4,9 @@
|
|
4
4
|
|
5
5
|
from mpflash.logger import log
|
6
6
|
|
7
|
+
from stubber.commands.cli import stubber_cli
|
7
8
|
from stubber.utils.config import CONFIG
|
8
9
|
|
9
|
-
from .cli import stubber_cli
|
10
|
-
|
11
10
|
|
12
11
|
@stubber_cli.command(name="show-config")
|
13
12
|
def cli_config():
|
@@ -27,3 +26,6 @@ def cli_config():
|
|
27
26
|
log.info(f"CONFIG.stub_path {CONFIG.stub_path}")
|
28
27
|
log.info(f"CONFIG.publish_path {CONFIG.publish_path}")
|
29
28
|
log.info(f"CONFIG.template_path {CONFIG.template_path}")
|
29
|
+
log.info(f"CONFIG.all_versions {CONFIG.all_versions}")
|
30
|
+
log.info(f"CONFIG.stable_version {CONFIG.stable_version}")
|
31
|
+
log.info(f"CONFIG.preview_version {CONFIG.preview_version}")
|
@@ -1,5 +1,5 @@
|
|
1
1
|
"""
|
2
|
-
|
2
|
+
Enrich mcu/firmware stubs with information from the docstubs
|
3
3
|
"""
|
4
4
|
|
5
5
|
from pathlib import Path
|
@@ -9,28 +9,30 @@ import rich_click as click
|
|
9
9
|
from mpflash.logger import log
|
10
10
|
|
11
11
|
from stubber.codemod.enrich import enrich_folder
|
12
|
+
from stubber.commands.cli import stubber_cli
|
12
13
|
from stubber.utils.config import CONFIG
|
13
14
|
|
14
|
-
from .cli import stubber_cli
|
15
|
-
|
16
15
|
|
17
16
|
@stubber_cli.command(name="enrich")
|
18
17
|
@click.option(
|
18
|
+
"--dest",
|
19
|
+
"--destination",
|
20
|
+
"-d",
|
19
21
|
"--stubs",
|
20
|
-
"
|
21
|
-
"stubs_folder",
|
22
|
+
"dest_folder",
|
22
23
|
default=CONFIG.stub_path.as_posix(),
|
23
24
|
type=click.Path(exists=True, file_okay=True, dir_okay=True),
|
24
|
-
help="
|
25
|
+
help="The destination file or folder containing the stubs stubs to be updated",
|
25
26
|
show_default=True,
|
26
27
|
)
|
27
28
|
@click.option(
|
29
|
+
"--source",
|
30
|
+
"-s",
|
28
31
|
"--docstubs",
|
29
|
-
"
|
30
|
-
"docstubs_folder",
|
32
|
+
"source_folder",
|
31
33
|
default=CONFIG.stub_path.as_posix(),
|
32
34
|
type=click.Path(exists=True, file_okay=True, dir_okay=True),
|
33
|
-
help="
|
35
|
+
help="The source file or folder containing the docstubs to be read",
|
34
36
|
show_default=True,
|
35
37
|
)
|
36
38
|
@click.option("--diff", default=False, help="Show diff", show_default=True, is_flag=True)
|
@@ -42,30 +44,40 @@ from .cli import stubber_cli
|
|
42
44
|
is_flag=True,
|
43
45
|
)
|
44
46
|
@click.option(
|
45
|
-
"--
|
46
|
-
"
|
47
|
-
|
48
|
-
|
49
|
-
help="Package name to be enriched (Optional)",
|
47
|
+
"--params-only",
|
48
|
+
"params_only",
|
49
|
+
default=False,
|
50
|
+
help="Copy only the parameters, not the docstrings (unless the docstring is missing)",
|
50
51
|
show_default=True,
|
52
|
+
is_flag=True,
|
51
53
|
)
|
54
|
+
# @click.option(
|
55
|
+
# "--package-name",
|
56
|
+
# "-p",
|
57
|
+
# "package_name",
|
58
|
+
# default="",
|
59
|
+
# help="Package name to be enriched (Optional)",
|
60
|
+
# show_default=True,
|
61
|
+
# )
|
52
62
|
def cli_enrich_folder(
|
53
|
-
|
54
|
-
|
63
|
+
dest_folder: Union[str, Path],
|
64
|
+
source_folder: Union[str, Path],
|
55
65
|
diff: bool = False,
|
56
66
|
dry_run: bool = False,
|
57
|
-
|
67
|
+
params_only: bool = True,
|
68
|
+
# package_name: str = "",
|
58
69
|
):
|
59
70
|
"""
|
60
71
|
Enrich the stubs in stub_folder with the docstubs in docstubs_folder.
|
61
72
|
"""
|
62
73
|
write_back = not dry_run
|
63
|
-
log.info(f"Enriching {
|
74
|
+
log.info(f"Enriching {dest_folder} with {source_folder}")
|
64
75
|
_ = enrich_folder(
|
65
|
-
Path(
|
66
|
-
Path(
|
76
|
+
Path(source_folder),
|
77
|
+
Path(dest_folder),
|
67
78
|
show_diff=diff,
|
68
79
|
write_back=write_back,
|
69
80
|
require_docstub=False,
|
70
|
-
package_name=package_name,
|
81
|
+
# package_name=package_name,
|
82
|
+
params_only=params_only,
|
71
83
|
)
|
stubber/commands/get_core_cmd.py
CHANGED
@@ -12,10 +12,9 @@ from mpflash.logger import log
|
|
12
12
|
|
13
13
|
import stubber.get_cpython as get_cpython
|
14
14
|
import stubber.utils as utils
|
15
|
+
from stubber.commands.cli import stubber_cli
|
15
16
|
from stubber.utils.config import CONFIG
|
16
17
|
|
17
|
-
from .cli import stubber_cli
|
18
|
-
|
19
18
|
##########################################################################################
|
20
19
|
# log = logging.getLogger("stubber")
|
21
20
|
#########################################################################################
|
@@ -5,18 +5,19 @@ get-docstubs
|
|
5
5
|
|
6
6
|
from pathlib import Path
|
7
7
|
from typing import Optional
|
8
|
+
from packaging.version import Version
|
8
9
|
|
10
|
+
import mpflash.basicgit as git
|
9
11
|
import rich_click as click
|
10
12
|
from mpflash.logger import log
|
11
13
|
|
12
|
-
|
14
|
+
from stubber.codemod.enrich import enrich_folder
|
13
15
|
import stubber.utils as utils
|
16
|
+
from stubber.commands.cli import stubber_cli
|
14
17
|
from stubber.stubs_from_docs import generate_from_rst
|
15
18
|
from stubber.utils.config import CONFIG
|
16
19
|
from stubber.utils.repos import fetch_repos
|
17
20
|
|
18
|
-
from .cli import stubber_cli
|
19
|
-
|
20
21
|
##########################################################################################
|
21
22
|
# log = logging.getLogger("stubber")
|
22
23
|
#########################################################################################
|
@@ -47,14 +48,37 @@ from .cli import stubber_cli
|
|
47
48
|
"--version", "--tag", default="", type=str, help="Version number to use. [default: Git tag]"
|
48
49
|
)
|
49
50
|
@click.option("--black/--no-black", "-b/-nb", default=True, help="Run black", show_default=True)
|
51
|
+
@click.option(
|
52
|
+
"--autoflake/--no-autoflake",
|
53
|
+
default=True,
|
54
|
+
help="Run autoflake to clean imports",
|
55
|
+
show_default=True,
|
56
|
+
)
|
57
|
+
@click.option(
|
58
|
+
"--clean-rst/--no-clean-rst",
|
59
|
+
"-b/-nb",
|
60
|
+
default=True,
|
61
|
+
help="remove .rST constructs from the docstrings",
|
62
|
+
show_default=True,
|
63
|
+
)
|
64
|
+
@click.option(
|
65
|
+
"--enrich",
|
66
|
+
is_flag=True,
|
67
|
+
default=False,
|
68
|
+
help="Enrich with type information from micropython-reference",
|
69
|
+
show_default=True,
|
70
|
+
)
|
50
71
|
@click.pass_context
|
51
72
|
def cli_docstubs(
|
52
73
|
ctx: click.Context,
|
53
74
|
path: Optional[str] = None,
|
54
75
|
target: Optional[str] = None,
|
55
76
|
black: bool = True,
|
77
|
+
autoflake: bool = True,
|
78
|
+
clean_rst: bool = True,
|
56
79
|
basename: Optional[str] = None,
|
57
80
|
version: str = "",
|
81
|
+
enrich: bool = False,
|
58
82
|
):
|
59
83
|
"""
|
60
84
|
Build stubs from documentation.
|
@@ -80,13 +104,43 @@ def cli_docstubs(
|
|
80
104
|
result = fetch_repos(version, CONFIG.mpy_path, CONFIG.mpy_lib_path)
|
81
105
|
if not result:
|
82
106
|
return -1
|
83
|
-
|
84
|
-
|
107
|
+
else:
|
108
|
+
# get the current checked out version
|
109
|
+
version = utils.checkedout_version(CONFIG.mpy_path)
|
85
110
|
|
86
111
|
release = git.get_local_tag(rst_path.as_posix(), abbreviate=False) or ""
|
87
112
|
|
88
113
|
dst_path = Path(target) / f"{basename}-{utils.clean_version(version, flat=True)}-docstubs"
|
89
114
|
|
90
115
|
log.info(f"Get docstubs for MicroPython {utils.clean_version(version, drop_v=False)}")
|
91
|
-
generate_from_rst(
|
116
|
+
generate_from_rst(
|
117
|
+
rst_path,
|
118
|
+
dst_path,
|
119
|
+
version,
|
120
|
+
release=release,
|
121
|
+
suffix=".pyi",
|
122
|
+
black=black,
|
123
|
+
autoflake=autoflake,
|
124
|
+
clean_rst=clean_rst,
|
125
|
+
)
|
126
|
+
|
127
|
+
if enrich:
|
128
|
+
if Version(version) < Version("1.24"):
|
129
|
+
log.warning(f"Enriching is not supported for version {version}")
|
130
|
+
else:
|
131
|
+
# !stubber enrich --params-only --source {reference} --dest {docstubs}
|
132
|
+
reference_path = CONFIG.stub_path.parent / "micropython-reference"
|
133
|
+
log.info(f"Enriching from {reference_path}")
|
134
|
+
_ = enrich_folder(
|
135
|
+
reference_path,
|
136
|
+
dst_path,
|
137
|
+
show_diff=False,
|
138
|
+
write_back=True,
|
139
|
+
require_docstub=False,
|
140
|
+
params_only=True,
|
141
|
+
)
|
142
|
+
log.info("::group:: start post processing of retrieved stubs")
|
143
|
+
# do not run stubgen
|
144
|
+
utils.do_post_processing([dst_path], stubgen=False, black=black, autoflake=autoflake)
|
145
|
+
|
92
146
|
log.info("::group:: Done")
|
@@ -7,16 +7,15 @@ from pathlib import Path
|
|
7
7
|
from typing import List, Optional
|
8
8
|
|
9
9
|
import rich_click as click
|
10
|
-
from mpflash.logger import log
|
11
10
|
|
12
11
|
import stubber.utils as utils
|
12
|
+
from mpflash.logger import log
|
13
13
|
from stubber.codemod.enrich import enrich_folder
|
14
|
+
from stubber.commands.cli import stubber_cli
|
14
15
|
from stubber.freeze.get_frozen import freeze_any
|
15
16
|
from stubber.utils.config import CONFIG
|
16
17
|
from stubber.utils.repos import fetch_repos
|
17
18
|
|
18
|
-
from .cli import stubber_cli
|
19
|
-
|
20
19
|
##########################################################################################
|
21
20
|
|
22
21
|
|
@@ -96,19 +95,23 @@ def cli_get_frozen(
|
|
96
95
|
|
97
96
|
# first create .pyi files so they can be enriched
|
98
97
|
utils.do_post_processing(stub_paths, stubgen=stubgen, black=False, autoflake=False)
|
98
|
+
|
99
99
|
family = "micropython"
|
100
100
|
_version = utils.clean_version(version, drop_v=False, flat=True)
|
101
101
|
docstubs_path = Path(CONFIG.stub_path) / f"{family}-{_version}-docstubs"
|
102
102
|
if docstubs_path.exists():
|
103
|
-
|
104
|
-
|
105
|
-
stub_path
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
103
|
+
board_folders = [f.parent for f in list(stub_path.glob("**/modules.json"))]
|
104
|
+
for folder in board_folders:
|
105
|
+
log.info(f"Enriching {str(stub_path)} with {docstubs_path}")
|
106
|
+
if merged := enrich_folder(
|
107
|
+
docstubs_path,
|
108
|
+
folder,
|
109
|
+
show_diff=False,
|
110
|
+
write_back=True,
|
111
|
+
require_docstub=False,
|
112
|
+
ext = ".pyi",
|
113
|
+
):
|
114
|
+
log.info(f" > Enriched {merged} frozen modules.")
|
112
115
|
else:
|
113
116
|
log.info(f"No docstubs found at {docstubs_path}")
|
114
117
|
|
stubber/commands/get_mcu_cmd.py
CHANGED
@@ -6,21 +6,21 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
from typing import List
|
9
|
+
|
9
10
|
import rich_click as click
|
10
11
|
from mpflash.logger import log
|
11
12
|
|
12
13
|
from stubber.bulk.mcu_stubber import stub_connected_mcus
|
14
|
+
from stubber.commands.cli import stubber_cli
|
13
15
|
from stubber.utils.config import CONFIG
|
14
16
|
|
15
|
-
from .cli import stubber_cli
|
16
|
-
|
17
17
|
##########################################################################################
|
18
18
|
# log = logging.getLogger("stubber")
|
19
19
|
#########################################################################################
|
20
20
|
|
21
21
|
|
22
22
|
@stubber_cli.command(
|
23
|
-
name="
|
23
|
+
name="mcu-stubs",
|
24
24
|
aliases=["get-mcu-stubs", "mcu-stubs", "mcu"],
|
25
25
|
)
|
26
26
|
@click.option(
|
stubber/commands/merge_cmd.py
CHANGED
@@ -7,12 +7,11 @@ from typing import List, Union
|
|
7
7
|
import rich_click as click
|
8
8
|
from mpflash.logger import log
|
9
9
|
|
10
|
+
from stubber.commands.cli import stubber_cli
|
10
11
|
from stubber.publish.merge_docstubs import merge_all_docstubs
|
11
12
|
from stubber.publish.package import GENERIC_L
|
12
13
|
from stubber.utils.config import CONFIG
|
13
14
|
|
14
|
-
from .cli import stubber_cli
|
15
|
-
|
16
15
|
|
17
16
|
@stubber_cli.command(name="merge")
|
18
17
|
@click.option("--family", default="micropython", type=str, show_default=True)
|
stubber/commands/publish_cmd.py
CHANGED
@@ -6,7 +6,8 @@ from typing import List, Union
|
|
6
6
|
|
7
7
|
import rich_click as click
|
8
8
|
from mpflash.logger import log
|
9
|
-
from
|
9
|
+
from rich.console import Console
|
10
|
+
from rich.table import Table
|
10
11
|
|
11
12
|
from stubber.commands.cli import stubber_cli
|
12
13
|
from stubber.publish.defaults import GENERIC_U
|
@@ -81,7 +82,7 @@ def cli_publish(
|
|
81
82
|
versions: Union[str, List[str]],
|
82
83
|
ports: Union[str, List[str]],
|
83
84
|
boards: Union[str, List[str]],
|
84
|
-
production: bool =
|
85
|
+
production: bool = False,
|
85
86
|
build: bool = False,
|
86
87
|
force: bool = False,
|
87
88
|
dry_run: bool = False,
|
@@ -100,7 +101,6 @@ def cli_publish(
|
|
100
101
|
"Multiple versions are not supported yet\n See https://github.com/Josverl/micropython-stubber/issues/487"
|
101
102
|
)
|
102
103
|
|
103
|
-
# db = get_database(publish_path=CONFIG.publish_path, production=production)
|
104
104
|
destination = "pypi" if production else "test-pypi"
|
105
105
|
log.info(f"Publish {family} {versions} {ports} {boards} to {destination}")
|
106
106
|
|
@@ -115,4 +115,19 @@ def cli_publish(
|
|
115
115
|
dry_run=dry_run,
|
116
116
|
clean=clean,
|
117
117
|
)
|
118
|
-
|
118
|
+
console = Console()
|
119
|
+
|
120
|
+
if not results:
|
121
|
+
console.print("No results to publish")
|
122
|
+
return
|
123
|
+
|
124
|
+
table = Table(show_header=True, header_style="bold magenta", title="Publish Results")
|
125
|
+
headers = results[0].keys()
|
126
|
+
for header in headers:
|
127
|
+
table.add_column(header)
|
128
|
+
|
129
|
+
for result in results:
|
130
|
+
if result["result"] != "-":
|
131
|
+
table.add_row(*[str(result[header]) for header in headers])
|
132
|
+
|
133
|
+
console.print(table)
|
stubber/commands/stub_cmd.py
CHANGED
@@ -4,16 +4,16 @@
|
|
4
4
|
# stub
|
5
5
|
##########################################################################################
|
6
6
|
|
7
|
-
from mpflash.logger import log
|
8
7
|
from pathlib import Path
|
9
8
|
from typing import Union
|
10
9
|
|
11
10
|
import rich_click as click
|
11
|
+
from mpflash.logger import log
|
12
|
+
|
13
|
+
from stubber.commands.cli import stubber_cli
|
12
14
|
from stubber.utils import generate_pyi_files
|
13
15
|
from stubber.utils.post import do_post_processing
|
14
16
|
|
15
|
-
from .cli import stubber_cli
|
16
|
-
|
17
17
|
##########################################################################################
|
18
18
|
# log = logging.getLogger("stubber")
|
19
19
|
#########################################################################################
|
stubber/commands/switch_cmd.py
CHANGED
@@ -6,13 +6,11 @@ from pathlib import Path
|
|
6
6
|
from typing import Optional, Union
|
7
7
|
|
8
8
|
import rich_click as click
|
9
|
+
from mpflash.versions import SET_PREVIEW, V_PREVIEW, micropython_versions
|
9
10
|
|
10
|
-
|
11
|
+
from stubber.commands.cli import stubber_cli
|
11
12
|
from stubber.utils.config import CONFIG
|
12
13
|
from stubber.utils.repos import fetch_repos, repo_paths
|
13
|
-
from mpflash.versions import SET_PREVIEW, V_PREVIEW
|
14
|
-
|
15
|
-
from .cli import stubber_cli
|
16
14
|
|
17
15
|
##########################################################################################
|
18
16
|
# log = logging.getLogger("stubber")
|
@@ -22,7 +20,7 @@ from .cli import stubber_cli
|
|
22
20
|
# get version list from Git tags in the repo that is provided on the command line
|
23
21
|
|
24
22
|
try:
|
25
|
-
VERSION_LIST =
|
23
|
+
VERSION_LIST = micropython_versions(minver="v1.9.3") + [
|
26
24
|
V_PREVIEW,
|
27
25
|
"latest",
|
28
26
|
"stable",
|