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

Possibility to change the default CONAN_SYSREQUIRES_MODE for SystemPackageTool #6677

Merged
merged 7 commits into from
Mar 19, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion conans/client/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def env_vars(self):
"CONAN_SKIP_BROKEN_SYMLINKS_CHECK": self._env_c("general.skip_broken_symlinks_check", "CONAN_SKIP_BROKEN_SYMLINKS_CHECK", "False"),
"CONAN_CACHE_NO_LOCKS": self._env_c("general.cache_no_locks", "CONAN_CACHE_NO_LOCKS", "False"),
"CONAN_SYSREQUIRES_SUDO": self._env_c("general.sysrequires_sudo", "CONAN_SYSREQUIRES_SUDO", "False"),
"CONAN_SYSREQUIRES_MODE": self._env_c("general.sysrequires_mode", "CONAN_SYSREQUIRES_MODE", "enabled"),
"CONAN_SYSREQUIRES_MODE": self._env_c("general.sysrequires_mode", "CONAN_SYSREQUIRES_MODE", None),
"CONAN_REQUEST_TIMEOUT": self._env_c("general.request_timeout", "CONAN_REQUEST_TIMEOUT", None),
"CONAN_RETRY": self._env_c("general.retry", "CONAN_RETRY", None),
"CONAN_RETRY_WAIT": self._env_c("general.retry_wait", "CONAN_RETRY_WAIT", None),
Expand Down
23 changes: 12 additions & 11 deletions conans/client/tools/system_pm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

class SystemPackageTool(object):

def __init__(self, runner=None, os_info=None, tool=None, recommends=False, output=None, conanfile=None):
def __init__(self, runner=None, os_info=None, tool=None, recommends=False, output=None,
conanfile=None, default_mode="enabled"):
output = output if output else conanfile.output if conanfile else None
self._output = default_output(output, 'conans.client.tools.system_pm.SystemPackageTool')
os_info = os_info or OSInfo()
Expand All @@ -21,6 +22,7 @@ def __init__(self, runner=None, os_info=None, tool=None, recommends=False, outpu
self._tool._runner = runner or ConanRunner(output=self._output)
self._tool._recommends = recommends
self._conanfile = conanfile
self._default_mode = default_mode

@staticmethod
def _get_sudo_str():
Expand All @@ -43,16 +45,6 @@ def _is_sudo_enabled():
return False
return get_env("CONAN_SYSREQUIRES_SUDO", True)

@staticmethod
def _get_sysrequire_mode():
allowed_modes = ("enabled", "verify", "disabled")
mode = get_env("CONAN_SYSREQUIRES_MODE", "enabled")
mode_lower = mode.lower()
if mode_lower not in allowed_modes:
raise ConanException("CONAN_SYSREQUIRES_MODE=%s is not allowed, allowed modes=%r"
% (mode, allowed_modes))
return mode_lower

@staticmethod
def _create_tool(os_info, output):
if os_info.with_apt:
Expand All @@ -74,6 +66,15 @@ def _create_tool(os_info, output):
else:
return NullTool(output=output)

def _get_sysrequire_mode(self):
czoido marked this conversation as resolved.
Show resolved Hide resolved
allowed_modes = ("enabled", "verify", "disabled")
mode = get_env("CONAN_SYSREQUIRES_MODE", self._default_mode)
mode_lower = mode.lower()
if mode_lower not in allowed_modes:
raise ConanException("CONAN_SYSREQUIRES_MODE=%s is not allowed, allowed modes=%r"
% (mode, allowed_modes))
return mode_lower

def add_repository(self, repository, repo_key=None, update=True):
self._tool.add_repository(repository, repo_key=repo_key)
if update:
Expand Down
16 changes: 16 additions & 0 deletions conans/test/unittests/client/tools/system_pm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,22 @@ def __call__(self, command, *args, **kwargs): # @UnusedVariable
self.assertNotIn("CONAN_SYSREQUIRES_MODE", str(exc.exception))
self.assertEqual(7, runner.calls)

# Check default_mode. The environment variable is not set and should behave like
# the default_mode
with tools.environment_append({
"CONAN_SYSREQUIRES_MODE": None,
"CONAN_SYSREQUIRES_SUDO": "True"
}):
packages = ["verify_package", "verify_another_package", "verify_yet_another_package"]
runner = RunnerMultipleMock(["sudo -A apt-get update"])
spt = SystemPackageTool(runner=runner, tool=AptTool(output=self.out), output=self.out,
default_mode="verify")
with self.assertRaises(ConanException) as exc:
spt.install(packages)
self.assertIn("Aborted due to CONAN_SYSREQUIRES_MODE=", str(exc.exception))
self.assertIn('\n'.join(packages), self.out)
self.assertEqual(3, runner.calls)

def system_package_tool_installed_test(self):
if (platform.system() != "Linux" and platform.system() != "Macos" and
platform.system() != "Windows"):
Expand Down