3030
3131
3232Status = NewType ("Status" , Dict [str , Union [str , None ]])
33+ StubSources = List [Tuple [str , Path ]]
3334
3435
3536class 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