39
39
40
40
import pkg_resources
41
41
42
- NOT_BUNDLE_LIBRARIES = [
42
+ BLINKA_LIBRARIES = [
43
43
"adafruit-blinka" ,
44
44
"adafruit-blinka-bleio" ,
45
45
"adafruit-blinka-displayio" ,
46
+ "adafruit-blinka-pyportal" ,
47
+ "adafruit-python-extended-bus" ,
46
48
"pyserial" ,
47
49
]
48
50
@@ -56,20 +58,22 @@ def add_file(bundle, src_file, zip_name):
56
58
return file_sector_size
57
59
58
60
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
61
+ """Figure out the module or package name and return it"""
62
+ repo = subprocess .run ('git remote get-url origin' , shell = True , stdout = subprocess .PIPE , cwd = library_path )
63
+ repo = repo .stdout .decode ("utf-8" , errors = "ignore" ).strip ().lower ()
64
+ module_name = repo [:- 4 ].split ("/" )[- 1 ].replace ("_" , "-" )
65
+ return module_name , repo
64
66
65
- def get_bundle_requirements (directory ):
67
+ def get_bundle_requirements (directory , package_list ):
66
68
"""
67
69
Open the requirements.txt if it exists
68
70
Remove anything that shouldn't be a requirement like Adafruit_Blinka
69
71
Return the list
70
72
"""
71
73
72
- libraries = []
74
+ pypi_reqs = [] # For multiple bundle dependency
75
+ dependencies = [] # For intra-bundle dependency
76
+
73
77
path = directory + "/requirements.txt"
74
78
if os .path .exists (path ):
75
79
with open (path , "r" ) as file :
@@ -84,25 +88,41 @@ def get_bundle_requirements(directory):
84
88
if any (operators in line for operators in [">" , "<" , "=" ]):
85
89
# Remove everything after any pip style version specifiers
86
90
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
91
+ if line not in dependencies and line in package_list :
92
+ dependencies .append (package_list [line ]["module_name" ])
93
+ elif line not in pypi_reqs and line not in BLINKA_LIBRARIES :
94
+ pypi_reqs .append (line )
95
+ return dependencies , pypi_reqs
90
96
91
97
def build_bundle_json (libs , bundle_version , output_filename , package_folder_prefix ):
92
98
"""
93
99
Generate a JSON file of all the libraries in libs
94
100
"""
95
- library_submodules = {}
101
+ packages = {}
96
102
for library_path in libs :
97
- library = {}
103
+ package = {}
98
104
package_info = build .get_package_info (library_path , package_folder_prefix )
99
- module_name = get_module_name (library_path )
105
+ module_name , repo = get_module_name (library_path )
100
106
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
107
+ package ["module_name" ] = package_info ["module_name" ]
108
+ package ["pypi_name" ] = module_name
109
+ package ["repo" ] = repo
110
+ package ["is_folder" ] = package_info ["is_package" ]
111
+ package ["version" ] = package_info ["version" ]
112
+ package ["path" ] = "lib/" + package_info ["module_name" ]
113
+ package ["library_path" ] = library_path
114
+ packages [module_name ] = package
115
+
116
+ library_submodules = {}
117
+ for id in packages :
118
+ library = {}
119
+ library ["package" ] = packages [id ]["is_folder" ]
120
+ library ["pypi_name" ] = packages [id ]["pypi_name" ]
121
+ library ["version" ] = packages [id ]["version" ]
122
+ library ["repo" ] = packages [id ]["repo" ]
123
+ library ["path" ] = packages [id ]["path" ]
124
+ library ["dependencies" ], library ["external_dependencies" ] = get_bundle_requirements (packages [id ]["library_path" ], packages )
125
+ library_submodules [packages [id ]["module_name" ]] = library
106
126
out_file = open (output_filename , "w" )
107
127
json .dump (library_submodules , out_file )
108
128
out_file .close ()
0 commit comments