Commit 7d34b2d7 authored by Jason R. Coombs's avatar Jason R. Coombs

Extract method for filtering extras

parent 1bbafd87
...@@ -2683,22 +2683,36 @@ class Distribution(object): ...@@ -2683,22 +2683,36 @@ class Distribution(object):
try: try:
return self.__dep_map return self.__dep_map
except AttributeError: except AttributeError:
self.__dep_map = self._build_dep_map() self.__dep_map = self._filter_extras(self._build_dep_map())
return self.__dep_map return self.__dep_map
@staticmethod
def _filter_extras(dm):
"""
Given a mapping of extras to dependencies, strip off
environment markers and filter out any dependencies
not matching the markers.
"""
for extra in list(dm):
if extra:
new_extra = extra
reqs = dm.pop(extra)
if ':' in extra:
new_extra, marker = extra.split(':', 1)
if invalid_marker(marker):
# XXX warn
reqs = []
elif not evaluate_marker(marker):
reqs = []
new_extra = safe_extra(new_extra) or None
dm.setdefault(new_extra, []).extend(reqs)
return dm
def _build_dep_map(self): def _build_dep_map(self):
dm = {} dm = {}
for name in 'requires.txt', 'depends.txt': for name in 'requires.txt', 'depends.txt':
for extra, reqs in split_sections(self._get_metadata(name)): for extra, reqs in split_sections(self._get_metadata(name)):
if extra:
if ':' in extra:
extra, marker = extra.split(':', 1)
if invalid_marker(marker):
# XXX warn
reqs = []
elif not evaluate_marker(marker):
reqs = []
extra = safe_extra(extra) or None
dm.setdefault(extra, []).extend(parse_requirements(reqs)) dm.setdefault(extra, []).extend(parse_requirements(reqs))
return dm return dm
......
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