Skip to content

Commit

Permalink
Adjust expectation that 'extra' is not in the marker evaluation if no…
Browse files Browse the repository at this point in the history
… extras demanded the requirement.
  • Loading branch information
jaraco committed Apr 7, 2016
1 parent be663b8 commit f664385
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
22 changes: 12 additions & 10 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import email.parser
import tempfile
import textwrap
import itertools
from pkgutil import get_importer

try:
Expand Down Expand Up @@ -986,16 +987,17 @@ def markers_pass(self, req):
Return False if the req has a marker and fails
evaluation. Otherwise, return True.
"""
if not req.marker:
return True

result = []
if req in self:
for extra in self[req] or ['']:
result.append(req.marker.evaluate({'extra': extra}))
else:
result.append(req.marker.evaluate())
return any(result)
extra_evals = (
req.marker.evaluate({'extra': extra})
for extra in self.get(req, ())
)
# set up a late-evaluated simple marker evaluation.
simple_eval = (
req.marker.evaluate()
for _ in (None,)
)
evals = itertools.chain(extra_evals, simple_eval)
return not req.marker or any(evals)


class Environment(object):
Expand Down
8 changes: 5 additions & 3 deletions pkg_resources/tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,13 @@ def test_environment_marker_evaluation_called(self):
req_extras = pkg_resources._ReqExtras({req: parent_req.extras})
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")
req, = parse_requirements("bar;python_version>='2' and extra==''")
req, = parse_requirements("bar;extra==''")
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):
"""Extras are also evaluated as markers at resolution time."""
Expand Down

0 comments on commit f664385

Please sign in to comment.