Skip to content

Commit

Permalink
When formatting a requirement, only lowercase its name.
Browse files Browse the repository at this point in the history
This fixes pypa#2113.

This bug was introduced in
<jazzband/pip-tools#452> as a band-aid fix to
<jazzband/pip-tools#431>. Pipenv then copied
that code in <pypa@2553ebc#diff-b56b95ccea8595a0f6f24ea753842976>, and inherited this latent bug.

Maybe the right fix is for pypa/packaging to lowercase the name? There's
a comment here
<https://github.com/pypa/packaging/blob/16.8/packaging/requirements.py#L86>
about normalizing the requirement's name, which might be what this is
referring to.
  • Loading branch information
jfly committed May 7, 2018
1 parent d5d4308 commit 392eae1
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion pipenv/patched/piptools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,36 @@ def make_install_requirement(name, version, extras, markers, constraint=False):
constraint=constraint)


def _requirement_to_str_lowercase_name(requirement):
"""
Formats a packaging.requirements.Requirement with a lowercase name.
This is simply a copy of
https://github.com/pypa/packaging/blob/16.8/packaging/requirements.py#L109-L124
modified to lowercase the dependency name.
Previously, we were invoking the original Requirement.__str__ method and
lowercasing the entire result, which would lowercase the name, *and* other,
important stuff that should not be lowercased (such as the marker). See
this issue for more information: https://github.com/pypa/pipenv/issues/2113.
"""
parts = [requirement.name.lower()]

if requirement.extras:
parts.append("[{0}]".format(",".join(sorted(requirement.extras))))

if requirement.specifier:
parts.append(str(requirement.specifier))

if requirement.url:
parts.append("@ {0}".format(requirement.url))

if requirement.marker:
parts.append("; {0}".format(requirement.marker))

return "".join(parts)


def format_requirement(ireq, marker=None):
"""
Generic formatter for pretty printing InstallRequirements to the terminal
Expand All @@ -66,7 +96,7 @@ def format_requirement(ireq, marker=None):
if ireq.editable:
line = '-e {}'.format(ireq.link)
else:
line = str(ireq.req).lower()
line = _requirement_to_str_lowercase_name(ireq.req)

if marker:
line = '{}; {}'.format(line, marker)
Expand Down

0 comments on commit 392eae1

Please sign in to comment.