Skip to content

Commit

Permalink
Merge commit '6d90e68974390a4e24e020eb60badaab1b7cbebc'
Browse files Browse the repository at this point in the history
  • Loading branch information
Josverl committed Feb 14, 2024
2 parents 18ffb45 + 6d90e68 commit 8400a55
Show file tree
Hide file tree
Showing 41 changed files with 75 additions and 49 deletions.
14 changes: 12 additions & 2 deletions docs/50_frozen_stubs.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,19 @@ Most OSS firmwares store these frozen modules as part of their repository, which
* /GENERIC
* /PYBD_SF2


3. generate typeshed stubs of these files. (the .pyi files will be stored alongside the .py files)
3. Generate typeshed stubs of these files.
_const pre-processing:_
As the mypy.stubgen tool is not able to incur the correct types from the MicroPython `foo = const(1)` syntax,
the 'to be frozen' modules are pre-processed usig a regular expression to replace the `foo = const(1)` with `foo = 1`.
If the `.py` files contain any docstrings, they are preserved. Howecer this is uncommon as most micropython-lib modules have not docstrings to save space.

_Addition of docstrings:_
Then the docstring to modules, classes and methods are added by merging the docstrings based on the docstubs generated from the MicroPython documentation.

Finally the stubs are generated using the `stubgen` tool.
The resulting .pyi files are stored alongside the .py files


4. Include/use them in the configuration

Expand Down
2 changes: 1 addition & 1 deletion mip/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
]
],
"deps": [],
"version": "1.17.0"
"version": "1.17.1"
}
2 changes: 1 addition & 1 deletion mip/minified.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
]
],
"deps": [],
"version": "1.17.0"
"version": "1.17.1"
}
2 changes: 1 addition & 1 deletion mip/mpy_v5.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
]
],
"deps": [],
"version": "1.17.0"
"version": "1.17.1"
}
2 changes: 1 addition & 1 deletion mip/mpy_v6.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
]
],
"deps": [],
"version": "1.17.0"
"version": "1.17.1"
}
2 changes: 1 addition & 1 deletion mip/v5/createstubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
except ImportError:
from ucollections import OrderedDict # type: ignore

__version__ = "v1.17.0"
__version__ = "v1.17.1"
ENOENT = 2
_MAX_CLASS_LEVEL = 2 # Max class nesting
LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
Expand Down
4 changes: 2 additions & 2 deletions mip/v5/createstubs_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- cross compilation, using mpy-cross, to avoid the compilation step on the micropython device
This variant was generated from createstubs.py by micropython-stubber v1.17.0
This variant was generated from createstubs.py by micropython-stubber v1.17.1
"""
# Copyright (c) 2019-2023 Jos Verlinde

Expand All @@ -42,7 +42,7 @@
except ImportError:
from ucollections import OrderedDict # type: ignore

__version__ = "v1.17.0"
__version__ = "v1.17.1"
ENOENT = 2
_MAX_CLASS_LEVEL = 2 # Max class nesting
LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
Expand Down
2 changes: 1 addition & 1 deletion mip/v5/createstubs_db_min.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
except O:pass
try:from collections import OrderedDict as k
except O:from ucollections import OrderedDict as k
__version__='v1.17.0'
__version__='v1.17.1'
A3=2
A4=2
A5=['lib','/lib','/sd/lib','/flash/lib',J]
Expand Down
Binary file modified mip/v5/createstubs_db_mpy.mpy
Binary file not shown.
4 changes: 2 additions & 2 deletions mip/v5/createstubs_mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- cross compilation, using mpy-cross,
to avoid the compilation step on the micropython device
This variant was generated from createstubs.py by micropython-stubber v1.17.0
This variant was generated from createstubs.py by micropython-stubber v1.17.1
"""
# Copyright (c) 2019-2023 Jos Verlinde

Expand All @@ -33,7 +33,7 @@
except ImportError:
from ucollections import OrderedDict # type: ignore

