From a5ea0fa9aac9d3d81b39c86a8a8d51ac6980ee6b Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Tue, 29 Sep 2020 13:25:37 +0200 Subject: [PATCH] Use utils.pip for executor installs --- poetry/installation/executor.py | 21 ++++++--------------- poetry/utils/pip.py | 11 ++++++++--- tests/installation/test_executor.py | 2 +- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/poetry/installation/executor.py b/poetry/installation/executor.py index aabf7d9d6f4..abb34b49356 100644 --- a/poetry/installation/executor.py +++ b/poetry/installation/executor.py @@ -22,6 +22,7 @@ from poetry.utils.helpers import safe_rmtree from poetry.utils.pip import pip_editable_install +from ..utils.pip import pip_install from .authenticator import Authenticator from .chef import Chef from .chooser import Chooser @@ -419,12 +420,9 @@ def _install(self, operation): message=operation_message, ) self._write(operation, message) - - args = ["install", "--no-deps", str(archive)] - if operation.job_type == "update": - args.insert(2, "-U") - - return self.run_pip(*args) + return pip_install( + str(archive), self._env, upgrade=operation.job_type == "update" + ) def _update(self, operation): return self._install(operation) @@ -479,8 +477,6 @@ def _install_directory(self, operation): else: req = os.path.realpath(package.source_url) - args = ["install", "--no-deps", "-U"] - pyproject = TomlFile(os.path.join(req, "pyproject.toml")) has_poetry = False @@ -525,17 +521,12 @@ def _install_directory(self, operation): with builder.setup_py(): if package.develop: return pip_editable_install(req, self._env) - - args.append(req) - - return self.run_pip(*args) + return pip_install(req, self._env, upgrade=True) if package.develop: return pip_editable_install(req, self._env) - args.append(req) - - return self.run_pip(*args) + return pip_install(req, self._env, upgrade=True) def _install_git(self, operation): from poetry.core.vcs import Git diff --git a/poetry/utils/pip.py b/poetry/utils/pip.py index 97e7dc6d0d7..62febadb6a8 100644 --- a/poetry/utils/pip.py +++ b/poetry/utils/pip.py @@ -1,3 +1,5 @@ +from typing import Union + from poetry.exceptions import PoetryException from poetry.utils._compat import Path from poetry.utils.env import Env @@ -6,10 +8,10 @@ def pip_install( path, environment, editable=False, deps=False, upgrade=False -): # type: (Path, Env, bool, bool, bool) -> None +): # type: (Union[Path, str], Env, bool, bool, bool) -> None path = Path(path) if isinstance(path, str) else path - args = ["pip", "install", "--prefix", str(environment.path)] + args = ["install", "--prefix", str(environment.path)] if upgrade: args.append("--upgrade") @@ -26,10 +28,13 @@ def pip_install( args.append(str(path)) + if path.is_file() and path.suffix == ".whl": + return environment.run_pip(*args) + with ephemeral_environment( executable=environment.python, pip=True, setuptools=True ) as env: - return env.run(*args) + return env.run("pip", *args) def pip_editable_install(directory, environment): # type: (Path, Env) -> None diff --git a/tests/installation/test_executor.py b/tests/installation/test_executor.py index 3064a0451fb..6c887e7aa9d 100644 --- a/tests/installation/test_executor.py +++ b/tests/installation/test_executor.py @@ -60,7 +60,7 @@ def test_execute_executes_a_batch_of_operations( mocker, config, pool, io, tmp_dir, mock_file_downloads ): pip_editable_install = mocker.patch( - "poetry.installation.executor.pip_editable_install" + "poetry.installation.executor.pip_editable_install", unsafe=not PY36 ) config = Config()