micropython-stubber 1.24.1__py3-none-any.whl → 1.24.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.
Files changed (90) hide show
  1. {micropython_stubber-1.24.1.dist-info → micropython_stubber-1.24.4.dist-info}/METADATA +9 -29
  2. micropython_stubber-1.24.4.dist-info/RECORD +107 -0
  3. {micropython_stubber-1.24.1.dist-info → micropython_stubber-1.24.4.dist-info}/WHEEL +1 -1
  4. stubber/__init__.py +1 -1
  5. stubber/board/createstubs.py +44 -38
  6. stubber/board/createstubs_db.py +17 -12
  7. stubber/board/createstubs_db_min.py +63 -63
  8. stubber/board/createstubs_db_mpy.mpy +0 -0
  9. stubber/board/createstubs_mem.py +17 -12
  10. stubber/board/createstubs_mem_min.py +99 -99
  11. stubber/board/createstubs_mem_mpy.mpy +0 -0
  12. stubber/board/createstubs_min.py +111 -112
  13. stubber/board/createstubs_mpy.mpy +0 -0
  14. stubber/board/modulelist.txt +27 -27
  15. stubber/codemod/board.py +1 -1
  16. stubber/codemod/enrich.py +13 -13
  17. stubber/codemod/merge_docstub.py +83 -53
  18. stubber/codemod/visitors/type_helpers.py +143 -41
  19. stubber/commands/enrich_folder_cmd.py +17 -17
  20. stubber/commands/get_docstubs_cmd.py +27 -9
  21. stubber/commands/get_frozen_cmd.py +1 -0
  22. stubber/commands/merge_cmd.py +2 -4
  23. stubber/merge_config.py +5 -36
  24. stubber/minify.py +3 -3
  25. stubber/modcat.py +118 -0
  26. stubber/publish/merge_docstubs.py +22 -5
  27. stubber/publish/stubpackage.py +33 -28
  28. stubber/rst/lookup.py +6 -23
  29. stubber/rst/reader.py +8 -13
  30. stubber/stubs_from_docs.py +2 -1
  31. stubber/tools/manifestfile.py +2 -1
  32. stubber/{cst_transformer.py → typing_collector.py} +36 -4
  33. micropython_stubber-1.24.1.dist-info/RECORD +0 -161
  34. mpflash/README.md +0 -220
  35. mpflash/libusb_flash.ipynb +0 -203
  36. mpflash/mpflash/__init__.py +0 -0
  37. mpflash/mpflash/add_firmware.py +0 -98
  38. mpflash/mpflash/ask_input.py +0 -236
  39. mpflash/mpflash/basicgit.py +0 -324
  40. mpflash/mpflash/bootloader/__init__.py +0 -2
  41. mpflash/mpflash/bootloader/activate.py +0 -60
  42. mpflash/mpflash/bootloader/detect.py +0 -82
  43. mpflash/mpflash/bootloader/manual.py +0 -101
  44. mpflash/mpflash/bootloader/micropython.py +0 -12
  45. mpflash/mpflash/bootloader/touch1200.py +0 -36
  46. mpflash/mpflash/cli_download.py +0 -129
  47. mpflash/mpflash/cli_flash.py +0 -224
  48. mpflash/mpflash/cli_group.py +0 -111
  49. mpflash/mpflash/cli_list.py +0 -87
  50. mpflash/mpflash/cli_main.py +0 -39
  51. mpflash/mpflash/common.py +0 -217
  52. mpflash/mpflash/config.py +0 -44
  53. mpflash/mpflash/connected.py +0 -96
  54. mpflash/mpflash/download.py +0 -364
  55. mpflash/mpflash/downloaded.py +0 -138
  56. mpflash/mpflash/errors.py +0 -9
  57. mpflash/mpflash/flash/__init__.py +0 -55
  58. mpflash/mpflash/flash/esp.py +0 -59
  59. mpflash/mpflash/flash/stm32.py +0 -19
  60. mpflash/mpflash/flash/stm32_dfu.py +0 -104
  61. mpflash/mpflash/flash/uf2/__init__.py +0 -88
  62. mpflash/mpflash/flash/uf2/boardid.py +0 -15
  63. mpflash/mpflash/flash/uf2/linux.py +0 -136
  64. mpflash/mpflash/flash/uf2/macos.py +0 -42
  65. mpflash/mpflash/flash/uf2/uf2disk.py +0 -12
  66. mpflash/mpflash/flash/uf2/windows.py +0 -43
  67. mpflash/mpflash/flash/worklist.py +0 -170
  68. mpflash/mpflash/list.py +0 -106
  69. mpflash/mpflash/logger.py +0 -41
  70. mpflash/mpflash/mpboard_id/__init__.py +0 -98
  71. mpflash/mpflash/mpboard_id/add_boards.py +0 -262
  72. mpflash/mpflash/mpboard_id/board.py +0 -37
  73. mpflash/mpflash/mpboard_id/board_id.py +0 -90
  74. mpflash/mpflash/mpboard_id/board_info.zip +0 -0
  75. mpflash/mpflash/mpboard_id/store.py +0 -48
  76. mpflash/mpflash/mpremoteboard/__init__.py +0 -271
  77. mpflash/mpflash/mpremoteboard/mpy_fw_info.py +0 -152
  78. mpflash/mpflash/mpremoteboard/runner.py +0 -140
  79. mpflash/mpflash/vendor/board_database.py +0 -185
  80. mpflash/mpflash/vendor/click_aliases.py +0 -91
  81. mpflash/mpflash/vendor/dfu.py +0 -165
  82. mpflash/mpflash/vendor/pydfu.py +0 -605
  83. mpflash/mpflash/vendor/readme.md +0 -12
  84. mpflash/mpflash/versions.py +0 -123
  85. mpflash/poetry.lock +0 -2603
  86. mpflash/pyproject.toml +0 -66
  87. mpflash/stm32_udev_rules.md +0 -63
  88. stubber/codemod/test_enrich.py +0 -87
  89. {micropython_stubber-1.24.1.dist-info → micropython_stubber-1.24.4.dist-info}/LICENSE +0 -0
  90. {micropython_stubber-1.24.1.dist-info → micropython_stubber-1.24.4.dist-info}/entry_points.txt +0 -0
