Skip to content

Commit 6f46a4b

Browse files
committed
fix support for easy_install's find-links option in setup.cfg
1 parent e84f616 commit 6f46a4b

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

changelog.d/1921.change.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix support for easy_install's ``find-links`` option in ``setup.cfg``.

setuptools/installer.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@
77

88
import pkg_resources
99
from setuptools.command.easy_install import easy_install
10+
from setuptools.extern import six
1011
from setuptools.wheel import Wheel
1112

1213
from .py31compat import TemporaryDirectory
1314

1415

16+
def _fixup_find_links(find_links):
17+
"""Ensure find-links option end-up being a list of strings."""
18+
if isinstance(find_links, six.string_types):
19+
return find_links.split()
20+
assert isinstance(find_links, (tuple, list))
21+
return find_links
22+
23+
1524
def _legacy_fetch_build_egg(dist, req):
1625
"""Fetch an egg needed for building.
1726
@@ -31,7 +40,7 @@ def _legacy_fetch_build_egg(dist, req):
3140
if dist.dependency_links:
3241
links = dist.dependency_links[:]
3342
if 'find_links' in opts:
34-
links = opts['find_links'][1] + links
43+
links = _fixup_find_links(opts['find_links'][1]) + links
3544
opts['find_links'] = ('setup', links)
3645
install_dir = dist.get_egg_cache_dir()
3746
cmd = easy_install(
@@ -84,7 +93,7 @@ def fetch_build_egg(dist, req):
8493
else:
8594
index_url = None
8695
if 'find_links' in opts:
87-
find_links = opts['find_links'][1][:]
96+
find_links = _fixup_find_links(opts['find_links'][1])[:]
8897
else:
8998
find_links = []
9099
if dist.dependency_links:

setuptools/tests/test_easy_install.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,44 @@ def test_setup_requires_with_python_requires(self, monkeypatch, tmpdir):
744744
eggs = list(map(str, pkg_resources.find_distributions(os.path.join(test_pkg, '.eggs'))))
745745
assert eggs == ['dep 1.0']
746746

747+
@pytest.mark.parametrize('use_legacy_installer,with_dependency_links_in_setup_py',
748+
itertools.product((False, True), (False, True)))
749+
def test_setup_requires_with_find_links_in_setup_cfg(self, monkeypatch,
750+
use_legacy_installer,
751+
with_dependency_links_in_setup_py):
752+
monkeypatch.setenv(str('PIP_RETRIES'), str('0'))
753+
monkeypatch.setenv(str('PIP_TIMEOUT'), str('0'))
754+
with contexts.save_pkg_resources_state():
755+
with contexts.tempdir() as temp_dir:
756+
make_trivial_sdist(os.path.join(temp_dir, 'python-xlib-42.tar.gz'), 'python-xlib', '42')
757+
test_pkg = os.path.join(temp_dir, 'test_pkg')
758+
test_setup_py = os.path.join(test_pkg, 'setup.py')
759+
test_setup_cfg = os.path.join(test_pkg, 'setup.cfg')
760+
os.mkdir(test_pkg)
761+
with open(test_setup_py, 'w') as fp:
762+
if with_dependency_links_in_setup_py:
763+
dependency_links = [os.path.join(temp_dir, 'links')]
764+
else:
765+
dependency_links = []
766+
fp.write(DALS(
767+
'''
768+
from setuptools import installer, setup
769+
if {use_legacy_installer}:
770+
installer.fetch_build_egg = installer._legacy_fetch_build_egg
771+
setup(setup_requires='python-xlib==42',
772+
dependency_links={dependency_links!r})
773+
''').format(use_legacy_installer=use_legacy_installer,
774+
dependency_links=dependency_links))
775+
with open(test_setup_cfg, 'w') as fp:
776+
fp.write(DALS(
777+
'''
778+
[easy_install]
779+
index_url = {index_url}
780+
find_links = {find_links}
781+
''').format(index_url=os.path.join(temp_dir, 'index'),
782+
find_links=temp_dir))
783+
run_setup(test_setup_py, [str('--version')])
784+
747785

748786
def make_trivial_sdist(dist_path, distname, version):
749787
"""

0 commit comments

Comments
 (0)