Skip to content

Commit

Permalink
Use utils.pip for executor installs
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Sep 29, 2020
1 parent 7401836 commit a5ea0fa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
21 changes: 6 additions & 15 deletions poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions poetry/utils/pip.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/installation/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit a5ea0fa

Please sign in to comment.