39
39
40
40
import pkg_resources
41
41
42
- NOT_BUNDLE_LIBRARIES = [
42
+ LINUX_LIBRARIES = [
43
43
"adafruit-blinka" ,
44
44
"adafruit-blinka-bleio" ,
45
45
"adafruit-blinka-displayio" ,
@@ -56,20 +56,22 @@ def add_file(bundle, src_file, zip_name):
56
56
return file_sector_size
57
57
58
58
def 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
64
64
65
- def get_bundle_requirements (directory ):
65
+ def get_bundle_requirements (directory , package_list ):
66
66
"""
67
67
Open the requirements.txt if it exists
68
68
Remove anything that shouldn't be a requirement like Adafruit_Blinka
69
69
Return the list
70
70
"""
71
71
72
- libraries = []
72
+ pypi_reqs = [] # For multiple bundle dependency
73
+ dependencies = [] # For intra-bundle dependency
74
+
73
75
path = directory + "/requirements.txt"
74
76
if os .path .exists (path ):
75
77
with open (path , "r" ) as file :
@@ -84,25 +86,39 @@ def get_bundle_requirements(directory):
84
86
if any (operators in line for operators in [">" , "<" , "=" ]):
85
87
# Remove everything after any pip style version specifiers
86
88
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
90
94
91
95
def build_bundle_json (libs , bundle_version , output_filename , package_folder_prefix ):
92
96
"""
93
97
Generate a JSON file of all the libraries in libs
94
98
"""
95
- library_submodules = {}
99
+ packages = {}
96
100
for library_path in libs :
97
- library = {}
101
+ package = {}
98
102
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 )
100
104
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
106
122
out_file = open (output_filename , "w" )
107
123
json .dump (library_submodules , out_file )
108
124
out_file .close ()
@@ -211,6 +227,7 @@ def build_bundles(filename_prefix, output_directory, library_location, library_d
211
227
if pkg :
212
228
build_tools_version = pkg .version
213
229
230
+ """
214
231
build_tools_fn = "z-build_tools_version-{}.ignore".format(
215
232
build_tools_version)
216
233
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
247
264
VERSION=bundle_version))
248
265
build_bundle(libs, bundle_version, zip_filename, package_folder_prefix,
249
266
build_tools_version=build_tools_version, example_bundle=True)
250
-
267
+ """
251
268
# Build Bundle JSON
252
269
json_filename = os .path .join (output_directory ,
253
270
filename_prefix + '-{VERSION}.json' .format (
0 commit comments