@@ -5,15 +5,17 @@ get-docstubs
5
5
 
6
6
  from pathlib import Path
7
7
  from typing import Optional
8
+
9
+ import rich_click as click
8
10
  from packaging.version import Version
9
11
 
10
12
  import mpflash.basicgit as git
11
- import rich_click as click
13
+ import stubber.utils as utils
12
14
  from mpflash.logger import log
13
-
14
15
  from stubber.codemod.enrich import enrich_folder
15
- import stubber.utils as utils
16
16
  from stubber.commands.cli import stubber_cli
17
+ from stubber.merge_config import copy_type_modules
18
+ from stubber.modcat import CP_REFERENCE_TO_DOCSTUB
17
19
  from stubber.stubs_from_docs import generate_from_rst
18
20
  from stubber.utils.config import CONFIG
19
21
  from stubber.utils.repos import fetch_repos
@@ -65,9 +67,25 @@ from stubber.utils.repos import fetch_repos
65
67
  "--enrich",
66
68
  is_flag=True,
67
69
  default=False,
68
- help="Enrich with type information from micropython-reference",
70
+ help="Enrich with type information from reference/micropython",
69
71
  show_default=True,
70
72
  )
73
+ # @click.option(
74
+ # "--copy-params",
75
+ # "copy_params",
76
+ # default=False,
77
+ # help="Copy the function/method parameters",
78
+ # show_default=True,
79
+ # is_flag=True,
80
+ # )
81
+ # @click.option(
82
+ # "--copy-docstr",
83
+ # "copy_docstr",
84
+ # default=False,
85
+ # help="Copy the docstrings",
86
+ # show_default=False,
87
+ # is_flag=True,
88
+ # )
71
89
  @click.pass_context
