Skip to content

Commit 8b20dfd

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 8b20dfd

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-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: 44 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,49 @@ 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+
with contexts.save_pkg_resources_state():
753+
with contexts.tempdir() as temp_dir:
754+
# Create source distribution for `extra_dep`.
755+
make_trivial_sdist(os.path.join(temp_dir, 'extra_dep-1.0.tar.gz'), 'extra_dep', '1.0')
756+
# Create source tree for `dep`.
757+
dep_pkg = os.path.join(temp_dir, 'dep')
758+
os.mkdir(dep_pkg)
759+
build_files({
760+
'setup.py':
761+
DALS("""
762+
import setuptools
763+
setuptools.setup(
764+
name='dep', version='2.0',
765+
extras_require={'extra': ['extra_dep']},
766+
)
767+
"""),
768+
'setup.cfg': '',
769+
}, prefix=dep_pkg)
770+
# "Install" dep.
771+
run_setup(os.path.join(dep_pkg, 'setup.py'), [str('dist_info')])
772+
working_set.add_entry(dep_pkg)
773+
# Create source tree for test package.
774+
test_pkg = os.path.join(temp_dir, 'test_pkg')
775+
test_setup_py = os.path.join(test_pkg, 'setup.py')
776+
test_setup_cfg = os.path.join(test_pkg, 'setup.cfg')
777+
os.mkdir(test_pkg)
778+
with open(test_setup_py, 'w') as fp:
779+
fp.write(DALS(
780+
'''
781+
from setuptools import installer, setup
782+
setup(setup_requires='dep[extra]')
783+
'''))
784+
# Check...
785+
monkeypatch.setenv(str('PIP_FIND_LINKS'), str(temp_dir))
786+
monkeypatch.setenv(str('PIP_NO_INDEX'), str('1'))
787+
monkeypatch.setenv(str('PIP_RETRIES'), str('0'))
788+
monkeypatch.setenv(str('PIP_TIMEOUT'), str('0'))
789+
run_setup(test_setup_py, [str('--version')])
790+
747791

748792
def make_trivial_sdist(dist_path, distname, version):
749793
"""

0 commit comments

Comments
 (0)