@@ -1170,12 +1170,27 @@ def get_tools_dir(self):
1170
1170
# mbed Classic deployed tools
1171
1171
paths .append ([self .path , '.temp' , 'tools' ])
1172
1172
1173
- fl = 'make.py'
1173
+ return self ._find_file_paths (paths , 'make.py' )
1174
+
1175
+ def get_requirements (self ):
1176
+ paths = []
1177
+ mbed_os_path = self .get_os_dir ()
1178
+ if mbed_os_path :
1179
+ paths .append ([mbed_os_path ])
1180
+ # mbed-os not identified but tools found under cwd/tools
1181
+ paths .append ([self .path , 'core' ])
1182
+ # mbed Classic deployed tools
1183
+ paths .append ([self .path , '.temp' , 'tools' ])
1184
+ # current dir
1185
+ paths .append ([self .path ])
1186
+
1187
+ return self ._find_file_paths (paths , 'requirements.txt' )
1188
+
1189
+ def _find_file_paths (self , paths , fl ):
1174
1190
for p in paths :
1175
1191
path = os .path .join (* p )
1176
1192
if os .path .isdir (path ) and os .path .isfile (os .path .join (path , fl )):
1177
1193
return os .path .join (path )
1178
-
1179
1194
return None
1180
1195
1181
1196
def get_env (self ):
@@ -1204,16 +1219,13 @@ def post_action(self):
1204
1219
os .path .isfile (os .path .join (mbed_tools_path , 'default_settings.py' ))):
1205
1220
shutil .copy (os .path .join (mbed_tools_path , 'default_settings.py' ), os .path .join (self .path , 'mbed_settings.py' ))
1206
1221
1207
- mbed_os_path = self .get_os_dir ()
1208
- if not mbed_os_path :
1209
- return False
1210
-
1222
+ req_path = self .get_requirements () or self .path
1223
+ req_file = 'requirements.txt'
1211
1224
missing = []
1212
- fname = 'requirements.txt'
1213
1225
try :
1214
- import pip
1215
- installed_packages = [ package . project_name . lower () for package in pip . get_installed_distributions ()]
1216
- with open ( os . path . join ( mbed_os_path , fname ), 'r' ) as f :
1226
+ with open ( os . path . join ( os . path . join ( req_path , req_file )), 'r' ) as f :
1227
+ import pip
1228
+ installed_packages = [ package . project_name . lower () for package in pip . get_installed_distributions ()]
1217
1229
for line in f .read ().splitlines ():
1218
1230
pkg = re .sub (r'^([\w-]+).*$' , r'\1' , line ).lower ()
1219
1231
if not pkg in installed_packages :
@@ -1229,7 +1241,7 @@ def post_action(self):
1229
1241
"The mbed build tools in this program require Python modules that are not installed.\n "
1230
1242
"This might prevent compiling code or exporting to IDEs and other toolchains.\n "
1231
1243
"The missing Python modules are: %s\n "
1232
- "You can install all missing modules by running \" pip install -r %s\" in \" %s\" " % (', ' .join (missing ), fname , mbed_os_path ))
1244
+ "You can install all missing modules by running \" pip install -r %s\" in \" %s\" " % (', ' .join (missing ), req_file , req_path ))
1233
1245
1234
1246
def add_tools (self , path ):
1235
1247
if not os .path .exists (path ):
0 commit comments