2323
2424from stubber .publish .bump import bump_version
2525from stubber .publish .enums import StubSource
26- from stubber .publish .package import StubSource
2726from stubber .publish .pypi import Version , get_pypi_versions
2827from stubber .utils .config import CONFIG
2928from stubber .utils .versions import clean_version
3029
3130
3231Status = NewType ("Status" , Dict [str , Union [str , None ]])
32+ StubSources = List [Tuple [StubSource , Path ]]
3333
3434
3535class 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