1
1
import logging
2
- from typing import Set , Tuple
2
+ from typing import Iterable , Set , Tuple
3
3
4
4
from pip ._internal .build_env import BuildEnvironment
5
5
from pip ._internal .distributions .base import AbstractDistribution
@@ -37,23 +37,17 @@ def prepare_distribution_metadata(
37
37
self .req .prepare_metadata ()
38
38
39
39
def _setup_isolation (self , finder : PackageFinder ) -> None :
40
- def _raise_conflicts (
41
- conflicting_with : str , conflicting_reqs : Set [Tuple [str , str ]]
42
- ) -> None :
43
- format_string = (
44
- "Some build dependencies for {requirement} "
45
- "conflict with {conflicting_with}: {description}."
46
- )
47
- error_message = format_string .format (
48
- requirement = self .req ,
49
- conflicting_with = conflicting_with ,
50
- description = ", " .join (
51
- f"{ installed } is incompatible with { wanted } "
52
- for installed , wanted in sorted (conflicting )
53
- ),
54
- )
55
- raise InstallationError (error_message )
40
+ self ._prepare_build_backend (finder )
41
+ # Install any extra build dependencies that the backend requests.
42
+ # This must be done in a second pass, as the pyproject.toml
43
+ # dependencies must be installed before we can call the backend.
44
+ if self .req .editable and self .req .permit_editable_wheels :
45
+ build_reqs = self ._get_build_requires_editable ()
46
+ else :
47
+ build_reqs = self ._get_build_requires_wheel ()
48
+ self ._install_build_reqs (finder , build_reqs )
56
49
50
+ def _prepare_build_backend (self , finder : PackageFinder ) -> None :
57
51
# Isolate in a BuildEnvironment and install the build-time
58
52
# requirements.
59
53
pyproject_requires = self .req .pyproject_requires
@@ -67,7 +61,7 @@ def _raise_conflicts(
67
61
self .req .requirements_to_check
68
62
)
69
63
if conflicting :
70
- _raise_conflicts ("PEP 517/518 supported requirements" , conflicting )
64
+ self . _raise_conflicts ("PEP 517/518 supported requirements" , conflicting )
71
65
if missing :
72
66
logger .warning (
73
67
"Missing build requirements in pyproject.toml for %s." ,
@@ -78,19 +72,46 @@ def _raise_conflicts(
78
72
"pip cannot fall back to setuptools without %s." ,
79
73
" and " .join (map (repr , sorted (missing ))),
80
74
)
81
- # Install any extra build dependencies that the backend requests.
82
- # This must be done in a second pass, as the pyproject.toml
83
- # dependencies must be installed before we can call the backend.
75
+
76
+ def _get_build_requires_wheel (self ) -> Iterable [str ]:
84
77
with self .req .build_env :
85
78
runner = runner_with_spinner_message ("Getting requirements to build wheel" )
86
79
backend = self .req .pep517_backend
87
80
assert backend is not None
88
81
with backend .subprocess_runner (runner ):
89
- reqs = backend .get_requires_for_build_wheel ()
82
+ return backend .get_requires_for_build_wheel ()
90
83
84
+ def _get_build_requires_editable (self ) -> Iterable [str ]:
85
+ with self .req .build_env :
86
+ runner = runner_with_spinner_message (
87
+ "Getting requirements to build editable"
88
+ )
89
+ backend = self .req .pep517_backend
90
+ assert backend is not None
91
+ with backend .subprocess_runner (runner ):
92
+ return backend .get_requires_for_build_editable ()
93
+
94
+ def _install_build_reqs (self , finder : PackageFinder , reqs : Iterable [str ]) -> None :
91
95
conflicting , missing = self .req .build_env .check_requirements (reqs )
92
96
if conflicting :
93
- _raise_conflicts ("the backend dependencies" , conflicting )
97
+ self . _raise_conflicts ("the backend dependencies" , conflicting )
94
98
self .req .build_env .install_requirements (
95
99
finder , missing , "normal" , "Installing backend dependencies"
96
100
)
101
+
102
+ def _raise_conflicts (
103
+ self , conflicting_with : str , conflicting_reqs : Set [Tuple [str , str ]]
104
+ ) -> None :
105
+ format_string = (
106
+ "Some build dependencies for {requirement} "
107
+ "conflict with {conflicting_with}: {description}."
108
+ )
109
+ error_message = format_string .format (
110
+ requirement = self .req ,
111
+ conflicting_with = conflicting_with ,
112
+ description = ", " .join (
113
+ f"{ installed } is incompatible with { wanted } "
114
+ for installed , wanted in sorted (conflicting_reqs )
115
+ ),
116
+ )
117
+ raise InstallationError (error_message )
0 commit comments