__version__ = "v1.17.0"
__version__ = "v1.17.1"
ENOENT = 2
_MAX_CLASS_LEVEL = 2 # Max class nesting
LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
Expand Down
2 changes: 1 addition & 1 deletion mip/v5/createstubs_mem_min.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
except N:pass
try:from collections import OrderedDict as f
except N:from ucollections import OrderedDict as f
__version__='v1.17.0'
__version__='v1.17.1'
y=2
z=2
A0=['lib','/lib','/sd/lib','/flash/lib',J]
Expand Down
Binary file modified mip/v5/createstubs_mem_mpy.mpy
Binary file not shown.
2 changes: 1 addition & 1 deletion mip/v5/createstubs_min.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
except N:pass
try:from collections import OrderedDict as g
except N:from ucollections import OrderedDict as g
__version__='v1.17.0'
__version__='v1.17.1'
A0=2
A1=2
A5=['lib','/lib','/sd/lib','/flash/lib',J]
Expand Down
Binary file modified mip/v5/createstubs_mpy.mpy
Binary file not shown.
2 changes: 1 addition & 1 deletion mip/v6/createstubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
except ImportError:
from ucollections import OrderedDict # type: ignore

__version__ = "v1.17.0"
__version__ = "v1.17.1"
ENOENT = 2
_MAX_CLASS_LEVEL = 2 # Max class nesting
LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
Expand Down
4 changes: 2 additions & 2 deletions mip/v6/createstubs_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- cross compilation, using mpy-cross, to avoid the compilation step on the micropython device
This variant was generated from createstubs.py by micropython-stubber v1.17.0
This variant was generated from createstubs.py by micropython-stubber v1.17.1
"""
# Copyright (c) 2019-2023 Jos Verlinde

Expand All @@ -42,7 +42,7 @@
except ImportError:
from ucollections import OrderedDict # type: ignore

__version__ = "v1.17.0"
__version__ = "v1.17.1"
ENOENT = 2
_MAX_CLASS_LEVEL = 2 # Max class nesting
LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
Expand Down
2 changes: 1 addition & 1 deletion mip/v6/createstubs_db_min.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
except O:pass
try:from collections import OrderedDict as k
except O:from ucollections import OrderedDict as k
__version__='v1.17.0'
__version__='v1.17.1'
A3=2
A4=2
A5=['lib','/lib','/sd/lib','/flash/lib',J]
Expand Down
Binary file modified mip/v6/createstubs_db_mpy.mpy
Binary file not shown.
4 changes: 2 additions & 2 deletions mip/v6/createstubs_mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- cross compilation, using mpy-cross,
to avoid the compilation step on the micropython device
This variant was generated from createstubs.py by micropython-stubber v1.17.0
This variant was generated from createstubs.py by micropython-stubber v1.17.1
"""
# Copyright (c) 2019-2023 Jos Verlinde

Expand All @@ -33,7 +33,7 @@
except ImportError:
from ucollections import OrderedDict # type: ignore

__version__ = "v1.17.0"
__version__ = "v1.17.1"
ENOENT = 2
_MAX_CLASS_LEVEL = 2 # Max class nesting
LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
Expand Down
2 changes: 1 addition & 1 deletion mip/v6/createstubs_mem_min.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
except N:pass
try:from collections import OrderedDict as f
except N:from ucollections import OrderedDict as f
__version__='v1.17.0'
__version__='v1.17.1'
y=2
z=2
A0=['lib','/lib','/sd/lib','/flash/lib',J]
Expand Down
Binary file modified mip/v6/createstubs_mem_mpy.mpy
Binary file not shown.
2 changes: 1 addition & 1 deletion mip/v6/createstubs_min.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
except N:pass
try:from collections import OrderedDict as g
except N:from ucollections import OrderedDict as g
__version__='v1.17.0'
__version__='v1.17.1'
A0=2
A1=2
A5=['lib','/lib','/sd/lib','/flash/lib',J]
Expand Down
Binary file modified mip/v6/createstubs_mpy.mpy
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
]
],
"deps": [],
"version": "1.17.0"
"version": "1.17.1"
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repo-path = "./repos"

