Skip to content

Commit 308dc9f

Browse files
authored
Merge pull request #833 from screamerbg/f/requirements-check
Feature: Requirements config option and handling
2 parents 88f1714 + fb420f0 commit 308dc9f

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

mbed/mbed.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,12 @@ def requirements_contains(self, library_name):
16201620
with open(os.path.join(req_path, req_file), 'r') as f:
16211621
return library_name in f.read()
16221622

1623-
def check_requirements(self, show_warning=False):
1623+
def check_requirements(self, require_install=False):
1624+
skip_requirements = self.get_cfg("NO_REQUIREMENTS", False)
1625+
if skip_requirements:
1626+
action("Skipping installed requirements check due to configuration flag.")
1627+
return True
1628+
16241629
req_path = self.get_requirements() or self.path
16251630
if not req_path:
16261631
return False
@@ -1638,7 +1643,7 @@ def check_requirements(self, show_warning=False):
16381643
if not pkg in installed_packages:
16391644
missing.append(pkg)
16401645

1641-
if missing and install_requirements:
1646+
if missing and install_requirements and require_install:
16421647
try:
16431648
action("Auto-installing missing Python modules (%s)..." % ', '.join(missing))
16441649
pquery([python_cmd, '-m', 'pip', 'install', '-q', '-r', os.path.join(req_path, req_file)])
@@ -1650,18 +1655,18 @@ def check_requirements(self, show_warning=False):
16501655

16511656
if missing:
16521657
msg = (
1653-
"Unable to auto-install required Python modules.\n"
1654-
"The mbed OS tools in this program require the following Python modules: %s\n"
1658+
"Missing Python modules were not auto-installed.\n"
1659+
"The Mbed OS tools in this program require the following Python modules: %s\n"
16551660
"You can install all missing modules by running \"pip install -r %s\" in \"%s\"" % (', '.join(missing), req_file, req_path))
16561661
if os.name == 'posix' and platform.system() == 'Darwin':
16571662
msg += "\nOn Mac you might have to install packages as your user by adding the \"--user\" flag"
16581663
elif os.name == 'posix':
16591664
msg += "\nOn Posix systems (Linux, etc) you might have to switch to superuser account or use \"sudo\""
16601665

1661-
if show_warning:
1662-
warning(msg)
1663-
else:
1666+
if require_install:
16641667
error(msg, 1)
1668+
else:
1669+
warning(msg)
16651670

16661671
return True
16671672

@@ -2640,7 +2645,7 @@ def compile_(toolchain=None, target=None, macro=False, profile=False,
26402645
args = remainder
26412646
# Find the root of the program
26422647
program = Program(getcwd(), True)
2643-
program.check_requirements(True)
2648+
program.check_requirements()
26442649
# Remember the original path. this is needed for compiling only the libraries and tests for the current folder.
26452650
orig_path = getcwd()
26462651
orig_target = target
@@ -2800,7 +2805,7 @@ def test_(toolchain=None, target=None, macro=False, compile_list=False, run_list
28002805
args = remainder
28012806
# Find the root of the program
28022807
program = Program(getcwd(), True)
2803-
program.check_requirements(True)
2808+
program.check_requirements()
28042809
# Check if current Mbed OS support icetea
28052810
icetea_supported = program.requirements_contains('icetea')
28062811

@@ -3039,7 +3044,7 @@ def export(ide=None, target=None, source=False, profile=["debug"], clean=False,
30393044
# Find the root of the program
30403045
program = Program(getcwd(), True)
30413046
if not no_requirements:
3042-
program.check_requirements(True)
3047+
program.check_requirements()
30433048
# Remember the original path. this is needed for compiling only the libraries and tests for the current folder.
30443049
orig_path = getcwd()
30453050
orig_target = target
@@ -3093,7 +3098,7 @@ def detect():
30933098
args = remainder
30943099
# Find the root of the program
30953100
program = Program(getcwd(), False)
3096-
program.check_requirements(True)
3101+
program.check_requirements()
30973102
# Change directories to the program root to use mbed OS tools
30983103
with cd(program.path):
30993104
tools_dir = program.get_tools_dir()

0 commit comments

Comments
 (0)