diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2016-04-05 11:59:18 +0100 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2016-04-05 11:59:18 +0100 |
| commit | 5c36cd3890dad731a0e3d9764345377406770c31 (patch) | |
| tree | d53acd61a90c74522dbb6da45403ef7166090d4d /pkg_resources | |
| parent | 19fd04bae3809caf61208e3d085491990222aca8 (diff) | |
| download | python-setuptools-git-5c36cd3890dad731a0e3d9764345377406770c31.tar.gz | |
Extract method for testing marker evaluation
Diffstat (limited to 'pkg_resources')
| -rw-r--r-- | pkg_resources/__init__.py | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 4f0a487e..c3e3e96c 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -804,17 +804,10 @@ class WorkingSet(object): if req in processed: # Ignore cyclic or redundant dependencies continue - # If the req has a marker, evaluate it -- skipping the req if - # it evaluates to False. - if req.marker: - result = [] - if req in extra_req_mapping: - for extra in extra_req_mapping[req] or ['']: - result.append(req.marker.evaluate({'extra': extra})) - else: - result.append(req.marker.evaluate()) - if not any(result): - continue + + if not self._markers_pass(req, extra_req_mapping): + continue + dist = best.get(req.key) if dist is None: # Find the best distribution and add it to the map @@ -854,6 +847,26 @@ class WorkingSet(object): # return list of distros to activate return to_activate + @staticmethod + def _markers_pass(req, extra_req_mapping): + """ + Return False if the req has a marker and fails + evaluation. Otherwise, return True. + + extra_req_mapping is a map of requirements to + extras. + """ + if not req.marker: + return True + + result = [] + if req in extra_req_mapping: + for extra in extra_req_mapping[req] or ['']: + result.append(req.marker.evaluate({'extra': extra})) + else: + result.append(req.marker.evaluate()) + return any(result) + def find_plugins(self, plugin_env, full_env=None, installer=None, fallback=True): """Find all activatable distributions in `plugin_env` |
