Skip to content

Commit 4c9bea1

Browse files
committed
fix possible issue with transitive build dependencies
Handle the case where a missing transitive build dependency is required by an extra for an already installed build dependency.
1 parent e84f616 commit 4c9bea1

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

changelog.d/1922.change.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix possible issue with transitive build dependencies.

setuptools/installer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ def fetch_build_egg(dist, req):
6666
dist.announce('WARNING: The wheel package is not available.', log.WARN)
6767
if not isinstance(req, pkg_resources.Requirement):
6868
req = pkg_resources.Requirement.parse(req)
69+
# Ignore environment markers: if we're here, it's needed. This ensure
70+
# we don't try to ask pip for something like `babel; extra == "i18n"`,
71+
# which would always be ignored.
72+
req.marker = None
6973
# Take easy_install options into account, but do not override relevant
7074
# pip environment variables (like PIP_INDEX_URL or PIP_QUIET); they'll
7175
# take precedence.

setuptools/tests/test_easy_install.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import pkg_resources
3838

3939
from . import contexts
40+
from .files import build_files
4041
from .textwrap import DALS
4142

4243
__metaclass__ = type
@@ -744,6 +745,54 @@ def test_setup_requires_with_python_requires(self, monkeypatch, tmpdir):
744745
eggs = list(map(str, pkg_resources.find_distributions(os.path.join(test_pkg, '.eggs'))))
745746
assert eggs == ['dep 1.0']
746747

748+
def test_setup_requires_with_transitive_extra_dependency(self, monkeypatch):
749+
# Use case: installing a package with a build dependency on
750+
# an already installed `dep[extra]`, which in turn depends
751+
# on `extra_dep` (whose is not already installed).
752+
monkeypatch.setenv(str('PIP_RETRIES'), str('0'))
753+
monkeypatch.setenv(str('PIP_TIMEOUT'), str('0'))
754+
monkeypatch.setenv(str('PIP_NO_INDEX'), str('1'))
755+
with contexts.save_pkg_resources_state():
756+
with contexts.tempdir() as temp_dir:
757+
# Create source distribution for `extra_dep`.
758+
make_trivial_sdist(os.path.join(temp_dir, 'extra_dep-1.0.tar.gz'), 'extra_dep', '1.0')
759+
# Create source tree for `dep`.
760+
dep_pkg = os.path.join(temp_dir, 'dep')
761+
os.mkdir(dep_pkg)
762+
build_files({
763+
'setup.py':
764+
DALS("""
765+
import setuptools
766+
setuptools.setup(
767+
name='dep', version='2.0',
768+
extras_require={'extra': ['extra_dep']},
769+
)
770+
"""),
771+
'setup.cfg': '',
772+
}, prefix=dep_pkg)
773+
# "Install" dep.
774+
run_setup(os.path.join(dep_pkg, 'setup.py'), [str('dist_info')])
775+
working_set.add_entry(dep_pkg)
776+
# Create source tree for test package.
777+
test_pkg = os.path.join(temp_dir, 'test_pkg')
778+
test_setup_py = os.path.join(test_pkg, 'setup.py')
779+
test_setup_cfg = os.path.join(test_pkg, 'setup.cfg')
780+
os.mkdir(test_pkg)
781+
with open(test_setup_py, 'w') as fp:
782+
fp.write(DALS(
783+
'''
784+
from setuptools import installer, setup
785+
setup(setup_requires='dep[extra]')
786+
'''))
787+
with open(test_setup_cfg, 'w') as fp:
788+
fp.write(DALS(
789+
'''
790+
[easy_install]
791+
find_links = {find_links}
792+
''').format(find_links=temp_dir))
793+
# Check...
794+
run_setup(test_setup_py, [str('--version')])
795+
747796

748797
def make_trivial_sdist(dist_path, distname, version):
749798
"""

0 commit comments

Comments
 (0)