micropython-stubber 1.16.2__py3-none-any.whl → 1.17.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.
Files changed (55) hide show
  1. {micropython_stubber-1.16.2.dist-info → micropython_stubber-1.17.0.dist-info}/METADATA +2 -1
  2. {micropython_stubber-1.16.2.dist-info → micropython_stubber-1.17.0.dist-info}/RECORD +54 -54
  3. stubber/__init__.py +1 -1
  4. stubber/basicgit.py +27 -33
  5. stubber/board/board_info.csv +137 -103
  6. stubber/board/createstubs.py +222 -189
  7. stubber/board/createstubs_db.py +284 -214
  8. stubber/board/createstubs_db_min.py +286 -265
  9. stubber/board/createstubs_db_mpy.mpy +0 -0
  10. stubber/board/createstubs_lvgl.py +171 -113
  11. stubber/board/createstubs_lvgl_min.py +738 -275
  12. stubber/board/createstubs_lvgl_mpy.mpy +0 -0
  13. stubber/board/createstubs_mem.py +237 -174
  14. stubber/board/createstubs_mem_min.py +263 -247
  15. stubber/board/createstubs_mem_mpy.mpy +0 -0
  16. stubber/board/createstubs_min.py +242 -227
  17. stubber/board/createstubs_mpy.mpy +0 -0
  18. stubber/board/fw_info.py +135 -0
  19. stubber/board/modulelist.txt +1 -2
  20. stubber/codemod/_partials/__init__.py +1 -1
  21. stubber/codemod/_partials/db_main.py +90 -72
  22. stubber/codemod/_partials/modules_reader.py +29 -17
  23. stubber/codemod/board.py +2 -4
  24. stubber/codemod/enrich.py +1 -1
  25. stubber/commands/build_cmd.py +6 -4
  26. stubber/commands/get_docstubs_cmd.py +6 -11
  27. stubber/commands/get_frozen_cmd.py +6 -11
  28. stubber/commands/switch_cmd.py +6 -4
  29. stubber/data/board_info.csv +134 -101
  30. stubber/data/board_info.json +1357 -901
  31. stubber/freeze/freeze_manifest_2.py +2 -1
  32. stubber/freeze/get_frozen.py +28 -13
  33. stubber/minify.py +56 -43
  34. stubber/publish/candidates.py +15 -23
  35. stubber/publish/defaults.py +2 -2
  36. stubber/publish/merge_docstubs.py +5 -7
  37. stubber/publish/missing_class_methods.py +2 -2
  38. stubber/publish/pathnames.py +2 -2
  39. stubber/publish/publish.py +2 -1
  40. stubber/publish/stubpackage.py +20 -40
  41. stubber/rst/lookup.py +9 -7
  42. stubber/rst/reader.py +2 -1
  43. stubber/stubber.py +5 -6
  44. stubber/update_fallback.py +3 -1
  45. stubber/update_module_list.py +1 -1
  46. stubber/utils/__init__.py +1 -1
  47. stubber/utils/config.py +7 -9
  48. stubber/utils/post.py +1 -1
  49. stubber/utils/repos.py +10 -7
  50. stubber/utils/versions.py +48 -7
  51. stubber/variants.py +3 -3
  52. stubber/board/logging.py +0 -99
  53. {micropython_stubber-1.16.2.dist-info → micropython_stubber-1.17.0.dist-info}/LICENSE +0 -0
  54. {micropython_stubber-1.16.2.dist-info → micropython_stubber-1.17.0.dist-info}/WHEEL +0 -0
  55. {micropython_stubber-1.16.2.dist-info → micropython_stubber-1.17.0.dist-info}/entry_points.txt +0 -0
stubber/rst/reader.py CHANGED
@@ -83,6 +83,7 @@ from stubber.rst import (
83
83
  )
84
84
  from stubber.rst.lookup import Fix
85
85
  from stubber.utils.config import CONFIG
86
+ from stubber.utils.versions import V_PREVIEW
86
87
 
87
88
  SEPERATOR = "::"
88
89
 
@@ -506,7 +507,7 @@ class RSTParser(RSTReader):
506
507
  # Add link to online documentation
507
508
  # https://docs.micropython.org/en/v1.17/library/array.html
508
509
  if "nightly" in self.source_tag:
509
- version = "latest"
510
+ version = V_PREVIEW
510
511
  else:
