Skip to content

Commit b53f8f7

Browse files
authored
Merge pull request #325 from Josverl/fix/board_allcaps
fix:board allcaps
2 parents 780c317 + 8322549 commit b53f8f7

File tree

7 files changed

+75
-55
lines changed

7 files changed

+75
-55
lines changed

.vscode/launch.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@
3333
"args": [
3434
"-v",
3535
"-v",
36-
"publish",
36+
"build",
3737
"--port",
3838
"esp32",
3939
"--board",
40-
"um_tinypico",
41-
"--pypi",
42-
"--dry-run",
43-
"--build",
40+
"S3",
41+
// "--pypi",
42+
// "--dry-run",
4443
// "switch",
4544
// "v1.19.1"
4645
// "get-frozen",

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repo-path = "./repos"
88

99
[tool.poetry]
1010
name = "micropython-stubber"
11-
version = "1.12.1"
11+
version = "1.12.2"
1212
description = "Tooling to create and maintain stubs for MicroPython"
1313
authors = ["Jos Verlinde <jos_verlinde@hotmail.com>"]
1414
license = "MIT"

src/stubber/commands/build_cmd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import click
66
from loguru import logger as log
77
from stubber.commands.cli import stubber_cli
8-
from stubber.publish.package import GENERIC_L
8+
from stubber.publish.package import GENERIC_U
99
from stubber.publish.publish import build_multiple
1010
from tabulate import tabulate
1111
from stubber.utils.config import CONFIG
@@ -37,7 +37,7 @@
3737
"-b",
3838
"boards",
3939
multiple=True,
40-
default=[GENERIC_L], # or "auto" ?
40+
default=[GENERIC_U], # or "auto" ?
4141
show_default=True,
4242
help="multiple: ",
4343
)

src/stubber/commands/publish_cmd.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
"""
2+
Commandline interface to publish stubs.
3+
"""
4+
15
from typing import List, Union
26

37
import click
48
from loguru import logger as log
59
from stubber.commands.cli import stubber_cli
6-
from stubber.publish.package import GENERIC_L
10+
from stubber.publish.package import GENERIC_U
711
from stubber.publish.publish import publish_multiple
812
from tabulate import tabulate
913
from stubber.utils.config import CONFIG
@@ -35,7 +39,7 @@
3539
"-b",
3640
"boards",
3741
multiple=True,
38-
default=[GENERIC_L], # or "auto" ?
42+
default=[GENERIC_U], # or "auto" ?
3943
show_default=True,
4044
help="multiple: ",
4145
)

src/stubber/publish/package.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
log.add(sys.stderr, level="INFO", backtrace=True, diagnose=True)
2828

2929

