8000 Accept custom pip command by uilianries · Pull Request #347 · conan-io/conan-package-tools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Accept custom pip command #347

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 6 commits into from
Mar 19, 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,7 @@ This is especially useful for CI integration.
- **CONAN_BASH_PATH**: Path to a bash executable. Used only in windows to help the tools.run_in_windows_bash() function to locate our Cygwin/MSYS2 bash.
Set it with the bash executable path if it’s not in the PATH or you want to use a different one.
- **CONAN_PIP_USE_SUDO** Use "sudo" when invoking pip, by default it will use sudo when not using Windows and not running docker image "conanio/". "False" to deactivate.
- **CONAN_PIP_COMMAND** Run custom `pip` command when updating Conan. e.g. "/usr/bin/pip2"
- **CONAN_DOCKER_USE_SUDO** Use "sudo" when invoking docker, by default it will use sudo when not using Windows. "False" to deactivate.
- **CONAN_ALLOW_GCC_MINORS** Declare this variable if you want to allow gcc >=5 versions with the minor (5.1, 6.3 etc).
- **CONAN_EXCLUDE_VCVARS_PRECOMMAND** For Visual Studio builds, it exclude the vcvars call to set the environment.
Expand Down
12 changes: 9 additions & 3 deletions cpt/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ def __init__(self, username=None, channel=None, runner=None,
self.sudo_pip_command = "sudo -E" if get_bool_from_env("CONAN_PIP_USE_SUDO") else ""
elif platform.system() != "Windows" and self._docker_image and 'conanio/' not in str(self._docker_image):
self.sudo_pip_command = "sudo -E"
self.pip_command = os.getenv("CONAN_PIP_COMMAND", "pip")
pip_found = True if tools.os_info.is_windows else tools.which(self.pip_command)
if not pip_found or not "pip" in self.pip_command:
raise Exception("CONAN_PIP_COMMAND: '{}' is not a valid pip command.".format(self.pip_command))

self.docker_shell = ""

Expand Down Expand Up @@ -439,12 +443,14 @@ def run(self, base_profile_name=None):
self.auth_manager.login(self.remotes_manager.upload_remote_name)
if self.conan_pip_package and not self.use_docker:
with self.printer.foldable_output("pip_update"):
self.runner('%s pip install %s' % (self.sudo_pip_command,
self.conan_pip_package))
self.runner('%s %s install -q %s' % (self.sudo_pip_command,
self.pip_command,
self.conan_pip_package))
if self.pip_install:
packages = " ".join(self.pip_install)
self.printer.print_message("Install extra python packages: {}".format(packages))
self.runner('%s pip install %s' % (self.sudo_pip_command, packages))
self.runner('%s %s install -q %s' % (self.sudo_pip_command,
self.pip_command, packages))

self.run_builds(base_profile_name=base_profile_name)

Expand Down
67 changes: 67 additions & 0 deletions cpt/test/unit/packager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from cpt.builds_generator import BuildConf
from cpt.packager import ConanMultiPackager
from conans import tools
from conans.test.utils.tools import TestBufferConanOutput
from conans.model.ref import ConanFileReference
from cpt.test.unit.utils import MockConanAPI, MockRunner, MockCIManager

Expand Down Expand Up @@ -817,3 +818,69 @@ def test_pip_docker_sudo(self):
self._add_build(1, "gcc", "4.3")
self.packager.run_builds(1, 2)
self.assertIn("sudo -E pip", self.runner.calls[1])

def test_regular_pip_command(self):
""" CPT Should call `pip` when CONAN_PIP_PACKAGE or CONAN_PIP_INSTALL are declared.
"""
with tools.environment_append({"CONAN_USERNAME": "foobar",
"CONAN_PIP_PACKAGE": "conan==1.0.0-dev",
"CONAN_PIP_INSTALL": "foobar==0.1.0"}):
output = TestBufferConanOutput()
self.packager = ConanMultiPackager(username="lasote",
channel="mychannel",
reference="lib/1.0",
ci_manager=self.ci_manager,
out=output.write,
conan_api=self.conan_api,
runner=self.runner,
exclude_vcvars_precommand=True)
self.packager.add_common_builds()
self.packager.run()
self.assertIn("[pip_update]", output)
self.assertIn(" pip install -q conan==1.0.0-dev", self.runner.calls)
self.assertIn(" pip install -q foobar==0.1.0", self.runner.calls)

def test_custom_pip_command(self):
""" CPT should run custom `pip` path when CONAN_PIP_COMMAND is declared.
"""
pip = "pip3" if tools.which("pip3") else "pip2"
with tools.environment_append({"CONAN_USERNAME": "foobar",
"CONAN_PIP_PACKAGE": "conan==0.1.0",
"CONAN_PIP_INSTALL": "foobar==0.1.0",
"CONAN_PIP_COMMAND": pip}):
output = TestBufferConanOutput()
self.packager = ConanMultiPackager(username="lasote",
channel="mychannel",
reference="lib/1.0",
ci_manager=self.ci_manager,
out=output.write,
conan_api=self.conan_api,
runner=self.runner,
exclude_vcvars_precommand=True)
self.packager.add_common_builds()
self.packager.run()
self.assertIn("[pip_update]", output)
self.assertIn(" {} install -q conan==0.1.0".format(pip), self.runner.calls)
self.assertIn(" {} install -q foobar==0.1.0".format(pip), self.runner.calls)

def test_invalid_pip_command(self):
""" CPT should not accept invalid `pip` command when CONAN_PIP_COMMAND is declared.
"""
with tools.environment_append({"CONAN_USERNAME": "foobar",
"CONAN_PIP_PACKAGE": "conan==0.1.0",
"CONAN_PIP_COMMAND": "/bin/bash"}):
output = TestBufferConanOutput()
with self.assertRaises(Exception) as context:
self.packager = ConanMultiPackager(username="lasote",
channel="mychannel",
reference="lib/1.0",
ci_manager=self.ci_manager,
out=output.write,
conan_api=self.conan_api,
runner=self.runner,
exclude_vcvars_precommand=True)
self.packager.add_common_builds()
self.packager.run()

self.assertTrue("CONAN_PIP_COMMAND: '/bin/bash' is not a valid pip command" in context.exception)
self.assertNotIn("[pip_update]", output)
0