Commit 6f7c2625 authored by Jason R. Coombs's avatar Jason R. Coombs Committed by GitHub

Merge pull request #2306 from takluyver/pep517-setup-requires

Don't install setup_requires when run as a PEP-517 backend.
parents a42d3008 d2883ac4
When running as a PEP 517 backend, setuptools does not try to install
``setup_requires`` itself. They are reported as build requirements for the
frontend to install.
...@@ -75,6 +75,22 @@ class Distribution(setuptools.dist.Distribution): ...@@ -75,6 +75,22 @@ class Distribution(setuptools.dist.Distribution):
distutils.core.Distribution = orig distutils.core.Distribution = orig
@contextlib.contextmanager
def no_install_setup_requires():
"""Temporarily disable installing setup_requires
Under PEP 517, the backend reports build dependencies to the frontend,
and the frontend is responsible for ensuring they're installed.
So setuptools (acting as a backend) should not try to install them.
"""
orig = setuptools._install_setup_requires
setuptools._install_setup_requires = lambda attrs: None
try:
yield
finally:
setuptools._install_setup_requires = orig
def _to_str(s): def _to_str(s):
""" """
Convert a filename to a string (on Python 2, explicitly Convert a filename to a string (on Python 2, explicitly
...@@ -154,7 +170,8 @@ class _BuildMetaBackend(object): ...@@ -154,7 +170,8 @@ class _BuildMetaBackend(object):
config_settings=None): config_settings=None):
sys.argv = sys.argv[:1] + ['dist_info', '--egg-base', sys.argv = sys.argv[:1] + ['dist_info', '--egg-base',
_to_str(metadata_directory)] _to_str(metadata_directory)]
self.run_setup() with no_install_setup_requires():
self.run_setup()
dist_info_directory = metadata_directory dist_info_directory = metadata_directory
while True: while True:
...@@ -194,7 +211,8 @@ class _BuildMetaBackend(object): ...@@ -194,7 +211,8 @@ class _BuildMetaBackend(object):
sys.argv = (sys.argv[:1] + setup_command + sys.argv = (sys.argv[:1] + setup_command +
['--dist-dir', tmp_dist_dir] + ['--dist-dir', tmp_dist_dir] +
config_settings["--global-option"]) config_settings["--global-option"])
self.run_setup() with no_install_setup_requires():
self.run_setup()
result_basename = _file_with_extension( result_basename = _file_with_extension(
tmp_dist_dir, result_extension) tmp_dist_dir, result_extension)
......
...@@ -380,7 +380,7 @@ class TestBuildMetaBackend: ...@@ -380,7 +380,7 @@ class TestBuildMetaBackend:
setup( setup(
name="qux", name="qux",
version="0.0.0", version="0.0.0",
py_modules=["hello.py"], py_modules=["hello"],
setup_requires={setup_literal}, setup_requires={setup_literal},
) )
""").format(setup_literal=setup_literal), """).format(setup_literal=setup_literal),
...@@ -407,6 +407,35 @@ class TestBuildMetaBackend: ...@@ -407,6 +407,35 @@ class TestBuildMetaBackend:
assert expected == sorted(actual) assert expected == sorted(actual)
def test_dont_install_setup_requires(self, tmpdir_cwd):
files = {
'setup.py': DALS("""
from setuptools import setup
setup(
name="qux",
version="0.0.0",
py_modules=["hello"],
setup_requires=["does-not-exist >99"],
)
"""),
'hello.py': DALS("""
def run():
print('hello')
"""),
}
build_files(files)
build_backend = self.get_build_backend()
dist_dir = os.path.abspath('pip-dist-info')
os.makedirs(dist_dir)
# does-not-exist can't be satisfied, so if it attempts to install
# setup_requires, it will fail.
build_backend.prepare_metadata_for_build_wheel(dist_dir)
_sys_argv_0_passthrough = { _sys_argv_0_passthrough = {
'setup.py': DALS(""" 'setup.py': DALS("""
import os import os
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment