Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When formatting a requirement, only lowercase its name. #2123

Merged
merged 1 commit into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 20 additions & 0 deletions tests/integration/test_install_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ def test_package_environment_markers(PipenvInstance, pypi):
c = p.pipenv('run python -c "import tablib;"')
assert c.return_code == 1

@pytest.mark.markers
@flaky
def test_platform_python_implementation_marker(PipenvInstance, pypi):
"""Markers should be converted during locking to help users who input this incorrectly
"""
with PipenvInstance(pypi=pypi) as p:
with open(p.pipfile_path, 'w') as f:
contents = """
[packages]
depends-on-marked-package = "*"
""".strip()
f.write(contents)

c = p.pipenv('install')
assert c.return_code == 0

# depends-on-marked-package has an install_requires of 'pytz; platform_python_implementation=="CPython"'
# Verify that that marker shows up in our lockfile unaltered.
assert p.lockfile['default']['pytz']['markers'] == "platform_python_implementation == 'CPython'"


@pytest.mark.run
@pytest.mark.alt
Expand Down
Binary file not shown.