Skip to content

Commit

Permalink
Merge pull request #889 from bridadan/fix_autoinstall_linux
Browse files Browse the repository at this point in the history
Parse environment markers when auto installing.
  • Loading branch information
mark-edgeworth authored May 3, 2019
2 parents a3d67fb + a6e9096 commit 47aa820
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions mbed/mbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,26 @@ def action_progress(line, sep):
if m.group(1) == "Checking out files":
show_progress('Checking out', (float(m.group(3)) / float(m.group(4))) * 100)

_environment_markers = {
"platform_system": platform.system()
}

_comparators = {
"!=": lambda a, b: a != b,
"==": lambda a, b: a == b,
}

def _eval_environment_marker(marker):
m = re.match(r'\s*([^!=]+)\s*([!=]+)\s*([^\s]*)', marker)
if m:
try:
environment_marker_value = _environment_markers[m.group(1)]
environment_marker_cmp = m.group(3).strip("\"'")
return _comparators[m.group(2)](environment_marker_value, environment_marker_cmp)
except KeyError as e:
pass

raise Exception("Unsupported environment marker: {}".format(marker))

# Repository object
class Repo(object):
Expand Down Expand Up @@ -1652,8 +1672,14 @@ def check_requirements(self, require_install=False):
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)
line_parts = line.split(";")

for line_part in line_parts[1:]:
if not _eval_environment_marker(line_part):
break
else:
if not pkg in installed_packages:
missing.append(pkg)

if missing and install_requirements and require_install:
try:
Expand Down

0 comments on commit 47aa820

Please sign in to comment.