3939
4040import pkg_resources
4141
42- NOT_BUNDLE_LIBRARIES = [
42+ LINUX_LIBRARIES = [
4343 "adafruit-blinka" ,
4444 "adafruit-blinka-bleio" ,
4545 "adafruit-blinka-displayio" ,
@@ -56,20 +56,22 @@ def add_file(bundle, src_file, zip_name):
5656 return file_sector_size
5757
5858def get_module_name (library_path ):
59- """Figure out the module or package name anbd return it"""
60- url = subprocess .run ('git remote get-url origin' , shell = True , stdout = subprocess .PIPE , cwd = library_path )
61- url = url .stdout .decode ("utf-8" , errors = "ignore" ).strip ().lower ()
62- module_name = url [:- 4 ].split ("/" )[- 1 ].replace ("_" , "-" )
63- return module_name
59+ """Figure out the module or package name and return it"""
60+ repo = subprocess .run ('git remote get-url origin' , shell = True , stdout = subprocess .PIPE , cwd = library_path )
61+ repo = repo .stdout .decode ("utf-8" , errors = "ignore" ).strip ().lower ()
62+ module_name = repo [:- 4 ].split ("/" )[- 1 ].replace ("_" , "-" )
63+ return module_name , repo
6464
65- def get_bundle_requirements (directory ):
65+ def get_bundle_requirements (directory , package_list ):
6666 """
6767 Open the requirements.txt if it exists
6868 Remove anything that shouldn't be a requirement like Adafruit_Blinka
6969 Return the list
7070 """
7171
72- libraries = []
72+ pypi_reqs = [] # For multiple bundle dependency
73+ dependencies = [] # For intra-bundle dependency
74+
7375 path = directory + "/requirements.txt"
7476 if os .path .exists (path ):
7577 with open (path , "r" ) as file :
@@ -84,25 +86,39 @@ def get_bundle_requirements(directory):
8486 if any (operators in line for operators in [">" , "<" , "=" ]):
8587 # Remove everything after any pip style version specifiers
8688 line = re .split ("[<|>|=|]" , line )[0 ]
87- if line not in libraries and line not in NOT_BUNDLE_LIBRARIES :
88- libraries .append (line )
89- return libraries
89+ if line not in dependencies and line in package_list :
90+ dependencies .append (package_list [line ]["module_name" ])
91+ elif line not in pypi_reqs and line not in LINUX_LIBRARIES :
92+ pypi_reqs .append (line )
93+ return dependencies , pypi_reqs
9094
9195def build_bundle_json (libs , bundle_version , output_filename , package_folder_prefix ):
9296 """
9397 Generate a JSON file of all the libraries in libs
9498 """
95- library_submodules = {}
99+ packages = {}
96100 for library_path in libs :
97- library = {}
101+ package = {}
98102 package_info = build .get_package_info (library_path , package_folder_prefix )
99- module_name = get_module_name (library_path )
103+ module_name , repo = get_module_name (library_path )
100104 if package_info ["module_name" ] is not None :
101- library ["package" ] = package_info ["is_package" ]
102- library ["version" ] = package_info ["version" ]
103- library ["path" ] = "lib/" + package_info ["module_name" ]
104- library ["dependencies" ] = get_bundle_requirements (library_path )
105- library_submodules [module_name ] = library
105+ package ["module_name" ] = package_info ["module_name" ]
106+ package ["repo" ] = repo
107+ package ["is_folder" ] = package_info ["is_package" ]
108+ package ["version" ] = package_info ["version" ]
109+ package ["path" ] = "lib/" + package_info ["module_name" ]
110+ package ["library_path" ] = library_path
111+ packages [module_name ] = package
112+
113+ library_submodules = {}
114+ for id in packages :
115+ library = {}
116+ library ["package" ] = packages [id ]["is_folder" ]
117+ library ["version" ] = packages [id ]["version" ]
118+ library ["repo" ] = packages [id ]["repo" ]
119+ library ["path" ] = packages [id ]["path" ]
120+ library ["dependencies" ], library ["external_dependencies" ] = get_bundle_requirements (packages [id ]["library_path" ], packages )
121+ library_submodules [packages [id ]["module_name" ]] = library
106122 out_file = open (output_filename , "w" )
107123 json .dump (library_submodules , out_file )
108124 out_file .close ()
@@ -211,6 +227,7 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d
211227 if pkg :
212228 build_tools_version = pkg .version
213229
230+ """
214231 build_tools_fn = "z-build_tools_version-{}.ignore".format(
215232 build_tools_version)
216233 build_tools_fn = os.path.join(output_directory, build_tools_fn)
@@ -247,7 +264,7 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d
247264 VERSION=bundle_version))
248265 build_bundle(libs, bundle_version, zip_filename, package_folder_prefix,
249266 build_tools_version=build_tools_version, example_bundle=True)
250-
267+ """
251268 # Build Bundle JSON
252269 json_filename = os .path .join (output_directory ,
253270 filename_prefix + '-{VERSION}.json' .format (
0 commit comments