Skip to content

Commit 812b83c

Browse files
authored
Merge pull request #1922 from benoit-pierre/fix_possible_issue_with_transitive_build_dependencies_from_extras
fix possible issue with transitive build dependencies
2 parents cbd977b + a2e883e commit 812b83c

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
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+
Build dependencies (setup_requires and tests_require) now install transitive dependencies indicated by extras.

setuptools/installer.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def fetch_build_egg(dist, req):
6464
pkg_resources.get_distribution('wheel')
6565
except pkg_resources.DistributionNotFound:
6666
dist.announce('WARNING: The wheel package is not available.', log.WARN)
67-
if not isinstance(req, pkg_resources.Requirement):
68-
req = pkg_resources.Requirement.parse(req)
67+
# Ignore environment markers; if supplied, it is required.
68+
req = strip_marker(req)
6969
# Take easy_install options into account, but do not override relevant
7070
# pip environment variables (like PIP_INDEX_URL or PIP_QUIET); they'll
7171
# take precedence.
@@ -127,3 +127,15 @@ def fetch_build_egg(dist, req):
127127
dist = pkg_resources.Distribution.from_filename(
128128
dist_location, metadata=dist_metadata)
129129
return dist
130+
131+
132+
def strip_marker(req):
133+
"""
134+
Return a new requirement without the environment marker to avoid
135+
calling pip with something like `babel; extra == "i18n"`, which
136+
would always be ignored.
137+
"""
138+
# create a copy to avoid mutating the input
139+
req = pkg_resources.Requirement.parse(str(req))
140+
req.marker = None
141+
return req

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)