Skip to content

Commit 919877e

Browse files
committed
Add support for package types in requirements.txt. Also fix python error when no requirements.txt file is present
1 parent 485a450 commit 919877e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

mbed/mbed.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,13 +1599,19 @@ def _find_file_paths(self, paths, fl):
15991599
return None
16001600

16011601
def requirements_contains(self, library_name):
1602-
req_path = self.get_requirements() or self.path
1602+
req_path = self.get_requirements()
1603+
if not req_path:
1604+
return None
1605+
16031606
req_file = 'requirements.txt'
16041607
with open(os.path.join(req_path, req_file), 'r') as f:
16051608
return library_name in f.read()
16061609

16071610
def check_requirements(self, show_warning=False):
16081611
req_path = self.get_requirements() or self.path
1612+
if not req_path:
1613+
return False
1614+
16091615
req_file = 'requirements.txt'
16101616
missing = []
16111617
try:
@@ -1615,17 +1621,17 @@ def check_requirements(self, show_warning=False):
16151621
for line in f.read().splitlines():
16161622
pkg = re.sub(r'-', '_', re.sub(r'^([^<>=@]+).*$', r'\1', line).lower())
16171623
pkg = re.sub(r'^(git|hg|svn|bzr)\+(.*)/([\w.-]+?)(\.(git|hg))?$', r'\3', pkg)
1624+
pkg = re.sub(r'\[([\w]+)\]', '', pkg)
16181625
if not pkg in installed_packages:
16191626
missing.append(pkg)
16201627

16211628
if missing and install_requirements:
16221629
try:
1623-
action("Auto-installing missing Python modules...")
1630+
action("Auto-installing missing Python modules (%s)..." % ', '.join(missing))
16241631
pquery([python_cmd, '-m', 'pip', 'install', '-q', '-r', os.path.join(req_path, req_file)])
16251632
missing = []
16261633
except ProcessException:
16271634
pass
1628-
16291635
except (IOError, ImportError, OSError):
16301636
pass
16311637

@@ -1644,6 +1650,8 @@ def check_requirements(self, show_warning=False):
16441650
else:
16451651
error(msg, 1)
16461652

1653+
return True
1654+
16471655

16481656
# Routines after cloning mbed-os
16491657
def post_action(self, check_reqs=True):

0 commit comments

Comments
 (0)