From efdbd11fa5c14df79ff896b74bd914e8713cf6fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Tue, 6 Sep 2022 19:43:09 +0200 Subject: [PATCH 1/2] refactor(env): remove duplicated implementations of get_pip_command() --- src/poetry/utils/env.py | 21 +-------------------- tests/utils/test_env.py | 2 +- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index afc1e7581a1..927d9501d35 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -1393,7 +1393,7 @@ def get_marker_env(self) -> dict[str, Any]: raise NotImplementedError() def get_pip_command(self, embedded: bool = False) -> list[str]: - raise NotImplementedError() + return [self.python, self.pip_embedded if embedded else self.pip] def get_supported_tags(self) -> list[Tag]: raise NotImplementedError() @@ -1556,11 +1556,6 @@ def get_version_info(self) -> tuple[Any, ...]: def get_python_implementation(self) -> str: return platform.python_implementation() - def get_pip_command(self, embedded: bool = False) -> list[str]: - # If we're not in a venv, assume the interpreter we're running on - # has a pip and use that - return [sys.executable, self.pip_embedded if embedded else self.pip] - def get_paths(self) -> dict[str, str]: # We can't use sysconfig.get_paths() because # on some distributions it does not return the proper paths @@ -1672,14 +1667,6 @@ def get_python_implementation(self) -> str: implementation: str = self.marker_env["platform_python_implementation"] return implementation - def get_pip_command(self, embedded: bool = False) -> list[str]: - # We're in a virtualenv that is known to be sane, - # so assume that we have a functional pip - return [ - self._bin(self._executable), - self.pip_embedded if embedded else self.pip, - ] - def get_supported_tags(self) -> list[Tag]: output = self.run_python_script(GET_SYS_TAGS) assert isinstance(output, str) @@ -1858,12 +1845,6 @@ def __init__( self._execute = execute self.executed: list[list[str]] = [] - def get_pip_command(self, embedded: bool = False) -> list[str]: - return [ - self._bin(self._executable), - self.pip_embedded if embedded else self.pip, - ] - def _run(self, cmd: list[str], **kwargs: Any) -> int | str: self.executed.append(cmd) diff --git a/tests/utils/test_env.py b/tests/utils/test_env.py index 32fb5cb0865..d645b29357a 100644 --- a/tests/utils/test_env.py +++ b/tests/utils/test_env.py @@ -1392,7 +1392,7 @@ def test_build_environment_called_build_script_specified( assert env == ephemeral_env assert env.executed == [ [ - "python", + sys.executable, env.pip_embedded, "install", "--disable-pip-version-check", From c91a6c886636d3e2a48b30d92d63703b7fe68be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Tue, 6 Sep 2022 19:47:25 +0200 Subject: [PATCH 2/2] env: prefer "python -m pip" to calling pip directly to allow pip updating itself on Windows --- src/poetry/utils/env.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 927d9501d35..5b8cf7f0a2c 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -1393,7 +1393,10 @@ def get_marker_env(self) -> dict[str, Any]: raise NotImplementedError() def get_pip_command(self, embedded: bool = False) -> list[str]: - return [self.python, self.pip_embedded if embedded else self.pip] + if embedded or not Path(self._bin(self._pip_executable)).exists(): + return [self.python, self.pip_embedded] + # run as module so that pip can update itself on Windows + return [self.python, "-m", "pip"] def get_supported_tags(self) -> list[Tag]: raise NotImplementedError()