Skip to content

Commit 93fc3e3

Browse files
committed
stubber: add enrich option to enhance docstub generation with type information
Signed-off-by: Jos Verlinde <[email protected]>
1 parent f744d60 commit 93fc3e3

File tree

3 files changed

+5551
-339
lines changed

3 files changed

+5551
-339
lines changed

WIP.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@
66
- [ ] pypi
77
- [x] Test v1.23.0 stubs with new stdib ( avoid regressions )
88
- [x] do the same for v1.24.1 stubs
9-
- [ ] If needed publish update to v1.23.0 stubs to only allow stdlib v1.23.x
9+
- [?] If needed publish update to v1.23.0 stubs to only allow stdlib v1.23.x
1010

11-
- [ ] Update install example in stubs readme for v1.24.*
1211
- [x] some decorators are added multiple times - need to check for existing decorator
13-
- [ ] docstubs : should automagically enrich the docstubs
12+
- [x] docstubs : should automagically `--enrich` the docstubs on v1.24.1 and newer ( + CI)
13+
- [ ] publish stubber
14+
15+
1416

1517
- [x] `__call__` needs addational overloads in machine and pyb modules
16-
- [ ] stdlib/udate.py should use same config as stubber / merge_config
17-
- [ ] stdlib/udate.py should allow configuration of version
18+
- [x] stdlib/udate.py should allow configuration of version
19+
- [ ] stdlib/udate.py should use same config as stubber
20+
- [x] uses config / pyproject.toml
21+
- [ ] uses merge_config
1822

23+
24+
- [ ] Update install example in stubs readme for v1.24.*
1925
- [ ] Update the documentation for this.
2026
- MyPy change
2127
- how to install
@@ -36,6 +42,10 @@
3642

3743

3844
# Longer term things to fix
45+
- [ ] generate badges for the stubs
46+
https://github.com/python/typing/discussions/1391
47+
![PyPI - Types](https://img.shields.io/pypi/types/micropython-esp32-stubs?style=plastic&label=esp32%20generic-S3)
48+
3949

4050
## pyright:
4151

src/stubber/commands/get_docstubs_cmd.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
from pathlib import Path
77
from typing import Optional
8+
from packaging.version import Version
89

910
import mpflash.basicgit as git
1011
import rich_click as click
1112
from mpflash.logger import log
1213

14+
from stubber.codemod.enrich import enrich_folder
1315
import stubber.utils as utils
1416
from stubber.commands.cli import stubber_cli
1517
from stubber.stubs_from_docs import generate_from_rst
@@ -59,6 +61,13 @@
5961
help="remove .rST constructs from the docstrings",
6062
show_default=True,
6163
)
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+
)
6271
@click.pass_context
6372
def cli_docstubs(
6473
ctx: click.Context,
@@ -69,6 +78,7 @@ def cli_docstubs(
6978
clean_rst: bool = True,
7079
basename: Optional[str] = None,
7180
version: str = "",
81+
enrich: bool = False,
7282
):
7383
"""
7484
Build stubs from documentation.
@@ -113,4 +123,24 @@ def cli_docstubs(
113123
autoflake=autoflake,
114124
clean_rst=clean_rst,
115125
)
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+
116146
log.info("::group:: Done")

0 commit comments

Comments
 (0)