Skip to content

Commit

Permalink
fix support for dependency_links/setup_requires in setup.cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit-pierre committed Jul 26, 2017
1 parent a9f7526 commit 0ff86ea
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
5 changes: 4 additions & 1 deletion setuptools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ def _looks_like_package(path):

find_packages = PackageFinder.find

setup = distutils.core.setup
def setup(**attrs):
if 'install_setup_requires' not in attrs:
attrs['install_setup_requires'] = True
distutils.core.setup(**attrs)

_Command = monkey.get_unpatched(distutils.core.Command)

Expand Down
21 changes: 19 additions & 2 deletions setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,16 @@ def __init__(self, attrs=None):
self.dist_files = []
self.src_root = attrs and attrs.pop("src_root", None)
self.patch_missing_pkg_info(attrs)
self.dependency_links = []
self.setup_requires = []
# Make sure we have any eggs needed to interpret 'attrs'
if attrs is not None:
self.dependency_links = attrs.pop('dependency_links', [])
assert_string_list(self, 'dependency_links', self.dependency_links)
if attrs and 'setup_requires' in attrs:
self.fetch_build_eggs(attrs['setup_requires'])
self.setup_requires = attrs.pop('setup_requires', [])
assert_string_list(self, 'setup_requires', self.setup_requires)
if attrs and attrs.pop('install_setup_requires', False):
self.install_setup_requires()
for ep in pkg_resources.iter_entry_points('distutils.setup_keywords'):
vars(self).setdefault(ep.name, None)
_Distribution.__init__(self, attrs)
Expand Down Expand Up @@ -416,6 +420,19 @@ def _clean_req(self, req):
req.marker = None
return req

def install_setup_requires(self):
# If dependency_links/setup_requires were not passed as
# arguments, then we need to honor setup.cfg's options.
if not self.dependency_links or not self.setup_requires:
dist = Distribution()
dist.parse_config_files()
if not self.setup_requires:
self.setup_requires = dist.setup_requires
if not self.dependency_links:
self.dependency_links = dist.dependency_links
if self.setup_requires:
self.fetch_build_eggs(self.setup_requires)

def parse_config_files(self, filenames=None):
"""Parses configuration files from various levels
and loads configuration.
Expand Down
34 changes: 28 additions & 6 deletions setuptools/tests/test_easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,15 @@ def create_sdist():
"""))])
yield dist_path

def test_setup_requires_overrides_version_conflict(self):
use_setup_cfg = (
(),
('dependency_links',),
('setup_requires',),
('dependency_links', 'setup_requires'),
)

@pytest.mark.parametrize('use_setup_cfg', use_setup_cfg)
def test_setup_requires_overrides_version_conflict(self, use_setup_cfg):
"""
Regression test for distribution issue 323:
https://bitbucket.org/tarek/distribute/issues/323
Expand All @@ -397,7 +405,7 @@ def test_setup_requires_overrides_version_conflict(self):

with contexts.save_pkg_resources_state():
with contexts.tempdir() as temp_dir:
test_pkg = create_setup_requires_package(temp_dir)
test_pkg = create_setup_requires_package(temp_dir, use_setup_cfg=use_setup_cfg)
test_setup_py = os.path.join(test_pkg, 'setup.py')
with contexts.quiet() as (stdout, stderr):
# Don't even need to install the package, just
Expand All @@ -408,7 +416,8 @@ def test_setup_requires_overrides_version_conflict(self):
assert len(lines) > 0
assert lines[-1].strip(), 'test_pkg'

def test_setup_requires_override_nspkg(self):
@pytest.mark.parametrize('use_setup_cfg', use_setup_cfg)
def test_setup_requires_override_nspkg(self, use_setup_cfg):
"""
Like ``test_setup_requires_overrides_version_conflict`` but where the
``setup_requires`` package is part of a namespace package that has
Expand Down Expand Up @@ -446,7 +455,8 @@ def test_setup_requires_override_nspkg(self):
""")

test_pkg = create_setup_requires_package(
temp_dir, 'foo.bar', '0.2', make_nspkg_sdist, template)
temp_dir, 'foo.bar', '0.2', make_nspkg_sdist, template,
use_setup_cfg=use_setup_cfg)

test_setup_py = os.path.join(test_pkg, 'setup.py')

Expand Down Expand Up @@ -532,7 +542,7 @@ def make_sdist(dist_path, files):

def create_setup_requires_package(path, distname='foobar', version='0.1',
make_package=make_trivial_sdist,
setup_py_template=None):
setup_py_template=None, use_setup_cfg={}):
"""Creates a source tree under path for a trivial test package that has a
single requirement in setup_requires--a tarball for that requirement is
also created and added to the dependency_links argument.
Expand All @@ -549,9 +559,21 @@ def create_setup_requires_package(path, distname='foobar', version='0.1',
}

test_pkg = os.path.join(path, 'test_pkg')
test_setup_py = os.path.join(test_pkg, 'setup.py')
os.mkdir(test_pkg)

if use_setup_cfg:
test_setup_cfg = os.path.join(test_pkg, 'setup.cfg')
test_setup_cfg_lines = ['[options]']
for name in use_setup_cfg:
value = test_setup_attrs.pop(name)
test_setup_cfg_lines.append('%s: %s' % (
name, ';'.join(value)
))
with open(test_setup_cfg, 'w') as f:
f.write('\n'.join(test_setup_cfg_lines))

test_setup_py = os.path.join(test_pkg, 'setup.py')

if setup_py_template is None:
setup_py_template = DALS("""\
import setuptools
Expand Down

0 comments on commit 0ff86ea

Please sign in to comment.