forked from python-poetry/poetry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pip.py
57 lines (43 loc) · 1.41 KB
/
pip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from __future__ import annotations
from typing import TYPE_CHECKING
from poetry.exceptions import PoetryException
from poetry.utils.env import EnvCommandError
if TYPE_CHECKING:
from pathlib import Path
from poetry.utils.env import Env
def pip_install(
path: Path,
environment: Env,
editable: bool = False,
deps: bool = False,
upgrade: bool = False,
) -> int | str:
is_wheel = path.suffix == ".whl"
# We disable version check here as we are already pinning to version available in
# either the virtual environment or the virtualenv package embedded wheel. Version
# checks are a wasteful network call that adds a lot of wait time when installing a
# lot of packages.
args = [
"install",
"--disable-pip-version-check",
"--isolated",
"--prefix",
str(environment.path),
]
if not is_wheel and not editable:
args.insert(1, "--use-pep517")
if upgrade:
args.append("--upgrade")
if not deps:
args.append("--no-deps")
if editable:
if not path.is_dir():
raise PoetryException(
"Cannot install non directory dependencies in editable mode"
)
args.append("-e")
args.append(str(path))
try:
return environment.run_pip(*args)
except EnvCommandError as e:
raise PoetryException(f"Failed to install {path.as_posix()}") from e