summaryrefslogtreecommitdiff
path: root/pkg_resources
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2016-04-07 22:22:58 +0100
committerJason R. Coombs <jaraco@jaraco.com>2016-04-07 22:22:58 +0100
commitf664385be2051cd135ad52e1563993945e0abe10 (patch)
tree6df0452289f22685455a0e4d20ab582f86c770bb /pkg_resources
parentbe663b8596fc3e3d02cb5716db1d638788a0230e (diff)
downloadpython-setuptools-git-f664385be2051cd135ad52e1563993945e0abe10.tar.gz
Adjust expectation that 'extra' is not in the marker evaluation if no extras demanded the requirement.
Diffstat (limited to 'pkg_resources')
-rw-r--r--pkg_resources/__init__.py22
-rw-r--r--pkg_resources/tests/test_resources.py8
2 files changed, 17 insertions, 13 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index d0ba5159..04064d5a 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -35,6 +35,7 @@ import plistlib
import email.parser
import tempfile
import textwrap
+import itertools
from pkgutil import get_importer
try:
@@ -986,16 +987,17 @@ class _ReqExtras(dict):
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):
diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py
index acc8dc1e..bd074f22 100644
--- a/pkg_resources/tests/test_resources.py
+++ b/pkg_resources/tests/test_resources.py
@@ -201,11 +201,13 @@ class TestDistro:
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."""