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

fix regression with environment markers handling #3967

Closed
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
10 changes: 7 additions & 3 deletions pip/_vendor/packaging/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ def __repr__(self):


class Variable(Node):
pass

def __str__(self):
return self.value


class Value(Node):
pass

def __str__(self):
return repr(str(self.value))


VARIABLE = (
Expand Down Expand Up @@ -151,7 +155,7 @@ def _format_marker(marker, first=True):
else:
return "(" + " ".join(inner) + ")"
elif isinstance(marker, tuple):
return '{0} {1} "{2}"'.format(*marker)
return '{0} {1} {2}'.format(*marker)
else:
return marker

Expand Down
23 changes: 23 additions & 0 deletions tests/unit/test_req.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,3 +607,26 @@ def test_exclusive_environment_markers():
req_set.add_requirement(eq26)
req_set.add_requirement(ne26)
assert req_set.has_requirement('Django')


def test_requirement_str():
for req_str, req_cannonical_str in (
('pywin32 (>1.0); sys.platform == "win32"',
"pywin32>1.0; sys_platform == 'win32'"),
("pywin31; sys.platform == 'win32'",
"pywin31; sys_platform == 'win32'"),
("foo != 1.3; platform.machine=='i386'",
"foo!=1.3; platform_machine == 'i386'"),
("bar; python_version=='2.4'or python_version==\"2.5\"",
"bar; python_version == '2.4' or python_version == '2.5'"),
("bar; ('3.2' <= python_version and python_version <= '3.5')",
"bar; '3.2' <= python_version and python_version <= '3.5'"),
("libxslt; 'linux' in sys.platform",
"libxslt; 'linux' in sys_platform"),
("foobar; '\"' in sys_platform",
"foobar; '\"' in sys_platform"),
("foobar; \"'\" in sys_platform",
"foobar; \"'\" in sys_platform"),
):
req = Requirement(req_str)
assert str(req) == req_cannonical_str