def load_readme(relative_path, limit=0): """ Loader for README files """ lines = setupmeta.readlines(relative_path, limit=limit) if lines is not None: content = [] for line in lines: m = RE_README_TOKEN.search(line) if not m: content.append(line) continue pre, post = m.group(1), m.group(4) pre = pre and pre.strip() post = post and post.strip() if pre or post: content.append(line) continue # Not beginning/end, or no spaces around action = m.group(2) param = m.group(3) if action == "end" and param == "long_description": break if action == "include": included = load_readme(param, limit=limit) if included: content.append(included) return "".join(content).strip()
def load_contents(relative_path, limit=0): """Return contents of file with 'relative_path' :param str relative_path: Relative path to file :param int limit: Max number of lines to load :return str|None: Contents, if any """ lines = setupmeta.readlines(relative_path, limit=limit) if lines is not None: return "".join(lines).strip()
def __init__(self, root): self.path = os.path.join(root, "PKG-INFO") self.info = {} self.name = None self.dependency_links = None self.entry_points_txt = None self.requires_txt = None lines = readlines(self.path) if not lines: return # Parse PKG-INFO when present key = None for line_number, line in enumerate(lines, start=1): m = RE_PKG_KEY_VALUE.match(line) if m: key = m.group(1).lower().replace("-", "_") key = self._canonical_names.get(key, key) if key not in MetaDefs.all_fields: continue value = m.group(2) if key in self._list_types: if key not in self.info: self.info[key] = [] self.info[key].append(value) else: self.info[key] = value elif key in self._list_types: # Indented description applying to previous key self.info[key].append(line[8:].rstrip()) elif line.strip(): trace("Unknown format line %s in %s: %s" % (line_number, self.path, line)) self.name = self.info.get("name") self.pythonified_name = pythonified_name(self.name) self.info["long_description"] = "\n".join( self.info.get("long_description", [])) self.load_more_info(root)