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

pip installer: fix installed script executable #3835

Merged
merged 3 commits into from
Mar 26, 2021
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 .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
matrix:
os: [Ubuntu, MacOS, Windows]
python-version: [3.6, 3.7, 3.8, 3.9]
fail-fast: false
steps:
- uses: actions/checkout@v2

Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 22 additions & 9 deletions poetry/utils/pip.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import os
import sys

from pathlib import Path
from typing import Union

from poetry.exceptions import PoetryException
from poetry.utils.env import Env
from poetry.utils.env import EnvCommandError
from poetry.utils.env import ephemeral_environment


Expand All @@ -14,9 +18,13 @@ def pip_install(
upgrade: bool = False,
) -> Union[int, str]:
path = Path(path) if isinstance(path, str) else path
is_wheel = path.suffix == ".whl"

args = ["install", "--prefix", str(environment.path)]

if not is_wheel:
args.insert(1, "--use-pep517")

if upgrade:
args.append("--upgrade")

Expand All @@ -32,16 +40,21 @@ def pip_install(

args.append(str(path))

if path.is_file() and path.suffix == ".whl":
try:
return environment.run_pip(*args)

with ephemeral_environment(
executable=environment.python, pip=True, setuptools=True
) as env:
return env.run(
"pip",
*args,
)
except EnvCommandError as e:
if sys.version_info < (3, 7) and not is_wheel:
# Under certain Python3.6 installs vendored pip wheel does not contain zip-safe
# pep517 lib. In this cases we create an isolated ephemeral virtual environment.
with ephemeral_environment(
executable=environment.python, pip=True, setuptools=True
) as env:
return environment.run(
env._bin("pip"),
*args,
env={**os.environ, "PYTHONPATH": str(env.purelib)},
)
raise PoetryException(f"Failed to install {path.as_posix()}") from e


def pip_editable_install(directory: Path, environment: Env) -> Union[int, str]:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ shellingham = "^1.1"
tomlkit = ">=0.7.0,<1.0.0"
pexpect = "^4.7.0"
packaging = "^20.4"
virtualenv = { version = "^20.0.26" }
virtualenv = "^20.4.3"
keyring = "^21.2.0"
importlib-metadata = {version = "^1.6.0", python = "<3.8"}

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 @@ -137,7 +137,7 @@ def test_execute_executes_a_batch_of_operations(
expected = set(expected.splitlines())
output = set(io.fetch_output().splitlines())
assert expected == output
assert 4 == len(env.executed)
assert 5 == len(env.executed)
assert 0 == return_code
pip_editable_install.assert_called_once()

Expand Down