23
23
24
24
from stubber .publish .bump import bump_version
25
25
from stubber .publish .enums import StubSource
26
- from stubber .publish .package import StubSource
27
26
from stubber .publish .pypi import Version , get_pypi_versions
28
27
from stubber .utils .config import CONFIG
29
28
from stubber .utils .versions import clean_version
30
29
31
30
32
31
Status = NewType ("Status" , Dict [str , Union [str , None ]])
32
+ StubSources = List [Tuple [StubSource , Path ]]
33
33
34
34
35
35
class StubPackage :
@@ -60,7 +60,7 @@ def __init__(
60
60
package_name : str ,
61
61
version : str = "0.0.1" ,
62
62
description : str = "MicroPython stubs" ,
63
- stubs : Optional [List [ Tuple [ str , Path ]] ] = None ,
63
+ stubs : Optional [StubSources ] = None ,
64
64
json_data : Optional [Dict [str , Any ]] = None ,
65
65
):
66
66
"""
@@ -96,7 +96,7 @@ def __init__(
96
96
"""hash of the the stub files"""
97
97
self .create_update_pyproject_toml ()
98
98
99
- self .stub_sources : List [ Tuple [ str , Path ]] = []
99
+ self .stub_sources : StubSources = []
100
100
# save the stub sources
101
101
if stubs :
102
102
self .stub_sources = stubs
@@ -215,8 +215,7 @@ def to_dict(self) -> dict:
215
215
"publish" : self ._publish ,
216
216
"pkg_version" : str (self .pkg_version ),
217
217
"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 ],
220
219
"description" : self .description ,
221
220
"hash" : self .hash ,
222
221
"stub_hash" : self .stub_hash ,
@@ -259,6 +258,36 @@ def update_package_files(self) -> None:
259
258
self .create_readme ()
260
259
self .create_license ()
261
260
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
+
262
291
def copy_stubs (self ) -> None :
263
292
"""
264
293
Copy files from all listed stub folders to the package folder
@@ -269,23 +298,11 @@ def copy_stubs(self) -> None:
269
298
- 3 - remove *.py files from the package folder
270
299
"""
271
300
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:
289
306
raise FileNotFoundError (f"Could not find stub source folder { CONFIG .stub_path / fw_path } " )
290
307
291
308
# 1 - Copy the stubs to the package, directly in the package folder (no folders)
@@ -294,7 +311,7 @@ def copy_stubs(self) -> None:
294
311
stub_type , fw_path = self .stub_sources [n ]
295
312
296
313
try :
297
- log .debug (f"Copying { stub_type } from { fw_path } " )
314
+ log .debug (f"Copying { stub_type . value } from { fw_path } " )
298
315
shutil .copytree (
299
316
CONFIG .stub_path / fw_path ,
300
317
self .package_path ,
@@ -579,21 +596,21 @@ def are_package_sources_available(self) -> bool:
579
596
Check if (all) the packages sources exist.
580
597
"""
581
598
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
597
614
return ok
598
615
599
616
def update_package (self ) -> bool :
0 commit comments