[tool.poetry]
name = "micropython-stubber"
version = "1.17.0"
version = "1.17.1"
description = "Tooling to create and maintain stubs for MicroPython"
authors = ["Jos Verlinde <jos_verlinde@hotmail.com>"]
license = "MIT"
Expand Down
1 change: 1 addition & 0 deletions repos/micropython
Submodule micropython added at 0285cb
1 change: 1 addition & 0 deletions repos/micropython-lib
Submodule micropython-lib added at 7cdf70
1 change: 1 addition & 0 deletions repos/micropython-stubs
Submodule micropython-stubs added at a329b2
2 changes: 1 addition & 1 deletion src/stubber/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""get the version"""


__version__ = "1.17.0"
__version__ = "1.17.1"
2 changes: 1 addition & 1 deletion src/stubber/board/createstubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
except ImportError:
from ucollections import OrderedDict # type: ignore

__version__ = "v1.17.0"
__version__ = "v1.17.1"
ENOENT = 2
_MAX_CLASS_LEVEL = 2 # Max class nesting
LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
Expand Down
4 changes: 2 additions & 2 deletions src/stubber/board/createstubs_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- cross compilation, using mpy-cross, to avoid the compilation step on the micropython device
This variant was generated from createstubs.py by micropython-stubber v1.17.0
This variant was generated from createstubs.py by micropython-stubber v1.17.1
"""
# Copyright (c) 2019-2023 Jos Verlinde

Expand All @@ -42,7 +42,7 @@
except ImportError:
from ucollections import OrderedDict # type: ignore

__version__ = "v1.17.0"
__version__ = "v1.17.1"
ENOENT = 2
_MAX_CLASS_LEVEL = 2 # Max class nesting
LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
Expand Down
2 changes: 1 addition & 1 deletion src/stubber/board/createstubs_db_min.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
except O:pass
try:from collections import OrderedDict as k
except O:from ucollections import OrderedDict as k
__version__='v1.17.0'
__version__='v1.17.1'
A3=2
A4=2
A5=['lib','/lib','/sd/lib','/flash/lib',J]
Expand Down
Binary file modified src/stubber/board/createstubs_db_mpy.mpy
Binary file not shown.
4 changes: 2 additions & 2 deletions src/stubber/board/createstubs_mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- cross compilation, using mpy-cross,
to avoid the compilation step on the micropython device
This variant was generated from createstubs.py by micropython-stubber v1.17.0
This variant was generated from createstubs.py by micropython-stubber v1.17.1
"""
# Copyright (c) 2019-2023 Jos Verlinde

Expand All @@ -33,7 +33,7 @@
except ImportError:
from ucollections import OrderedDict # type: ignore

__version__ = "v1.17.0"
__version__ = "v1.17.1"
ENOENT = 2
_MAX_CLASS_LEVEL = 2 # Max class nesting
LIBS = ["lib", "/lib", "/sd/lib", "/flash/lib", "."]
Expand Down
2 changes: 1 addition & 1 deletion src/stubber/board/createstubs_mem_min.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
except N:pass
try:from collections import OrderedDict as f
except N:from ucollections import OrderedDict as f
__version__='v1.17.0'
__version__='v1.17.1'
y=2
z=2
A0=['lib','/lib','/sd/lib','/flash/lib',J]
Expand Down
Binary file modified src/stubber/board/createstubs_mem_mpy.mpy
Binary file not shown.
2 changes: 1 addition & 1 deletion src/stubber/board/createstubs_min.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
except N:pass
try:from collections import OrderedDict as g
except N:from ucollections import OrderedDict as g
__version__='v1.17.0'
__version__='v1.17.1'
A0=2
A1=2
A5=['lib','/lib','/sd/lib','/flash/lib',J]
Expand Down
Binary file modified src/stubber/board/createstubs_mpy.mpy
Binary file not shown.
13 changes: 5 additions & 8 deletions src/stubber/commands/get_frozen_cmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Get the frozen stubs for MicroPython."""

##########################################################################################
# get-frozen
##########################################################################################
Expand All @@ -8,7 +9,6 @@
import click
from loguru import logger as log

import stubber.basicgit as git
import stubber.utils as utils
from stubber.codemod.enrich import enrich_folder
from stubber.freeze.get_frozen import freeze_any
Expand Down Expand Up @@ -76,14 +76,11 @@ def cli_get_frozen(
)
)
return -1
else:
version = utils.clean_version(git.get_local_tag(CONFIG.mpy_path.as_posix()) or "0.0")
if not version:
log.warning("Unable to find the micropython repo in folder : {}".format(CONFIG.mpy_path.as_posix()))

log.info("MicroPython version : {}".format(version))
# folder/{family}-{version}-frozen
# folder/{family}-{version[_preview]}-frozen
family = "micropython"
# get the current checked out version
version = utils.checkedout_version(CONFIG.mpy_path)
log.info("MicroPython version : {}".format(version))

stub_path = freeze_any(version=version, mpy_path=CONFIG.mpy_path, mpy_lib_path=CONFIG.mpy_lib_path)
stub_paths.append(stub_path)
Expand Down
13 changes: 8 additions & 5 deletions src/stubber/freeze/freeze_manifest_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import List, Optional

from loguru import logger as log

from stubber import utils
from stubber.tools.manifestfile import MODE_FREEZE, ManifestFile, ManifestFileError, ManifestOutput
from stubber.utils.config import CONFIG
Expand Down Expand Up @@ -55,10 +56,10 @@ def freeze_one_manifest_2(manifest: Path, frozen_stub_path: Path, mpy_path: Path
# save cwd for 'misbehaving' older esp8266 manifest files
cwd = Path.cwd()
# so we need to get the port and board from the path
log.info(f"input_manifest: {manifest}")
log.debug(f"input_manifest: {manifest}")
port, board = get_portboard(manifest)

log.info("port-board: {}".format((port + "-" +board).rstrip("-")))
log.info("port-board: {}".format((port + "-" + board).rstrip("-")))

path_vars = make_path_vars(port=port, board=board, mpy_path=mpy_path, mpy_lib_path=mpy_lib_path)
upy_manifest = ManifestFile(MODE_FREEZE, path_vars)
Expand All @@ -69,23 +70,25 @@ def freeze_one_manifest_2(manifest: Path, frozen_stub_path: Path, mpy_path: Path
except ManifestFileError as er:
log.error('freeze error executing "{}": {}'.format(manifest, er.args[0]))
raise er
log.info(f"total {len(upy_manifest.files())} files")
log.debug(f"total {len(upy_manifest.files())} files")

# restore working directory
os.chdir(cwd)
# save the frozen files to the stubs
copy_frozen_to_stubs(frozen_stub_path, port, board, upy_manifest.files(), version, mpy_path=mpy_path)


def copy_frozen_to_stubs(stub_path: Path, port: str, board: str, files: List[ManifestOutput], version: str, mpy_path: Path):
def copy_frozen_to_stubs(
stub_path: Path, port: str, board: str, files: List[ManifestOutput], version: str, mpy_path: Path
):
"""
copy the frozen files from the manifest to the stubs folder
stubpath = the destination : # stubs/{family}-{version}-frozen
"""
freeze_path, board = get_freeze_path(stub_path, port, board)

log.info(f"copy frozen: {port}-{board} to {freeze_path}")
log.debug(f"copy frozen: {port}-{board} to {freeze_path}")
freeze_path.mkdir(parents=True, exist_ok=True)
# clean target folder
shutil.rmtree(freeze_path, ignore_errors=True)
Expand Down
Loading

0 comments on commit 8400a55

Please sign in to comment.