@@ -1170,12 +1170,27 @@ def get_tools_dir(self):
11701170 # mbed Classic deployed tools
11711171 paths .append ([self .path , '.temp' , 'tools' ])
11721172
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 ):
11741190 for p in paths :
11751191 path = os .path .join (* p )
11761192 if os .path .isdir (path ) and os .path .isfile (os .path .join (path , fl )):
11771193 return os .path .join (path )
1178-
11791194 return None
11801195
11811196 def get_env (self ):
@@ -1204,16 +1219,13 @@ def post_action(self):
12041219 os .path .isfile (os .path .join (mbed_tools_path , 'default_settings.py' ))):
12051220 shutil .copy (os .path .join (mbed_tools_path , 'default_settings.py' ), os .path .join (self .path , 'mbed_settings.py' ))
12061221
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'
12111224 missing = []
1212- fname = 'requirements.txt'
12131225 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 ()]
12171229 for line in f .read ().splitlines ():
12181230 pkg = re .sub (r'^([\w-]+).*$' , r'\1' , line ).lower ()
12191231 if not pkg in installed_packages :
@@ -1229,7 +1241,7 @@ def post_action(self):
12291241 "The mbed build tools in this program require Python modules that are not installed.\n "
12301242 "This might prevent compiling code or exporting to IDEs and other toolchains.\n "
12311243 "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 ))
12331245
12341246 def add_tools (self , path ):
12351247 if not os .path .exists (path ):
0 commit comments