Skip to content
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

Validate CONAN_CPU_COUNT and output user friendly error message #4372

Merged
merged 1 commit into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions conans/client/tools/oss.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def cpu_count(output=None):
output = default_output(output, 'conans.client.tools.oss.cpu_count')
try:
env_cpu_count = os.getenv("CONAN_CPU_COUNT", None)
if env_cpu_count is not None and not env_cpu_count.isdigit():
raise ConanException("Invalid CONAN_CPU_COUNT value '%s', "
"please specify a positive integer" % env_cpu_count)
return int(env_cpu_count) if env_cpu_count else multiprocessing.cpu_count()
except NotImplementedError:
output.warn("multiprocessing.cpu_count() not implemented. Defaulting to 1 cpu")
Expand Down
3 changes: 3 additions & 0 deletions conans/test/unittests/util/tools_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,9 @@ def cpu_count_test(self):
self.assertGreaterEqual(cpus, 1)
with tools.environment_append({"CONAN_CPU_COUNT": "34"}):
self.assertEquals(tools.cpu_count(output=output), 34)
with tools.environment_append({"CONAN_CPU_COUNT": "null"}):
with self.assertRaisesRegexp(ConanException, "Invalid CONAN_CPU_COUNT value"):
tools.cpu_count(output=output)

def get_env_unit_test(self):
"""
Expand Down