Skip to content

Commit c08d4cc

Browse files
committed
Add --no-build-isolation for disabling build isolation
1 parent 34cc364 commit c08d4cc

File tree

7 files changed

+46
-10
lines changed

7 files changed

+46
-10
lines changed

src/pip/_internal/cmdoptions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,17 @@ def only_binary():
451451
help='Ignore the Requires-Python information.'
452452
) # type: Any
453453

454+
no_build_isolation = partial(
455+
Option,
456+
'--no-build-isolation',
457+
dest='build_isolation',
458+
action='store_false',
459+
default=True,
460+
help='Disable isolation when building a modern source distribution. '
461+
'Build dependencies specified by PEP 518 must be already installed '
462+
'if this option is used.'
463+
) # type: Any
464+
454465
install_options = partial(
455466
Option,
456467
'--install-option',

src/pip/_internal/commands/download.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def __init__(self, *args, **kw):
5757
cmd_opts.add_option(cmdoptions.no_clean())
5858
cmd_opts.add_option(cmdoptions.require_hashes())
5959
cmd_opts.add_option(cmdoptions.progress_bar())
60+
cmd_opts.add_option(cmdoptions.no_build_isolation())
6061

6162
cmd_opts.add_option(
6263
'-d', '--dest', '--destination-dir', '--destination-directory',
@@ -201,6 +202,7 @@ def run(self, options, args):
201202
download_dir=options.download_dir,
202203
wheel_download_dir=None,
203204
progress_bar=options.progress_bar,
205+
build_isolation=options.build_isolation,
204206
)
205207

206208
resolver = Resolver(

src/pip/_internal/commands/install.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def __init__(self, *args, **kw):
139139
help='Ignore the installed packages (reinstalling instead).')
140140

141141
cmd_opts.add_option(cmdoptions.ignore_requires_python())
142+
cmd_opts.add_option(cmdoptions.no_build_isolation())
142143

143144
cmd_opts.add_option(cmdoptions.install_options())
144145
cmd_opts.add_option(cmdoptions.global_options())
@@ -260,6 +261,7 @@ def run(self, options, args):
260261
download_dir=None,
261262
wheel_download_dir=None,
262263
progress_bar=options.progress_bar,
264+
build_isolation=options.build_isolation,
263265
)
264266

265267
resolver = Resolver(

src/pip/_internal/commands/wheel.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def __init__(self, *args, **kw):
6363
dest='build_options',
6464
metavar='options',
6565
action='append',
66-
help="Extra arguments to be supplied to 'setup.py bdist_wheel'.")
66+
help="Extra arguments to be supplied to 'setup.py bdist_wheel'.",
67+
)
68+
cmd_opts.add_option(cmdoptions.no_build_isolation())
6769
cmd_opts.add_option(cmdoptions.constraints())
6870
cmd_opts.add_option(cmdoptions.editable())
6971
cmd_opts.add_option(cmdoptions.requirements())
@@ -158,6 +160,7 @@ def run(self, options, args):
158160
download_dir=None,
159161
wheel_download_dir=options.wheel_dir,
160162
progress_bar=options.progress_bar,
163+
build_isolation=options.build_isolation,
161164
)
162165

163166
resolver = Resolver(

src/pip/_internal/operations/prepare.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def dist(self, finder):
104104
return list(pkg_resources.find_distributions(
105105
self.req.source_dir))[0]
106106

107-
def prep_for_dist(self, finder):
107+
def prep_for_dist(self, finder, build_isolation):
108108
# FIXME:https://github.com/pypa/pip/issues/1112
109109
pass
110110

@@ -120,23 +120,23 @@ def dist(self, finder):
120120
)
121121
return dist
122122

123-
def prep_for_dist(self, finder):
123+
def prep_for_dist(self, finder, build_isolation):
124124
# Before calling "setup.py egg_info", we need to set-up the build
125125
# environment.
126-
127126
build_requirements, isolate = self.req.get_pep_518_info()
127+
should_isolate = build_isolation and isolate
128128

129129
if 'setuptools' not in build_requirements:
130130
logger.warning(
131131
"This version of pip does not implement PEP 516, so "
132132
"it cannot build a wheel without setuptools. You may need to "
133133
"upgrade to a newer version of pip.")
134134

135-
if not isolate:
135+
if not should_isolate:
136136
self.req.build_env = NoOpBuildEnvironment(no_clean=False)
137137

138138
with self.req.build_env as prefix:
139-
if isolate:
139+
if should_isolate:
140140
_install_build_reqs(finder, prefix, build_requirements)
141141

142142
self.req.run_egg_info()
@@ -157,7 +157,7 @@ class RequirementPreparer(object):
157157
"""
158158

159159
def __init__(self, build_dir, download_dir, src_dir, wheel_download_dir,
160-
progress_bar):
160+
progress_bar, build_isolation):
161161
super(RequirementPreparer, self).__init__()
162162

163163
self.src_dir = src_dir
@@ -181,6 +181,9 @@ def __init__(self, build_dir, download_dir, src_dir, wheel_download_dir,
181181

182182
self.progress_bar = progress_bar
183183

184+
# Is build isolation allowed?
185+
self.build_isolation = build_isolation
186+
184187
@property
185188
def _download_should_save(self):
186189
# TODO: Modify to reduce indentation needed
@@ -306,7 +309,7 @@ def prepare_linked_requirement(self, req, session, finder,
306309
(req, exc, req.link)
307310
)
308311
abstract_dist = make_abstract_dist(req)
309-
abstract_dist.prep_for_dist(finder)
312+
abstract_dist.prep_for_dist(finder, self.build_isolation)
310313
if self._download_should_save:
311314
# Make a .zip of the source_dir we already created.
312315
if req.link.scheme in vcs.all_schemes:
@@ -331,7 +334,7 @@ def prepare_editable_requirement(self, req, require_hashes, finder):
331334
req.update_editable(not self._download_should_save)
332335

333336
abstract_dist = make_abstract_dist(req)
334-
abstract_dist.prep_for_dist(finder)
337+
abstract_dist.prep_for_dist(finder, self.build_isolation)
335338

336339
if self._download_should_save:
337340
req.archive(self.download_dir)

tests/functional/test_wheel.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,17 @@ def test_pip_wheel_with_pep518_build_reqs(script, data):
222222
assert wheel_file_path in result.files_created, result.stdout
223223
assert "Successfully built pep518" in result.stdout, result.stdout
224224
assert "Installing build dependencies" in result.stdout, result.stdout
225+
226+
227+
@pytest.mark.network
228+
def test_pip_wheel_with_pep518_build_reqs_no_isolation(script, data):
229+
script.pip('install', 'wheel')
230+
result = script.pip(
231+
'wheel', '--no-index', '-f', data.find_links, '--no-build-isolation',
232+
'pep518==3.0',
233+
)
234+
wheel_file_name = 'pep518-3.0-py%s-none-any.whl' % pyversion[0]
235+
wheel_file_path = script.scratch / wheel_file_name
236+
assert wheel_file_path in result.files_created, result.stdout
237+
assert "Successfully built pep518" in result.stdout, result.stdout
238+
assert "Installing build dependencies" not in result.stdout, result.stdout

tests/unit/test_req.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def _basic_resolver(self, finder):
3939
src_dir=os.path.join(self.tempdir, 'src'),
4040
download_dir=None,
4141
wheel_download_dir=None,
42-
progress_bar="on"
42+
progress_bar="on",
43+
build_isolation=True,
4344
)
4445
return Resolver(
4546
preparer=preparer, wheel_cache=None,

0 commit comments

Comments
 (0)