def load(impl): """Load iformation about installed Python distributions. :param impl: interpreter implementation, f.e. cpython2, cpython3, pypy :type impl: str """ fname = PYDIST_OVERRIDES_FNAMES.get(impl) if exists(fname): to_check = [fname] # first one! else: to_check = [] dname = PYDIST_DIRS.get(impl) if isdir(dname): to_check.extend(join(dname, i) for i in os.listdir(dname)) fbname = '/usr/share/dh-python/dist/{}_fallback'.format(impl) if exists(fbname): # fall back generated at dh-python build time to_check.append(fbname) # last one! result = {} for fpath in to_check: with open(fpath, encoding='utf-8') as fp: for line in fp: line = line.strip('\r\n') if line.startswith('#') or not line: continue dist = PYDIST_RE.search(line) if not dist: raise Exception('invalid pydist line: %s (in %s)' % (line, fpath)) dist = dist.groupdict() name = safe_name(dist['name']) dist['versions'] = get_requested_versions(impl, dist['vrange']) dist['dependency'] = dist['dependency'].strip() if dist['rules']: dist['rules'] = dist['rules'].split(';') else: dist['rules'] = [] result.setdefault(name, []).append(dist) return result