Skip to content

Fix: Support for package types in requirements.txt #775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 31, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions mbed/mbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -1599,13 +1599,19 @@ def _find_file_paths(self, paths, fl):
return None

def requirements_contains(self, library_name):
req_path = self.get_requirements() or self.path
req_path = self.get_requirements()
if not req_path:
return False

req_file = 'requirements.txt'
with open(os.path.join(req_path, req_file), 'r') as f:
return library_name in f.read()

def check_requirements(self, show_warning=False):
req_path = self.get_requirements() or self.path
if not req_path:
return False

req_file = 'requirements.txt'
missing = []
try:
Expand All @@ -1615,17 +1621,17 @@ def check_requirements(self, show_warning=False):
for line in f.read().splitlines():
pkg = re.sub(r'-', '_', re.sub(r'^([^<>=@]+).*$', r'\1', line).lower())
pkg = re.sub(r'^(git|hg|svn|bzr)\+(.*)/([\w.-]+?)(\.(git|hg))?$', r'\3', pkg)
pkg = re.sub(r'\[([\w]+)\]', '', pkg)
if not pkg in installed_packages:
missing.append(pkg)

if missing and install_requirements:
try:
action("Auto-installing missing Python modules...")
action("Auto-installing missing Python modules (%s)..." % ', '.join(missing))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

pquery([python_cmd, '-m', 'pip', 'install', '-q', '-r', os.path.join(req_path, req_file)])
missing = []
except ProcessException:
pass

except (IOError, ImportError, OSError):
pass

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

return True


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