511
512
  version = self.source_tag.replace(
512
513
  "_", "."
stubber/stubber.py CHANGED
@@ -4,8 +4,8 @@
4
4
  """Create, Process, and Maintain stubs ✏️ for MicroPython"""
5
5
 
6
6
 
7
- from stubber.commands.cli import stubber_cli
8
7
  from stubber.commands.build_cmd import cli_build
8
+ from stubber.commands.cli import stubber_cli
9
9
  from stubber.commands.clone_cmd import cli_clone
10
10
  from stubber.commands.config_cmd import cli_config
11
11
  from stubber.commands.enrich_folder_cmd import cli_enrich_folder
@@ -22,7 +22,6 @@ from stubber.commands.upd_fallback_cmd import cli_update_fallback
22
22
  from stubber.commands.upd_module_list_cmd import cli_update_module_list
23
23
  from stubber.commands.variants_cmd import cli_variants
24
24
 
25
-
26
25
  ##########################################################################################
27
26
  if __name__ == "__main__":
28
27
  # add all commands to the CLI
@@ -33,13 +32,13 @@ if __name__ == "__main__":
33
32
  stubber_cli.add_command(cli_docstubs)
34
33
  stubber_cli.add_command(cli_get_core)
35
34
  stubber_cli.add_command(cli_get_frozen)
36
- stubber_cli.add_command(cli_get_lobo)
35
+ # stubber_cli.add_command(cli_get_lobo)
37
36
  stubber_cli.add_command(cli_stub)
38
37
  stubber_cli.add_command(cli_enrich_folder)
39
- stubber_cli.add_command(cli_minify)
38
+ # stubber_cli.add_command(cli_minify)
40
39
  stubber_cli.add_command(cli_publish)
41
40
  stubber_cli.add_command(cli_merge_docstubs)
42
- stubber_cli.add_command(cli_update_module_list)
43
- stubber_cli.add_command(cli_update_fallback)
41
+ # stubber_cli.add_command(cli_update_module_list)
42
+ # stubber_cli.add_command(cli_update_fallback)
44
43
  stubber_cli.add_command(cli_variants)
45
44
  stubber_cli()
@@ -9,6 +9,8 @@ from typing import List, Optional, Tuple
9
9
 
10
10
  from loguru import logger as log
11
11
 
12
+ from stubber.utils.versions import V_PREVIEW
13
+
12
14
  # log = logging.getLogger()
13
15
 
14
16
  RELEASED = "v1_18"
@@ -24,7 +26,7 @@ def fallback_sources(version: str, fw_version: Optional[str] = None) -> List[Tup
24
26
  """
25
27
  if not fw_version:
26
28
  fw_version = version
27
- if fw_version == "latest":
29
+ if fw_version == V_PREVIEW:
28
30
  fw_version = RELEASED
29
31
  SOURCES = [
30
32
  ("uasyncio", f"micropython-{fw_version}-esp32"),
@@ -100,7 +100,7 @@ def update_module_list():
100
100
  "builtins",
101
101
  "re",
102
102
  }
103
-
103
+ log.info("Update the module list in createstubs.py")
104
104
  all_modules = read_modules()
105
105
  modules_to_stub = sorted(all_modules - set(mods_excluded | mods_problematic))
106
106
 
stubber/utils/__init__.py CHANGED
@@ -2,4 +2,4 @@
2
2
  from .manifest import make_manifest, manifest
3
3
  from .post import do_post_processing
4
4
  from .stubmaker import generate_pyi_files, generate_pyi_from_file
5
- from .versions import clean_version
5
+ from .versions import checkedout_version, clean_version
stubber/utils/config.py CHANGED
@@ -2,12 +2,14 @@
2
2
 
3
3
  from pathlib import Path
4
4
 
5
+ from loguru import logger as log
5
6
  from typedconfig.config import Config, key, section
6
7
  from typedconfig.source import EnvironmentConfigSource
7
- from .typed_config_toml import TomlConfigSource
8
8
 
9
- from loguru import logger as log
10
9
  import stubber.basicgit as git
10
+ from stubber.utils.versions import V_PREVIEW
11
+
12
+ from .typed_config_toml import TomlConfigSource
11
13
 
12
14
 
13
15
  @section("micropython-stubber")
@@ -16,9 +18,7 @@ class StubberConfig(Config):
16
18
  stub_path = key(key_name="stub-path", cast=Path, required=False, default=Path("./stubs"))
17
19
  "a Path to the stubs directory"
18
20
  # relative to stubs folder
19
- fallback_path = key(
20
- key_name="fallback-path", cast=Path, required=False, default=Path("typings/fallback")
21
- )
21
+ fallback_path = key(key_name="fallback-path", cast=Path, required=False, default=Path("typings/fallback"))
22
22
  "a Path to the fallback stubs directory"
23
23
 
24
24
  # ------------------------------------------------------------------------------------------
@@ -29,9 +29,7 @@ class StubberConfig(Config):
29
29
  mpy_path = key(key_name="mpy-path", cast=Path, required=False, default=Path("micropython"))
30
30
  "a Path to the micropython folder in the repos directory"
31
31
 
32
- mpy_lib_path = key(
33
- key_name="mpy-lib-path", cast=Path, required=False, default=Path("micropython-lib")
34
- )
32
+ mpy_lib_path = key(key_name="mpy-lib-path", cast=Path, required=False, default=Path("micropython-lib"))
35
33
  "a Path to the micropython-lib folder in the repos directory"
36
34
 
37
35
  # mpy_stubs_repo_path = key(key_name="mpy-stubs-repo-path", cast=Path, required=False, default=Path("./micropython-stubs"))
@@ -96,7 +94,7 @@ class StubberConfig(Config):
96
94
  all_versions = ["1.19", "1.19.1", "1.20.0", "1.21.0"]
97
95
  config_updates.update(all_versions=all_versions)
98
96
  config_updates.update(
99
- stable_version=[v for v in all_versions if not v.endswith("preview")][-1]
97
+ stable_version=[v for v in all_versions if not v.endswith(V_PREVIEW)][-1]
100
98
  ) # second last version - last version is the preview version
101
99
  return config_updates
102
100
 
stubber/utils/post.py CHANGED
@@ -35,7 +35,7 @@ def run_black(path: Path, capture_output: bool = False):
35
35
  "--line-length",
36
36
  "140",
37
37
  ]
38
- result = subprocess.run(cmd, capture_output=True, text=True)
38
+ result = subprocess.run(cmd, capture_output=True, text=True, encoding="utf-8")
39
39
 
40
40
  return result.returncode
41
41
 
stubber/utils/repos.py CHANGED
@@ -13,6 +13,7 @@ from packaging.version import Version
13
13
 
14
14
  import stubber.basicgit as git
15
15
  from stubber.utils.config import CONFIG
16
+ from stubber.utils.versions import SET_PREVIEW, V_PREVIEW
16
17
 
17
18
  # # log = logging.getLogger(__name__)
18
19
 
@@ -34,8 +35,8 @@ def switch(tag: str, *, mpy_path: Path, mpy_lib_path: Path):
34
35
  git.fetch(mpy_lib_path)
35
36
 
36
37
  if not tag or tag in {"master", ""}:
37
- tag = "latest"
38
- if tag == "latest":
38
+ tag = V_PREVIEW
39
+ if tag in SET_PREVIEW:
39
40
  git.switch_branch(repo=mpy_path, branch="master")
40
41
  else:
41
42
  git.checkout_tag(repo=mpy_path, tag=tag)
@@ -76,7 +77,7 @@ def match_lib_with_mpy(version_tag: str, mpy_path: Path, lib_path: Path) -> bool
76
77
  micropython_lib_commits = read_micropython_lib_commits()
77
78
  # Make sure that the correct micropython-lib release is checked out
78
79
  # check if micropython-lib has matching tags
79
- if version_tag == "latest":
80
+ if version_tag in SET_PREVIEW:
80
81
  # micropython-lib is now a submodule
81
82
  result = git.checkout_commit("master", lib_path)
82
83
  if not result:
@@ -88,8 +89,10 @@ def match_lib_with_mpy(version_tag: str, mpy_path: Path, lib_path: Path) -> bool
88
89
  # micropython-lib is now a submodule
89
90
  result = git.checkout_tag(version_tag, lib_path)
90
91
  if not result:
91
- log.error("Could not checkout micropython-lib @master")
92
- return False
92
+ log.warning(f"Could not checkout micropython-lib @{version_tag}")
93
+ if not git.checkout_tag("master", lib_path):
94
+ log.error("Could not checkout micropython-lib @master")
95
+ return False
93
96
  return git.sync_submodules(mpy_path)
94
97
  else:
95
98
  log.info(
@@ -109,10 +112,10 @@ def fetch_repos(tag: str, mpy_path: Path, mpy_lib_path: Path):
109
112
  log.trace("no stubs repo found : {CONFIG.stub_path.parent}")
110
113
 
111
114
  if not tag:
112
- tag = "latest"
115
+ tag = V_PREVIEW
113
116
 
114
117
  log.info(f"Switching to {tag}")
115
- if tag == "latest":
118
+ if tag == V_PREVIEW:
116
119
  git.switch_branch(repo=mpy_path, branch="master")
117
120
  else:
118
121
  git.checkout_tag(repo=mpy_path, tag=tag)
stubber/utils/versions.py CHANGED
@@ -1,8 +1,21 @@
1
1
  """Handle versions of micropython based on the git tags in the repo """
2
2
 
3
+ from pathlib import Path
4
+
3
5
  from github import Github
4
6
  from packaging.version import parse
5
7
 
8
+ import stubber.basicgit as git
9
+ import stubber.utils as utils
10
+
11
+ OLDEST_VERSION = "1.16"
12
+ "This is the oldest MicroPython version to build the stubs on"
13
+
14
+ V_PREVIEW = "preview"
15
+ "Latest preview version"
16
+
17
+ SET_PREVIEW = {"preview", "latest", "master"}
18
+
6
19
 
7
20
  def clean_version(
8
21
  version: str,
@@ -15,9 +28,9 @@ def clean_version(
15
28
  ):
16
29
  "Clean up and transform the many flavours of versions"
17
30
  # 'v1.13.0-103-gb137d064e' --> 'v1.13-103'
18
-
19
31
  if version in {"", "-"}:
20
32
  return version
33
+ is_preview = "-preview" in version
21
34
  nibbles = version.split("-")
22
35
  ver_ = nibbles[0].lower().lstrip("v")
23
36
  if not patch and ver_ >= "1.10.0" and ver_ < "1.20.0" and ver_.endswith(".0"):
@@ -25,21 +38,35 @@ def clean_version(
25
38
  nibbles[0] = nibbles[0][:-2]
26
39
  if len(nibbles) == 1:
27
40
  version = nibbles[0]
28
- elif build:
41
+ elif build and not is_preview:
29
42
  version = "-".join(nibbles) if commit else "-".join(nibbles[:-1])
30
43
  else:
31
44
  # version = "-".join((nibbles[0], LATEST))
32
45
  # HACK: this is not always right, but good enough most of the time
33
- version = "latest"
46
+ if is_preview:
47
+ version = "-".join((nibbles[0], V_PREVIEW))
48
+ else:
49
+ version = V_PREVIEW
34
50
  if flat:
35
- version = version.strip().replace(".", "_")
51
+ version = version.strip().replace(".", "_").replace("-", "_")
36
52
  else:
37
- version = version.strip().replace("_", ".")
53
+ version = version.strip().replace("_preview", "-preview").replace("_", ".")
38
54
 
39
55
  if drop_v:
40
56
  version = version.lstrip("v")
41
- elif not version.startswith("v") and version.lower() != "latest":
57
+ elif not version.startswith("v") and version.lower() not in SET_PREVIEW:
42
58
  version = "v" + version
59
+ if version == "latest":
60
+ version = V_PREVIEW
61
+ return version
62
+
63
+
64
+ def checkedout_version(path: Path, flat: bool = False) -> str:
65
+ """Get the checked-out version of the repo"""
66
+ version = git.get_local_tag(path.as_posix())
67
+ if not version:
68
+ raise ValueError("No valid Tag found")
69
+ version = utils.clean_version(version, flat=flat, drop_v=False)
43
70
  return version
44
71
 
45
72
 
@@ -50,4 +77,18 @@ def micropython_versions(start: str = "v1.9.2"):
50
77
  repo = g.get_repo("micropython/micropython")
51
78
  return [tag.name for tag in repo.get_tags() if parse(tag.name) >= parse(start)]
52
79
  except Exception:
53
- return ["v1.19.1", "v1.19", "v1.18", "v1.17", "v1.16", "v1.15", "v1.14", "v1.13", "v1.12", "v1.11", "v1.10", "v1.9.4", "v1.9.3"]
80
+ return [
81
+ "v1.19.1",
82
+ "v1.19",
83
+ "v1.18",
84
+ "v1.17",
85
+ "v1.16",
86
+ "v1.15",
87
+ "v1.14",
88
+ "v1.13",
89
+ "v1.12",
90
+ "v1.11",
91
+ "v1.10",
92
+ "v1.9.4",
93
+ "v1.9.3",
94
+ ]
stubber/variants.py CHANGED
@@ -26,7 +26,7 @@ def create_variants(
26
26
  *,
27
27
  target_path: Optional[Path] = None,
28
28
  version: str = "",
29
- make_variants: List[CreateStubsVariant] = ALL_VARIANTS,
29
+ make_variants: List[CreateStubsVariant] = ALL_VARIANTS[:3],
30
30
  update_modules: bool = True,
31
31
  ):
32
32
  """
@@ -50,7 +50,7 @@ def create_variants(
50
50
  ctx = codemod.CodemodContext()
51
51
  base_file = base_path / "createstubs.py"
52
52
  log.info(f"Reading : {base_file}")
53
- base_txt = (base_path / "createstubs.py").read_text()
53
+ base_txt = (base_path / "createstubs.py").read_text(encoding="utf-8")
54
54
  base_module = cst.parse_module(base_txt)
55
55
 
56
56
  for var in make_variants:
@@ -89,7 +89,7 @@ def create_variants(
89
89
 
90
90
  # str -> path
91
91
  # read minified file
92
- minified_txt = minified_path.read_text()
92
+ minified_txt = minified_path.read_text(encoding="utf-8")
93
93
  cross_compile(minified_txt, mpy_path, version=version)
94
94
 
95
95
 
stubber/board/logging.py DELETED
@@ -1,99 +0,0 @@
1
- import sys
2
-
3
- CRITICAL = 50
4
- ERROR = 40
5
- WARNING = 30
6
- INFO = 20
7
- DEBUG = 10
8
- NOTSET = 0
9
-
10
- _level_dict = {
11
- CRITICAL: "CRIT",
12
- ERROR: "ERROR",
13
- WARNING: "WARN",
14
- INFO: "INFO",
15
- DEBUG: "DEBUG",
16
- }
17
-
18
- _stream = sys.stderr
19
-
20
-
21
- class Logger:
22
-
23
- level = NOTSET
24
-
25
- def __init__(self, name):
26
- self.name = name
27
-
28
- def _level_str(self, level):
29
- l = _level_dict.get(level)
30
- if l is not None:
31
- return l
32
- return "LVL%s" % level
33
-
34
- def setLevel(self, level):
35
- self.level = level
36
-
37
- def isEnabledFor(self, level):
38
- return level >= (self.level or _level)
39
-
40
- def log(self, level, msg, *args):
41
- if level >= (self.level or _level):
42
- _stream.write("%-6s:%-8s:" % (self._level_str(level), self.name))
43
- if not args:
44
- print(msg, file=_stream)
45
- else:
46
- print(msg % args, file=_stream)
47
-
48
- def debug(self, msg, *args):
49
- self.log(DEBUG, msg, *args)
50
-
51
- def info(self, msg, *args):
52
- self.log(INFO, msg, *args)
53
-
54
- def warning(self, msg, *args):
55
- self.log(WARNING, msg, *args)
56
-
57
- def error(self, msg, *args):
58
- self.log(ERROR, msg, *args)
59
-
60
- def critical(self, msg, *args):
61
- self.log(CRITICAL, msg, *args)
62
-
63
- # def exc(self, e, msg, *args):
64
- # self.log(ERROR, msg, *args)
65
- # sys.print_exception(e, _stream) # type : disable
66
-
67
- def exception(self, msg, *args):
68
- self.critical(sys.exc_info()[1], msg, *args)
69
-
70
-
71
- _level = INFO
72
- _loggers = {}
73
-
74
-
75
- def getLogger(name):
76
- if name in _loggers:
77
- return _loggers[name]
78
- l = Logger(name)
79
- _loggers[name] = l
80
- return l
81
-
82
-
83
- def info(msg, *args):
84
- getLogger(None).info(msg, *args)
85
-
86
-
87
- def debug(msg, *args):
88
- getLogger(None).debug(msg, *args)
89
-
90
-
91
- def basicConfig(level=INFO, filename=None, stream=None, format=None):
92
- global _level, _stream
93
- _level = level
94
- if stream:
95
- _stream = stream
96
- if filename is not None:
97
- print("logging.basicConfig: filename arg is not supported")
98
- if format is not None:
99
- print("logging.basicConfig: format arg is not supported")