Skip to content

Commit d1cd2ef

Browse files
committed
fix:board allcaps
1 parent 780c317 commit d1cd2ef

File tree

6 files changed

+70
-53
lines changed

6 files changed

+70
-53
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",

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import click
44
from loguru import logger as log
55
from stubber.commands.cli import stubber_cli
6-
from stubber.publish.package import GENERIC_L
6+
from stubber.publish.package import GENERIC_U
77
from stubber.publish.publish import publish_multiple
88
from tabulate import tabulate
99
from stubber.utils.config import CONFIG
@@ -35,7 +35,7 @@
3535
"-b",
3636
"boards",
3737
multiple=True,
38-
default=[GENERIC_L], # or "auto" ?
38+
default=[GENERIC_U], # or "auto" ?
3939
show_default=True,
4040
help="multiple: ",
4141
)

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 & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131

3232
Status = NewType("Status", Dict[str, Union[str, None]])
33+
StubSources = List[Tuple[str, Path]]
3334

3435

3536
class StubPackage:
@@ -60,7 +61,7 @@ def __init__(
6061
package_name: str,
6162
version: str = "0.0.1",
6263
description: str = "MicroPython stubs",
63-
stubs: Optional[List[Tuple[str, Path]]] = None,
64+
stubs: Optional[StubSources] = None,
6465
json_data: Optional[Dict[str, Any]] = None,
6566
):
6667
"""
@@ -96,7 +97,7 @@ def __init__(
9697
"""hash of the the stub files"""
9798
self.create_update_pyproject_toml()
9899

99-
self.stub_sources: List[Tuple[str, Path]] = []
100+
self.stub_sources: StubSources = []
100101
# save the stub sources
101102
if stubs:
102103
self.stub_sources = stubs
@@ -215,8 +216,7 @@ def to_dict(self) -> dict:
215216
"publish": self._publish,
216217
"pkg_version": str(self.pkg_version),
217218
"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],
219+
"stub_sources": [(name, Path(path).as_posix()) for (name, path) in self.stub_sources],
220220
"description": self.description,
221221
"hash": self.hash,
222222
"stub_hash": self.stub_hash,
@@ -259,6 +259,36 @@ def update_package_files(self) -> None:
259259
self.create_readme()
260260
self.create_license()
261261

262+
@staticmethod
263+
def update_sources(stub_sources: StubSources) -> StubSources:
264+
"""
265+
Update the stub sources to:
266+
- use the -merged folder for the firmware sources
267+
- and fallback to use the GENERIC folder for the frozen sources
268+
"""
269+
updated_sources = []
270+
for stub_type, fw_path in stub_sources:
271+
# update to use -merged
272+
if stub_type == StubSource.FIRMWARE:
273+
# Check if -merged folder exists and use that instead
274+
if fw_path.name.endswith("-merged"):
275+
merged_path = fw_path
276+
else:
277+
merged_path = fw_path.with_name(f"{fw_path.name}-merged")
278+
if (CONFIG.stub_path / merged_path).exists():
279+
updated_sources.append((stub_type, merged_path))
280+
else:
281+
updated_sources.append((stub_type, fw_path))
282+
elif stub_type == StubSource.FROZEN:
283+
# use if folder exists , else use GENERIC folder
284+
if (CONFIG.stub_path / fw_path).exists():
285+
updated_sources.append((stub_type, fw_path))
286+
else:
287+
updated_sources.append((stub_type, fw_path.with_name("GENERIC")))
288+
else:
289+
updated_sources.append((stub_type, fw_path))
290+
return updated_sources
291+
262292
def copy_stubs(self) -> None:
263293
"""
264294
Copy files from all listed stub folders to the package folder
@@ -269,23 +299,11 @@ def copy_stubs(self) -> None:
269299
- 3 - remove *.py files from the package folder
270300
"""
271301
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:
302+
# update to -menrge and fallback to GENERIC
303+
self.stub_sources = self.update_sources(self.stub_sources)
304+
# Check if all stub source folders exist
305+
for stub_type, fw_path in self.stub_sources:
306+
if not (CONFIG.stub_path / fw_path).exists(): # and stub_type != StubSource.FROZEN:
289307
raise FileNotFoundError(f"Could not find stub source folder {CONFIG.stub_path / fw_path}")
290308

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

296314
try:
297-
log.debug(f"Copying {stub_type} from {fw_path}")
315+
log.debug(f"Copying {stub_type.value} from {fw_path}")
298316
shutil.copytree(
299317
CONFIG.stub_path / fw_path,
300318
self.package_path,
@@ -579,21 +597,21 @@ def are_package_sources_available(self) -> bool:
579597
Check if (all) the packages sources exist.
580598
"""
581599
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)
600+
for name, path in self.update_sources(self.stub_sources):
601+
if (CONFIG.stub_path / path).exists():
602+
continue
603+
if name == StubSource.FROZEN:
604+
# not a blocking issue if there are no frozen stubs, perhaps this port/board does not have any
605+
continue
606+
# todo: below is a workaround for different types, but where is the source of this difference coming from?
607+
msg = (
608+
f"{self.package_name}: source '{name.value}' not found: {CONFIG.stub_path / path}"
609+
if isinstance(name, StubSource)
610+
else f"{self.package_name}: source '{name}' not found: {CONFIG.stub_path / path}"
611+
)
612+
self.status["error"] = msg
613+
log.debug(msg)
614+
ok = False
597615
return ok
598616

599617
def update_package(self) -> bool:

0 commit comments

Comments
 (0)