30-
def package_name(pkg_type: str, *, port: str = "", board: str = "", family:str="micropython", **kwargs) -> str:
30+
def package_name(pkg_type: str, *, port: str = "", board: str = "", family: str = "micropython", **kwargs) -> str:
3131
"generate a package name for the given package type"
3232
if pkg_type == COMBO_STUBS:
3333
# # {family}-{port}-{board}-stubs
@@ -51,7 +51,7 @@ def package_name(pkg_type: str, *, port: str = "", board: str = "", family:str="
5151
def get_package(
5252
db: PysonDB,
5353
*,
54-
pkg_type:str,
54+
pkg_type: str,
5555
version: str,
5656
port: str,
5757
board: str = GENERIC_L,
@@ -109,7 +109,7 @@ def create_package(
109109
port: str = "",
110110
board: str = "",
111111
family: str = "micropython",
112-
pkg_type:str=COMBO_STUBS,
112+
pkg_type: str = COMBO_STUBS,
113113
) -> StubPackage: # sourcery skip: merge-duplicate-blocks, remove-redundant-if
114114
"""
115115
create and initialize a package with the correct sources
@@ -164,6 +164,6 @@ def combo_sources(family: str, port: str, board: str, ver_flat: str) -> List[Tup
164164
),
165165
(
166166
StubSource.CORE,
167-
Path("micropython_core"), # TODO : Add version to core stubs
167+
Path(f"{family}-core"), # TODO : Add version to core stubs
168168
),
169169
]

src/stubber/publish/publish.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
from stubber.publish.enums import COMBO_STUBS
1212
from stubber.publish.package import get_package
1313
from stubber.utils.config import CONFIG
14-
from stubber.publish.package import GENERIC_L
14+
from stubber.publish.package import GENERIC_U
1515

1616

1717
def build_multiple(
1818
family: str = "micropython",
1919
versions: List[str] = ["v1.19.1"],
2020
ports: List[str] = ["auto"],
21-
boards: List[str] = [GENERIC_L],
21+
boards: List[str] = [GENERIC_U],
2222
production: bool = False,
2323
clean: bool = False,
2424
force: bool = False,
@@ -47,7 +47,7 @@ def publish_multiple(
4747
family: str = "micropython",
4848
versions: List[str] = ["v1.19.1"],
4949
ports: List[str] = ["auto"],
50-
boards: List[str] = [GENERIC_L],
50+
boards: List[str] = [GENERIC_U],
5151
production: bool = False,
5252
clean: bool = False,
5353
build: bool = False,

src/stubber/publish/stubpacker.py

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323

2424
from stubber.publish.bump import bump_version
2525
from stubber.publish.enums import StubSource
26-
from stubber.publish.package import StubSource
2726
from stubber.publish.pypi import Version, get_pypi_versions
2827
from stubber.utils.config import CONFIG
2928
from stubber.utils.versions import clean_version
3029

3130

3231
Status = NewType("Status", Dict[str, Union[str, None]])
32+
StubSources = List[Tuple[StubSource, Path]]
3333

3434

3535
class StubPackage:
@@ -60,7 +60,7 @@ def __init__(
6060
package_name: str,
6161
version: str = "0.0.1",
6262
description: str = "MicroPython stubs",
63-
stubs: Optional[List[Tuple[str, Path]]] = None,
63+
stubs: Optional[StubSources] = None,
6464
json_data: Optional[Dict[str, Any]] = None,
6565
):
6666
"""
@@ -96,7 +96,7 @@ def __init__(
9696
"""hash of the the stub files"""
9797
self.create_update_pyproject_toml()
9898

99-
self.stub_sources: List[Tuple[str, Path]] = []
99+
self.stub_sources: StubSources = []
100100
# save the stub sources
101101
if stubs:
102102
self.stub_sources = stubs
@@ -215,8 +215,7 @@ def to_dict(self) -> dict:
215215
"publish": self._publish,
216216
"pkg_version": str(self.pkg_version),
217217
"path": self.package_path.name, # only store the folder name , as it is relative to the publish folder
218-
# force all source paths to lowercase to avoid issues with case sensitive file systems
219-
"stub_sources": [(name, Path(path).as_posix().lower()) for (name, path) in self.stub_sources],
218+
"stub_sources": [(name, Path(path).as_posix()) for (name, path) in self.stub_sources],
220219
"description": self.description,
221220
"hash": self.hash,
222221
"stub_hash": self.stub_hash,
@@ -259,6 +258,36 @@ def update_package_files(self) -> None:
259258
self.create_readme()
260259
self.create_license()
261260

261+
@staticmethod
262+
def update_sources(stub_sources: StubSources) -> StubSources:
263+
"""
264+
Update the stub sources to:
265+
- use the -merged folder for the firmware sources
266+
- and fallback to use the GENERIC folder for the frozen sources
267+
"""
268+
updated_sources = []
269+
for stub_type, fw_path in stub_sources:
270+
# update to use -merged
271+
if stub_type == StubSource.FIRMWARE:
272+
# Check if -merged folder exists and use that instead
273+
if fw_path.name.endswith("-merged"):
274+
merged_path = fw_path
275+
else:
276+
merged_path = fw_path.with_name(f"{fw_path.name}-merged")
277+
if (CONFIG.stub_path / merged_path).exists():
278+
updated_sources.append((stub_type, merged_path))
279+
else:
280+
updated_sources.append((stub_type, fw_path))
281+
elif stub_type == StubSource.FROZEN:
282+
# use if folder exists , else use GENERIC folder
283+
if (CONFIG.stub_path / fw_path).exists():
284+
updated_sources.append((stub_type, fw_path))
285+
else:
286+
updated_sources.append((stub_type, fw_path.with_name("GENERIC")))
287+
else:
288+
updated_sources.append((stub_type, fw_path))
289+
return updated_sources
290+
262291
def copy_stubs(self) -> None:
263292
"""
264293
Copy files from all listed stub folders to the package folder
@@ -269,23 +298,11 @@ def copy_stubs(self) -> None:
269298
- 3 - remove *.py files from the package folder
270299
"""
271300
try:
272-
# First check if all stub source folders exist
273-
for n in range(len(self.stub_sources)):
274-
stub_type, fw_path = self.stub_sources[n]
275-
# update to use -merged
276-
if stub_type == StubSource.FIRMWARE:
277-
# Check if -merged folder exists and use that instead
278-
if fw_path.name.endswith("-merged"):
279-
merged_path = fw_path
280-
else:
281-
merged_path = fw_path.with_name(f"{fw_path.name}-merged")
282-
if (CONFIG.stub_path / merged_path).exists():
283-
stub_type = StubSource.MERGED
284-
# Update the source list
285-
self.stub_sources[n] = (stub_type, merged_path)
286-
fw_path = merged_path
287-
# check if path exists
288-
if not (CONFIG.stub_path / fw_path).exists() and stub_type != StubSource.FROZEN:
301+
# update to -menrge and fallback to GENERIC
302+
self.stub_sources = self.update_sources(self.stub_sources)
303+
# Check if all stub source folders exist
304+
for stub_type, fw_path in self.stub_sources:
305+
if not (CONFIG.stub_path / fw_path).exists(): # and stub_type != StubSource.FROZEN:
289306
raise FileNotFoundError(f"Could not find stub source folder {CONFIG.stub_path / fw_path}")
290307

291308
# 1 - Copy the stubs to the package, directly in the package folder (no folders)
@@ -294,7 +311,7 @@ def copy_stubs(self) -> None:
294311
stub_type, fw_path = self.stub_sources[n]
295312

296313
try:
297-
log.debug(f"Copying {stub_type} from {fw_path}")
314+
log.debug(f"Copying {stub_type.value} from {fw_path}")
298315
shutil.copytree(
299316
CONFIG.stub_path / fw_path,
300317
self.package_path,
@@ -579,21 +596,21 @@ def are_package_sources_available(self) -> bool:
579596
Check if (all) the packages sources exist.
580597
"""
581598
ok = True
582-
for name, path in self.stub_sources:
583-
if not (CONFIG.stub_path / path).exists():
584-
# todo: below is a workaround for different types, but where is the source of this difference coming from?
585-
msg = (
586-
f"{self.package_name}: source '{name._value_}' not found: {CONFIG.stub_path / path}"
587-
if isinstance(name, StubSource)
588-
else f"{self.package_name}: source '{name}' not found: {CONFIG.stub_path / path}"
589-
)
590-
if name != StubSource.FROZEN:
591-
log.debug(msg)
592-
self.status["error"] = msg
593-
ok = False
594-
else:
595-
# not a blocking issue if there are no frozen stubs, perhaps this port/board does not have any
596-
log.debug(msg)
599+
for name, path in self.update_sources(self.stub_sources):
600+
if (CONFIG.stub_path / path).exists():
601+
continue
602+
if name == StubSource.FROZEN:
603+
# not a blocking issue if there are no frozen stubs, perhaps this port/board does not have any
604+
continue
605+
# todo: below is a workaround for different types, but where is the source of this difference coming from?
606+
msg = (
607+
f"{self.package_name}: source '{name.value}' not found: {CONFIG.stub_path / path}"
608+
if isinstance(name, StubSource) # type: ignore
609+
else f"{self.package_name}: source '{name}' not found: {CONFIG.stub_path / path}"
610+
)
611+
self.status["error"] = msg
612+
log.debug(msg)
613+
ok = False
597614
return ok
598615

599616
def update_package(self) -> bool:

0 commit comments

Comments
 (0)