Commit 4e5c1640 authored by Jason R. Coombs's avatar Jason R. Coombs

Move customized behavior for fetch_build_eggs into a specialized subclass of Distribution.

parent 84a97be0
......@@ -30,14 +30,6 @@ __import__('pkg_resources.extern.packaging.specifiers')
__import__('pkg_resources.extern.packaging.version')
_skip_install_eggs = False
class SetupRequirementsError(BaseException):
def __init__(self, specifiers):
self.specifiers = specifiers
def _get_unpatched(cls):
warnings.warn("Do not call this function", DeprecationWarning)
return get_unpatched(cls)
......@@ -340,8 +332,6 @@ class Distribution(Distribution_parse_config_files, _Distribution):
self.dependency_links = attrs.pop('dependency_links', [])
assert_string_list(self, 'dependency_links', self.dependency_links)
if attrs and 'setup_requires' in attrs:
if _skip_install_eggs:
raise SetupRequirementsError(attrs['setup_requires'])
self.fetch_build_eggs(attrs['setup_requires'])
for ep in pkg_resources.iter_entry_points('distutils.setup_keywords'):
vars(self).setdefault(ep.name, None)
......
......@@ -30,9 +30,35 @@ import os
import sys
import tokenize
import shutil
import contextlib
from setuptools import dist
from setuptools.dist import SetupRequirementsError
import setuptools
import distutils
class SetupRequirementsError(BaseException):
def __init__(self, specifiers):
self.specifiers = specifiers
class Distribution(setuptools.dist.Distribution):
def fetch_build_eggs(self, specifiers):
raise SetupRequirementsError(specifiers)
@classmethod
@contextlib.contextmanager
def patch(cls):
"""
Replace
distutils.dist.Distribution with this class
for the duration of this context.
"""
orig = distutils.core.Distribution
distutils.core.Distribution = cls
try:
yield
finally:
distutils.core.Distribution = orig
def _run_setup(setup_script='setup.py'):
......@@ -54,17 +80,15 @@ def _fix_config(config_settings):
def _get_build_requires(config_settings):
config_settings = _fix_config(config_settings)
requirements = ['setuptools', 'wheel']
dist._skip_install_eggs = True
sys.argv = sys.argv[:1] + ['egg_info'] + \
config_settings["--global-option"]
try:
_run_setup()
with Distribution.patch():
_run_setup()
except SetupRequirementsError as e:
requirements += e.specifiers
dist._skip_install_eggs = False
return requirements
......
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