72
90
  def cli_docstubs(
73
91
  ctx: click.Context,
@@ -126,19 +144,19 @@ def cli_docstubs(
126
144
 
127
145
  if enrich:
128
146
  if Version(version) < Version("1.24"):
129
- log.warning(f"Enriching is not supported for version {version}")
147
+ log.warning(f"Enriching is only supported for version v1.24+, not {version}")
130
148
  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}")
149
+ reference_path = CONFIG.stub_path.parent / "reference/micropython"
134
150
  _ = enrich_folder(
135
151
  reference_path,
136
152
  dst_path,
137
153
  show_diff=False,
138
154
  write_back=True,
139
155
  require_docstub=False,
140
- params_only=True,
156
+ copy_params=True,
157
+ copy_docstr=False,
141
158
  )
159
+ copy_type_modules(reference_path, dst_path, CP_REFERENCE_TO_DOCSTUB)
142
160
  log.info("::group:: start post processing of retrieved stubs")
143
161
  # do not run stubgen
144
162
  utils.do_post_processing([dst_path], stubgen=False, black=black, autoflake=autoflake)
@@ -109,6 +109,7 @@ def cli_get_frozen(
109
109
  show_diff=False,
110
110
  write_back=True,
111
111
  require_docstub=False,
112
+ copy_docstr=True,
112
113
  ext = ".pyi",
113
114
  ):
114
115
  log.info(f" > Enriched {merged} frozen modules.")
@@ -5,8 +5,8 @@ enrich machinestubs with docstubs
5
5
  from typing import List, Union
6
6
 
7
7
  import rich_click as click
8
- from mpflash.logger import log
9
8
 
9
+ from mpflash.logger import log
10
10
  from stubber.commands.cli import stubber_cli
11
11
  from stubber.publish.merge_docstubs import merge_all_docstubs
12
12
  from stubber.publish.package import GENERIC_L
@@ -60,6 +60,4 @@ def cli_merge_docstubs(
60
60
  versions = list(versions)
61
61
  # single version should be a string
62
62
  log.info(f"Merge docstubs for {family} {versions}")
63
- _ = merge_all_docstubs(
64
- versions=versions, family=family, boards=boards, ports=ports, mpy_path=CONFIG.mpy_path
65
- )
63
+ _ = merge_all_docstubs(versions=versions, family=family, boards=boards, ports=ports)
stubber/merge_config.py CHANGED
@@ -1,6 +1,6 @@
1
1
  """
2
2
  Merge configuration for the stubber.
3
- defines constants and util functions to copy, update or remove type modules
3
+ util functions to copy, update or remove type modules
4
4
  """
5
5
 
6
6
  import shutil
@@ -8,43 +8,11 @@ from pathlib import Path
8
8
  from typing import Final, List
9
9
 
10
10
  from mpflash.logger import log
11
- from stubber.rst.lookup import U_MODULES
12
11
 
13
- EXT: Final = [".pyi", ".py", ""]
14
- CP_REFERENCE_TO_DOCSTUB: Final = [
15
- "asyncio",
16
- "rp2/PIOASMEmit.pyi",
17
- "rp2/asm_pio.pyi",
18
- ]
19
- "Modules to copy from reference modules to the docstubs"
20
-
21
-
22
- STDLIB_MODULES: Final = [
23
- "collections",
24
- "io",
25
- "builtins",
26
- "asyncio",
27
- "sys",
28
- # "os", # TODO # Do not remove `os` to allow better typing by mypy for the `os` module
29
- # "ssl", # TODO
30
- ]
31
- """Modules that should be in /stdlib"""
32
- # and should not be in the individual packes as that causes duplication
12
+ from stubber.modcat import (CP_REFERENCE_TO_DOCSTUB, RM_MERGED,
13
+ STDLIB_ONLY_MODULES, U_MODULES)
33
14
 
34
- RM_MERGED: Final = (
35
- [
36
- "sys", # use auto patched version from mpy_stdlib
37
- "asyncio", # use manually patched version from mpy_stdlib
38
- "_asyncio", # ditto
39
- "uasyncio", # ditto
40
- "_rp2", # Leave out for now , to avoid conflicts with the rp2 module
41
- "pycopy_imphook", # pycopy only: not needed in the merged stubs
42
- # "os",
43
- ]
44
- + STDLIB_MODULES
45
- + [f"u{mod}" for mod in U_MODULES]
46
- )
47
- "Modules to remove from merged stubs, U_MODULES will be recreated later"
15
+ EXT: Final = [".pyi", ".py", ""]
48
16
 
49
17
 
50
18
  def copy_type_modules(source_folder: Path, target_folder: Path, CP_REFERENCE_MODULES: List[str]):
@@ -109,3 +77,4 @@ def remove_modules(target_folder: Path, RM_MODULES: List[str]):
109
77
  target.unlink()
110
78
  finally:
111
79
  log.debug(f" - remove {target}")
80
+
stubber/minify.py CHANGED
@@ -370,8 +370,8 @@ def cross_compile(
370
370
  # target must be a Path object
371
371
  _target = get_temp_file(suffix=".mpy")
372
372
  result = pipx_mpy_cross(version, source_file, _target)
373
- if result.stderr and "No matching distribution found for mpy-cross==" in result.stderr:
374
- log.warning(f"mpy-cross=={version} not found, using most current version.")
373
+ if result.stderr and "No matching distribution found for mpy-cross~=" in result.stderr:
374
+ log.warning(f"mpy-cross~={version} not found, using most current version.")
375
375
  result = pipx_mpy_cross(V_PREVIEW, source_file, _target)
376
376
 
377
377
  if result.returncode == 0:
@@ -395,7 +395,7 @@ def pipx_mpy_cross(version: str, source_file, _target):
395
395
  if version in SET_PREVIEW:
396
396
  version = ""
397
397
  if version:
398
- version = "==" + version
398
+ version = "~=" + version.lstrip("v")
399
399
 
400
400
  cmd = ["pipx", "run", f"mpy-cross{version}"] if version else ["pipx", "run", "mpy-cross"]
401
401
  # Add params
stubber/modcat.py ADDED
@@ -0,0 +1,118 @@
1
+ """
2
+ Used to define where stub modules should and should not be copied to, or merged to
3
+
4
+ This is shared between stubber, and external build scripts.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ from typing import Final
9
+
10
+ from stubber.publish.enums import StubSource
11
+
12
+ ########################################################
13
+ STDLIB_ONLY_MODULES = [
14
+ "abc",
15
+ "array",
16
+ "collections",
17
+ "io",
18
+ "builtins",
19
+ "asyncio",
20
+ "sys",
21
+ "types",
22
+ "ssl",
23
+ "os",
24
+ # Experiment
25
+ "json",
26
+ "struct"
27
+ # "socket", # should be ins tdlib - but is only available on networked boards
28
+ # time # should be in stdlib - but has implementation differences per port)
29
+ ]
30
+ """Modules that should only be in stdlib, and not in the individual packages"""
31
+ # and should not be in the individual packes as that causes duplication
32
+
33
+
34
+ ########################################################
35
+ # stubber.publish.stubpacker #
36
+ ########################################################
37
+ # Indicates which stubs will NOT be copied from the stub sources
38
+ # and shared with multiple modules and the sdtbli build.py that is in the stubs repo
39
+ STUBS_COPY_FILTER = {
40
+ StubSource.FROZEN: [
41
+ "espnow", # merged stubs + documentation of the espnow module is better than the info in the frozen stubs
42
+ # "collections", # must be in stdlib
43
+ # "types", # must be in stdlib
44
+ # "abc", # must be in stdlib
45
+ "time", # used from merged ( should be in stdlib - but has implementation differences per port)
46
+ # "io", # must be in stdlib
47
+ ] + STDLIB_ONLY_MODULES,
48
+ StubSource.FIRMWARE: [
49
+ "builtins",
50
+ # "collections", # collections must be in stdlib
51
+ ] + STDLIB_ONLY_MODULES,
52
+ StubSource.MERGED: STDLIB_ONLY_MODULES,
53
+ }
54
+
55
+ # these modules will be replaced by a simple import statement to import from stdlib
56
+ STDLIB_UMODULES = ["ucollections"]
57
+
58
+ ########################################################
59
+ # stubber.rst... #
60
+ ########################################################
61
+ U_MODULES = [
62
+ "array",
63
+ "asyncio",
64
+ "binascii",
65
+ "bluetooth",
66
+ "errno",
67
+ "io",
68
+ "json",
69
+ "machine",
70
+ "os",
71
+ "platform",
72
+ "select",
73
+ "ssl",
74
+ "struct",
75
+ "socket",
76
+ "sys",
77
+ "time",
78
+ "zlib",
79
+ ]
80
+ """
81
+ List of modules that are documented with the base name only,
82
+ but can also be imported with a `u` prefix
83
+ """
84
+
85
+ ########################################################
86
+ # stubber.merge_config #
87
+ # defines constants to copy, update, remove type stubs #
88
+ ########################################################
89
+
90
+ CP_REFERENCE_TO_DOCSTUB: Final = [
91
+ "asyncio", # just for documentation
92
+ # stdlib stubs are using the version from stdlib/asyncio
93
+ "rp2/PIOASMEmit.pyi",
94
+ "rp2/asm_pio.pyi",
95
+ ]
96
+ "Modules to copy from reference modules to the docstubs"
97
+
98
+
99
+
100
+
101
+ RM_MERGED = (
102
+ [
103
+ "sys", # use auto patched version from mpy_stdlib
104
+ "asyncio", # use manually patched version from mpy_stdlib
105
+ "_asyncio", # ditto
106
+ "uasyncio", # ditto
107
+ "_rp2", # Leave out for now , to avoid conflicts with the rp2 module
108
+ "pycopy_imphook", # pycopy only: not needed in the merged stubs
109
+ # "os",
110
+ "types", # defined in webassembly pyscript - shadows stdlib
111
+ "abc", # defined in webassembly pyscript - shadows stdlib
112
+ # "uos", # ???? problems with mypy & webassembly stubs
113
+ ]
114
+ + STDLIB_ONLY_MODULES
115
+ + [f"u{mod}" for mod in U_MODULES]
116
+ )
117
+ "Modules to remove from merged stubs, U_MODULES will be recreated later"
118
+
@@ -7,7 +7,6 @@ from pathlib import Path
7
7
  from typing import List, Optional, Union
8
8
 
9
9
  from mpflash.logger import log
10
-
11
10
  from stubber.codemod.enrich import enrich_folder
12
11
  from stubber.merge_config import RM_MERGED, recreate_umodules, remove_modules
13
12
  from stubber.publish.candidates import board_candidates, filter_list
@@ -21,8 +20,8 @@ def merge_all_docstubs(
21
20
  family: str = "micropython",
22
21
  ports: Optional[Union[List[str], str]] = None,
23
22
  boards: Optional[Union[List[str], str]] = None,
24
- *,
25
- mpy_path: Path = CONFIG.mpy_path,
23
+ # *,
24
+ # mpy_path: Path = CONFIG.mpy_path,
26
25
  ):
27
26
  """merge docstubs and MCU stubs to merged stubs"""
28
27
  if versions is None:
@@ -67,7 +66,19 @@ def merge_all_docstubs(
67
66
  continue
68
67
  log.info(f"Merge {candidate['version']} docstubs with boardstubs to {merged_path.name}")
69
68
  try:
69
+ # TODO : webassembly: Need to merge from reference/pyscript as well
70
70
  result = copy_and_merge_docstubs(board_path, merged_path, doc_path)
71
+ if candidate["port"] == "webassembly":
72
+ # TODO : webassembly: Need to merge from reference/pyscript as well
73
+ # use enrich_folder to merge the docstubs
74
+ enrich_folder(
75
+ source_folder=CONFIG.mpy_stubs_path / "reference/pyscript",
76
+ target_folder=merged_path,
77
+ write_back=True,
78
+ copy_params=True,
79
+ copy_docstr=True,
80
+ )
81
+ pass
71
82
  except Exception as e:
72
83
  log.error(f"Error parsing {candidate['version']} docstubs: {e}")
73
84
  continue
@@ -122,7 +133,13 @@ def copy_and_merge_docstubs(fw_path: Path, dest_path: Path, docstub_path: Path):
122
133
  recreate_umodules(dest_path)
123
134
 
124
135
  # 2 - Enrich the MCU stubs with the document stubs
125
- result = enrich_folder(source_folder=docstub_path, target_folder=dest_path, write_back=True)
136
+ result = enrich_folder(
137
+ source_folder=docstub_path,
138
+ target_folder=dest_path,
139
+ write_back=True,
140
+ copy_params=True,
141
+ copy_docstr=True,
142
+ )
126
143
 
127
144
  refactor_rp2_module(dest_path)
128
145
 
@@ -147,7 +164,7 @@ def refactor_rp2_module(dest_path: Path):
147
164
  rp2_file.rename(rp2_folder / "__init__.pyi")
148
165
  # copy the asm_pio.pyi file from the reference folder
149
166
  for submod in ["rp2/asm_pio.pyi"]:
150
- file = CONFIG.mpy_stubs_path / "micropython-reference" / submod
167
+ file = CONFIG.mpy_stubs_path / "reference/micropython" / submod
151
168
  if file.exists():
152
169
  shutil.copy(file, rp2_folder / file.name)
153
170
  log.info(f" - add rp2/{ file.name}")
@@ -1,4 +1,12 @@
1
- """Create a stub-only package for a specific version of micropython"""
1
+ """
2
+ Create a stub-only package for a specific
3
+ - version
4
+ - port
5
+ - board
6
+ of micropython
7
+
8
+
9
+ """
2
10
 
3
11
  import hashlib
4
12
  import json
@@ -31,27 +39,11 @@ from stubber.publish.defaults import GENERIC_U, default_board
31
39
  from stubber.publish.enums import StubSource
32
40
  from stubber.publish.pypi import Version, get_pypi_versions
33
41
  from stubber.utils.config import CONFIG
42
+ from stubber.modcat import STDLIB_UMODULES, STUBS_COPY_FILTER
34
43
 
35
44
  Status = NewType("Status", Dict[str, Union[str, None]])
36
45
  StubSources = List[Tuple[StubSource, Path]]
37
46
 
38
- # indicates which stubs will be skipped when copying for these stub sources
39
- STUBS_COPY_FILTER = {
40
- StubSource.FROZEN: [
41
- "espnow", # merged stubs + documentation of the espnow module is better than the info in the forzen stubs
42
- ],
43
- StubSource.FIRMWARE: [
44
- "builtins",
45
- "collections", # collections must be in stdlib
46
- ],
47
- StubSource.MERGED: [
48
- "collections", # collections must be in stdlib
49
- ],
50
- }
51
-
52
- # these modules will be replaced by a simple import statement to import from stdlib
53
- STDLIB_UMODULES = ["ucollections"]
54
-
55
47
 
56
48
  class VersionedPackage:
57
49
  """
@@ -274,8 +266,12 @@ class Builder(VersionedPackage):
274
266
  # make sure parent folder exists
275
267
  _toml = self.toml_path
276
268
  (_toml).parent.mkdir(parents=True, exist_ok=True)
277
- with open(_toml, "wb") as output:
278
- tomli_w.dump(pyproject, output)
269
+ try:
270
+ with open(_toml, "wb") as output:
271
+ tomli_w.dump(pyproject, output)
272
+ except OSError as e:
273
+ log.error(e)
274
+ log.debug(repr(_toml))
279
275
 
280
276
  # -----------------------------------------------
281
277
  def create_update_pyproject_toml(self) -> None:
@@ -359,10 +355,14 @@ class Builder(VersionedPackage):
359
355
 
360
356
  def copy_folder(self, stub_type: StubSource, src_path: Path):
361
357
  Path(self.package_path).mkdir(parents=True, exist_ok=True)
362
- for item in (CONFIG.stub_path / src_path).rglob("*"):
358
+ for item in (CONFIG.stub_path / src_path).rglob("*.pyi"):
363
359
  if item.is_file():
364
360
  # filter the 'poorly' decorated files
365
- if stub_type in STUBS_COPY_FILTER and item.stem in STUBS_COPY_FILTER[stub_type]:
361
+ if stub_type in STUBS_COPY_FILTER and (
362
+ item.stem in STUBS_COPY_FILTER[stub_type] or
363
+ item.parent.name in STUBS_COPY_FILTER[stub_type]
364
+ ):
365
+ log.trace(f"Skipping {item.name}")
366
366
  continue
367
367
 
368
368
  target = Path(self.package_path) / item.relative_to(CONFIG.stub_path / src_path)
@@ -631,8 +631,10 @@ class PoetryBuilder(Builder):
631
631
  try:
632
632
  with open(_toml, "rb") as f:
633
633
  pyproject = tomllib.load(f)
634
- # pyproject["tool"]["poetry"]["version"] = version
635
- pyproject["project"]["version"] = version
634
+ if "project" in pyproject:
635
+ pyproject["project"]["version"] = version
636
+ else:
637
+ pyproject["tool"]["poetry"]["version"] = version
636
638
  # update the version in the toml file
637
639
  with open(_toml, "wb") as output:
638
640
  tomli_w.dump(pyproject, output)
@@ -742,10 +744,13 @@ class PoetryBuilder(Builder):
742
744
  raise (e)
743
745
 
744
746
  # update the name , version and description of the package
745
- # _pyproject["tool"]["poetry"]["name"] = self.package_name
746
- # _pyproject["tool"]["poetry"]["description"] = self.description
747
- _pyproject["project"]["name"] = self.package_name
748
- _pyproject["project"]["description"] = self.description
747
+ if 'project' in _pyproject:
748
+ _pyproject["project"]["name"] = self.package_name
749
+ _pyproject["project"]["description"] = self.description
750
+ else:
751
+ _pyproject["tool"]["poetry"]["name"] = self.package_name
752
+ _pyproject["tool"]["poetry"]["description"] = self.description
753
+
749
754
  # write out the pyproject.toml file
750
755
  self.pyproject = _pyproject
751
756
 
stubber/rst/lookup.py CHANGED
@@ -16,7 +16,6 @@ __all__ = [
16
16
  "MODULE_GLUE",
17
17
  "RST_DOC_FIXES",
18
18
  "DOCSTUB_SKIP",
19
- "U_MODULES",
20
19
  ]
21
20
 
22
21
  # all possible Types needed for the stubs - excess types should be removed later , and otherwise won't do much harm
@@ -52,25 +51,6 @@ class Fix:
52
51
  "the from_ string is a regular expression"
53
52
 
54
53
 
55
- U_MODULES = [
56
- "array",
57
- "asyncio",
58
- "binascii",
59
- "io",
60
- "json",
61
- "machine",
62
- "os",
63
- "select",
64
- "ssl",
65
- "struct",
66
- "socket",
67
- "time",
68
- "zlib",
69
- ]
70
- """
71
- List of modules that are documented with the base name only,
72
- but can also be imported with a `u` prefix
73
- """
74
54
 
75
55
  # This table is used to try to correct the errors in the documentation,
76
56
  # or adapt the human readable documentation to machine readable.
@@ -101,6 +81,9 @@ RST_DOC_FIXES: List[Tuple[str, str]] = [
101
81
  ".. method:: AIOESPNow._aiter__() / async AIOESPNow.__anext__()",
102
82
  ".. method:: AIOESPNow._aiter__()\n async AIOESPNow.__anext__()",
103
83
  ),
84
+ # appended to in ssl.constant name - ssl.PROTOCOL_DTLS_CLIENT(when DTLS support is enabled)
85
+ # Ugly hack to fix the documentation
86
+ ( '(when DTLS support is enabled)', " : Incomplete # (when DTLS support is enabled)")
104
87
  ]
105
88
 
106
89
 
@@ -154,8 +137,8 @@ LOOKUP_LIST = {
154
137
  "uio.open": ("IO", 0.95), # Open a file.
155
138
  "uos.listdir": ("List[Incomplete]", 0.95),
156
139
  "os.uname": ("uname_result", 0.95),
157
- # undocumented CPython class ssl.SSLSocket
158
- # TODO: include ssl.SSLSocket from stdlib / mpy_typeshed, currently Incomplete
140
+ # ssl.SSLSocket is defined in reference/micropython/ssl
141
+
159
142
  "ssl.wrap_socket": ("SSLSocket", 0.95),
160
143
  "ussl.wrap_socket": ("SSLSocket", 0.95),
161
144
  #
@@ -367,7 +350,7 @@ MODULE_GLUE = {
367
350
  "ssl": [
368
351
  "from typing_extensions import TypeAlias",
369
352
  "from _mpy_shed import StrOrBytesPath",
370
- "SSLSocket : TypeAlias = Incomplete",
353
+ # SSLSocket is part of the refence stubs
371
354
  ],
372
355
  "struct": ANY_BUF,
373
356
  "time": [
stubber/rst/reader.py CHANGED
@@ -69,19 +69,10 @@ from typing import List, Optional, Tuple
69
69
 
70
70
  from mpflash.logger import log
71
71
  from mpflash.versions import V_PREVIEW
72
-
73
- from stubber.rst import (
74
- CHILD_PARENT_CLASS,
75
- MODULE_GLUE,
76
- PARAM_FIXES,
77
- PARAM_RE_FIXES,
78
- RST_DOC_FIXES,
79
- TYPING_IMPORT,
80
- ClassSourceDict,
81
- FunctionSourceDict,
82
- ModuleSourceDict,
83
- return_type_from_context,
84
- )
72
+ from stubber.rst import (CHILD_PARENT_CLASS, MODULE_GLUE, PARAM_FIXES,
73
+ PARAM_RE_FIXES, RST_DOC_FIXES, TYPING_IMPORT,
74
+ ClassSourceDict, FunctionSourceDict, ModuleSourceDict,
75
+ return_type_from_context)
85
76
  from stubber.rst.lookup import Fix
86
77
  from stubber.utils.config import CONFIG
87
78
 
@@ -782,6 +773,10 @@ class RSTParser(RSTReader):
782
773
  self.line_no += counter - 1
783
774
  # clean up before returning
784
775
  names = [n.strip() for n in names if n.strip() != "etc."] # remove etc.
776
+ # Ugly one-off hack
777
+ # to remove the '(when DTLS support is enabled)' from the ssl constants
778
+ # names = [n.replace('(when DTLS support is enabled)', '') for n in names]
779
+
785
780
  return names
786
781
 
787
782
  def parse_data(self):
@@ -10,7 +10,8 @@ from typing import List, Optional
10
10
  from mpflash.logger import log
11
11
 
12
12
  from stubber import utils
13
- from stubber.rst import DOCSTUB_SKIP, U_MODULES
13
+ from stubber.rst import DOCSTUB_SKIP
14
+ from stubber.modcat import U_MODULES
14
15
  from stubber.rst.reader import RSTWriter
15
16
 
16
17
 
@@ -29,6 +29,7 @@ from __future__ import print_function
29
29
  import contextlib
30
30
  import os
31
31
  import sys
32
+ import glob
32
33
  import tempfile
33
34
  from collections import namedtuple
34
35
 
@@ -400,7 +401,7 @@ class ManifestFile:
400
401
  self._metadata.pop()
401
402
 
402
403
  def _require_from_path(self, library_path, name, version, extra_kwargs):
403
- for root, dirnames, filenames in os.walk(library_path): # type: ignore
404
+ for root, dirnames, filenames in os.walk(library_path):
404
405
  if os.path.basename(root) == name and "manifest.py" in filenames:
405
406
  self.include(root, is_require=True, **extra_kwargs)
406
407
  return True
@@ -5,6 +5,7 @@ from dataclasses import dataclass, field
5
5
  from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
6
6
 
7
7
  import libcst as cst
8
+ from libcst import matchers as m
8
9
 
9
10
 
10
11
  @dataclass
@@ -43,12 +44,33 @@ MODULE_KEY = ("__module",)
43
44
  MOD_DOCSTR_KEY = ("__module_docstring",)
44
45
 
45
46
  # debug helper
46
- _m = cst.parse_module("")
47
+ _code = cst.parse_module("").code_for_node
48
+
49
+
50
+ def is_property(node: cst.FunctionDef) -> bool:
51
+ """check if the function is a property"""
52
+ return any(m.matches(dec, m.Decorator(decorator=m.Name(value="property"))) for dec in node.decorators)
53
+
54
+
55
+ # FIXME : this is a clumsy way - but I cant find a working matcher for this
56
+ def is_setter(node: cst.FunctionDef) -> bool:
57
+ """check if the function is a setter"""
58
+ return any(d for d in _code(node).split("\n") if d.startswith("@") and d.endswith(".setter"))
59
+
60
+
61
+ def is_getter(node: cst.FunctionDef) -> bool:
62
+ """check if the function is a getter"""
63
+ return any(d for d in _code(node).split("\n") if d.startswith("@") and d.endswith(".getter"))
64
+
65
+
66
+ def is_deleter(node: cst.FunctionDef) -> bool:
67
+ """check if the function is a deleter"""
68
+ return any(d for d in _code(node).split("\n") if d.startswith("@") and d.endswith(".deleter"))
47
69
 
48
70
 
49
71
  class StubTypingCollector(cst.CSTVisitor):
50
72
  """
51
- Collect the function/method and class definitions from the stubs source
73
+ Collect the function/method and class definitions from ta rich .py or .pyi source
52
74
  """
53
75
 
54
76
  def __init__(self):
@@ -119,12 +141,22 @@ class StubTypingCollector(cst.CSTVisitor):
119
141
  def_type="funcdef",
120
142
  def_node=node,
121
143
  )
122
- key = tuple(self.stack)
144
+ if is_getter(node):
145
+ extra = ["getter"]
146
+ elif is_setter(node):
147
+ extra = ["setter"]
148
+ elif is_deleter(node):
149
+ extra = ["deleter"]
150
+ else:
151
+ extra = []
152
+ key = tuple(self.stack + extra)
153
+
123
154
  if not key in self.annotations:
124
155
  # store the first function/method signature
125
156
  self.annotations[key] = AnnoValue(type_info=ti)
126
157
 
127
- if any(dec.decorator.value == "overload" for dec in node.decorators): # type: ignore
158
+
159
+ if any(m.matches(dec , m.Decorator(decorator=m.Name("overload"))) for dec in node.decorators):
128
160
  # and store the overloads
129
161
  self.annotations[key].overloads.append(ti)
130
162