Skip to content

Commit

Permalink
Canonicalize extras before matching them - Fix issue #3810 (#4037)
Browse files Browse the repository at this point in the history
Canonicalize InstallRequirement.extras

since dist.extras are already canonicalized, pip needs to canonicalize
extras before matching them with dist.extras

Fixes #3810
  • Loading branch information
xavfernandez authored Oct 29, 2016
1 parent 78af5b1 commit e53e224
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pip/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def _strip_extras(path):
return path_no_extras, extras


def _safe_extras(extras):
return set(pkg_resources.safe_extra(extra) for extra in extras)


class InstallRequirement(object):

def __init__(self, req, comes_from, source_dir=None, editable=False,
Expand All @@ -85,7 +89,7 @@ def __init__(self, req, comes_from, source_dir=None, editable=False,
add_msg = traceback.format_exc()
raise InstallationError(
"Invalid requirement: '%s'\n%s" % (req, add_msg))
self.extras = req.extras
self.extras = _safe_extras(req.extras)

self.req = req
self.comes_from = comes_from
Expand Down Expand Up @@ -149,7 +153,7 @@ def from_editable(cls, editable_req, comes_from=None, default_vcs=None,
wheel_cache=wheel_cache)

if extras_override is not None:
res.extras = extras_override
res.extras = _safe_extras(extras_override)

return res

Expand Down Expand Up @@ -224,7 +228,8 @@ def from_line(
wheel_cache=wheel_cache, constraint=constraint)

if extras:
res.extras = Requirement('placeholder' + extras).extras
res.extras = _safe_extras(
Requirement('placeholder' + extras).extras)

return res

Expand Down Expand Up @@ -1158,7 +1163,7 @@ def parse_editable(editable_req, default_vcs=None):
return (
package_name,
url_no_extras,
Requirement("placeholder" + extras).extras,
Requirement("placeholder" + extras.lower()).extras,
)
else:
return package_name, url_no_extras, None
Expand Down
22 changes: 22 additions & 0 deletions tests/functional/test_install_extras.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import textwrap
import pytest
from os.path import join

Expand Down Expand Up @@ -103,3 +104,24 @@ def test_nonexistent_options_listed_in_order(script, data):
" simplewheel 2.0 does not provide the extra 'nope'"
)
assert msg in result.stderr


def test_install_special_extra(script, data):
# Check that uppercase letters and '-' are dealt with
# make a dummy project
pkga_path = script.scratch_path / 'pkga'
pkga_path.mkdir()
pkga_path.join("setup.py").write(textwrap.dedent("""
from setuptools import setup
setup(name='pkga',
version='0.1',
extras_require={'Hop_hOp-hoP': ['missing_pkg']},
)
"""))

result = script.pip(
'install', '--no-index', '%s[Hop_hOp-hoP]' % pkga_path,
expect_error=True)
assert (
"Could not find a version that satisfies the requirement missing_pkg"
) in result.stderr, str(result)

0 comments on commit e53e224

Please sign in to comment.