Skip to content

Commit 99e9fb2

Browse files
committed
Improved detection of missing Python modules. Also improved missing modules warning
1 parent 8032fb6 commit 99e9fb2

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

mbed/mbed.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -856,23 +856,24 @@ def post_clone(self):
856856
os.path.isfile(os.path.join(mbed_os_path, 'tools/default_settings.py'))):
857857
shutil.copy(os.path.join(mbed_os_path, 'tools/default_settings.py'), os.path.join(self.path, 'mbed_settings.py'))
858858

859+
859860
missing = []
860861
fname = 'requirements.txt'
861-
with open(os.path.join(mbed_os_path, fname), 'r') as f:
862-
for line in f.read().splitlines():
863-
print line
864-
try:
865-
exec("import " + line)
866-
except:
867-
missing.append(line)
868-
raise
862+
try:
863+
import pkgutil
864+
with open(os.path.join(mbed_os_path, fname), 'r') as f:
865+
for line in f.read().splitlines():
866+
if pkgutil.find_loader(line) is None:
867+
missing.append(line)
868+
except:
869+
pass
869870

870871
if len(missing):
871-
print missing
872872
warning(
873-
"mbed OS and tools in this program have unmet dependencies with your Python environment, which might prevent you from compiling or exporting.\n"
873+
"Detected unmet Python environment dependencies for mbed OS and tools in this program.\n"
874+
"This might prevent you from compiling your code or exporting to IDEs and other toolchains.\n"
874875
"The missing Python modules are: %s\n"
875-
"You can install all missing dependecies by opening a command prompt in \"%s\" and running \"pip install %s\"" % (', '.join(missing), mbed_os_path, fname))
876+
"You can install all missing dependencies by opening a command prompt in \"%s\" and running \"pip install %s\"" % (', '.join(missing), mbed_os_path, fname))
876877

877878

878879
def formaturl(url, format="default"):
@@ -988,6 +989,9 @@ def new(name, scm='git', depth=None, protocol=None):
988989
if d_path:
989990
os.chdir(d_path)
990991

992+
program = Program.get_program(d_path)
993+
program.post_clone()
994+
991995

992996
# Import command
993997
@subcommand('import',
@@ -1032,13 +1036,18 @@ def import_(url, path=None, depth=None, protocol=None, top=True):
10321036
with cd(repo.path):
10331037
deploy(depth=depth, protocol=protocol)
10341038

1039+
if top:
1040+
program = Program.get_program(repo.path)
1041+
program.post_clone()
1042+
10351043

10361044
# Deploy command
10371045
@subcommand('deploy',
10381046
dict(name='--depth', nargs='?', help='Number of revisions to fetch from the remote repository. Default: all revisions.'),
10391047
dict(name='--protocol', nargs='?', help='Transport protocol for the source control management. Supported: https, http, ssh, git. Default: inferred from URL.'),
10401048
help="Import missing dependencies in the current program or library.")
10411049
def deploy(depth=None, protocol=None):
1050+
sys.exit(1)
10421051
repo = Repo.fromrepo()
10431052
repo.scm.ignores(repo)
10441053

@@ -1051,9 +1060,6 @@ def deploy(depth=None, protocol=None):
10511060
import_(lib.fullurl, lib.path, depth=depth, protocol=protocol, top=False)
10521061
repo.scm.ignore(repo, relpath(repo.path, lib.path))
10531062

1054-
program = Program.get_program()
1055-
program.post_clone()
1056-
10571063

10581064
# Add library command
10591065
@subcommand('add',

0 commit comments

Comments
 (0)