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
def _build_dep_map(self): @staticmethod
dm = {} def _filter_extras(dm):
for name in 'requires.txt', 'depends.txt': """
for extra, reqs in split_sections(self._get_metadata(name)): 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: if extra:
new_extra = extra
reqs = dm.pop(extra)
if ':' in extra: if ':' in extra:
extra, marker = extra.split(':', 1) new_extra, marker = extra.split(':', 1)
if invalid_marker(marker): if invalid_marker(marker):
# XXX warn # XXX warn
reqs = [] reqs = []
elif not evaluate_marker(marker): elif not evaluate_marker(marker):
reqs = [] reqs = []
extra = safe_extra(extra) or None new_extra = safe_extra(new_extra) or None
dm.setdefault(new_extra, []).extend(reqs)
return dm
def _build_dep_map(self):
dm = {}
for name in 'requires.txt', 'depends.txt':
for extra, reqs in split_sections(self._get_metadata(name)):
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