Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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:
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)