Commit f664385b authored by Jason R. Coombs's avatar Jason R. Coombs

Adjust expectation that 'extra' is not in the marker evaluation if no extras...

Adjust expectation that 'extra' is not in the marker evaluation if no extras demanded the requirement.
parent be663b85
...@@ -35,6 +35,7 @@ import plistlib ...@@ -35,6 +35,7 @@ import plistlib
import email.parser import email.parser
import tempfile import tempfile
import textwrap import textwrap
import itertools
from pkgutil import get_importer from pkgutil import get_importer
try: try:
...@@ -986,16 +987,17 @@ class _ReqExtras(dict): ...@@ -986,16 +987,17 @@ class _ReqExtras(dict):
Return False if the req has a marker and fails Return False if the req has a marker and fails
evaluation. Otherwise, return True. evaluation. Otherwise, return True.
""" """
if not req.marker: extra_evals = (
return True req.marker.evaluate({'extra': extra})
for extra in self.get(req, ())
result = [] )
if req in self: # set up a late-evaluated simple marker evaluation.
for extra in self[req] or ['']: simple_eval = (
result.append(req.marker.evaluate({'extra': extra})) req.marker.evaluate()
else: for _ in (None,)
result.append(req.marker.evaluate()) )
return any(result) evals = itertools.chain(extra_evals, simple_eval)
return not req.marker or any(evals)
class Environment(object): class Environment(object):
......
...@@ -201,11 +201,13 @@ class TestDistro: ...@@ -201,11 +201,13 @@ class TestDistro:
req_extras = pkg_resources._ReqExtras({req: parent_req.extras}) req_extras = pkg_resources._ReqExtras({req: parent_req.extras})
assert req_extras.markers_pass(req) assert req_extras.markers_pass(req)
# this is a little awkward; I would want this to fail # extra should not be present in the marker namespace if
# no markers were supplied
parent_req, = parse_requirements("foo") parent_req, = parse_requirements("foo")
req, = parse_requirements("bar;python_version>='2' and extra==''") req, = parse_requirements("bar;extra==''")
req_extras = pkg_resources._ReqExtras({req: parent_req.extras}) req_extras = pkg_resources._ReqExtras({req: parent_req.extras})
assert req_extras.markers_pass(req) with pytest.raises(packaging.markers.UndefinedEnvironmentName):
req_extras.markers_pass(req)
def test_marker_evaluation_with_extras(self): def test_marker_evaluation_with_extras(self):
"""Extras are also evaluated as markers at resolution time.""" """Extras are also evaluated as markers at resolution time."""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment