def _safe_repr(val): # FIXME: actually not safe at all. Needs to escape and all. if is_string(val): if len(val.splitlines()) > 1: return '"""%s"""' % (val, ) else: return '"%s"' % (val, ) else: return repr(val)
def _safe_repr(val): # FIXME: actually not safe at all. Needs to escape and all. if is_string(val): if len(val.splitlines()) > 1: return '"""%s"""' % (val,) else: return '"%s"' % (val,) else: return repr(val)
def distutils_to_package_description(dist): root = bento.core.node.Node("", None) top = root.find_dir(os.getcwd()) data = {} data['name'] = dist.get_name() data['version'] = dist.get_version() data['author'] = dist.get_author() data['author_email'] = dist.get_author_email() data['maintainer'] = dist.get_contact() data['maintainer_email'] = dist.get_contact_email() data['summary'] = dist.get_description() data['description'] = dist.get_long_description().replace("#", "\#") data['license'] = dist.get_license() data['platforms'] = dist.get_platforms() data['download_url'] = dist.get_download_url() data['url'] = dist.get_url() # XXX: reliable way to detect whether Distribution was monkey-patched by # setuptools try: reqs = getattr(dist, "install_requires") # FIXME: how to detect this correctly if is_string(reqs): reqs = [reqs] data['install_requires'] = reqs except AttributeError: pass if dist.py_modules is None: data['py_modules'] = [] else: data['py_modules'] = dist.py_modules if dist.packages is None: packages = [] else: packages = dist.packages data['packages'] = validate_packages(packages, top) if dist.ext_modules: data['extensions'] = dict([(e.name, e) for e in dist.ext_modules]) else: data['extensions'] = {} data['classifiers'] = dist.get_classifiers() data["executables"] = {} entry_points = entry_points_from_dist(dist) if entry_points: console_scripts = entry_points.get("console_scripts", []) for entry in console_scripts: exe = Executable.from_representation(entry) data["executables"][exe.name] = exe return PackageDescription(**data)
def distutils_to_package_description(dist): root = bento.core.node.Node("", None) top = root.find_dir(os.getcwd()) data = {} data["name"] = dist.get_name() data["version"] = dist.get_version() data["author"] = dist.get_author() data["author_email"] = dist.get_author_email() data["maintainer"] = dist.get_contact() data["maintainer_email"] = dist.get_contact_email() data["summary"] = dist.get_description() data["description"] = dist.get_long_description().replace("#", "\#") data["license"] = dist.get_license() data["platforms"] = dist.get_platforms() data["download_url"] = dist.get_download_url() data["url"] = dist.get_url() # XXX: reliable way to detect whether Distribution was monkey-patched by # setuptools try: reqs = getattr(dist, "install_requires") # FIXME: how to detect this correctly if is_string(reqs): reqs = [reqs] data["install_requires"] = reqs except AttributeError: pass if dist.py_modules is None: data["py_modules"] = [] else: data["py_modules"] = dist.py_modules if dist.packages is None: packages = [] else: packages = dist.packages data["packages"] = validate_packages(packages, top) if dist.ext_modules: data["extensions"] = dict([(e.name, e) for e in dist.ext_modules]) else: data["extensions"] = {} data["classifiers"] = dist.get_classifiers() data["executables"] = {} entry_points = entry_points_from_dist(dist) if entry_points: console_scripts = entry_points.get("console_scripts", []) for entry in console_scripts: exe = Executable.from_representation(entry) data["executables"][exe.name] = exe return PackageDescription(**data)
def entry_points_from_dist(dist): if hasattr(dist, "entry_points"): from pkg_resources import split_sections if is_string(dist.entry_points): entry_points = {} sections = split_sections(dist.entry_points) for group, lines in sections: group = group.strip() entry_points[group] = lines else: entry_points = dist.entry_points else: entry_points = {} return entry_points
def make_node(self, lst): "make a branch of nodes" if is_string(lst): lst = [x for x in split_path(lst) if x and x != '.'] cur = self for x in lst: if x == '..': cur = cur.parent continue if getattr(cur, 'children', {}): if x in cur.children: cur = cur.children[x] continue else: cur.children = {} cur = self.__class__(x, cur) return cur
def _test_impl(self, data, ref): res = [] while True: tok = self.lexer.token() if not tok: break res.append(tok.type) if is_string(ref): ref = split(ref) try: self.assertEqual(res, ref) except AssertionError: e = extract_exception() cnt = 0 for i, j in zip(res, ref): if not i == j: break cnt += 1 print(("Break at index %d" % cnt)) raise e
def _test_impl(self, data, ref): res = [] while True: tok = self.lexer.token() if not tok: break res.append(tok.type) if is_string(ref): ref = split(ref) try: self.assertEqual(res, ref) except AssertionError: e = extract_exception() cnt = 0 for i, j in zip(res, ref): if not i == j: break cnt += 1 print("Break at index %d" % cnt) raise e
def find_node(self, lst): "read the file system, make the nodes as needed" if is_string(lst): lst = [x for x in split_path(lst) if x and x != '.'] cur = self for x in lst: if x == '..': cur = cur.parent continue try: if x in cur.children: cur = cur.children[x] continue except: cur.children = {} # optimistic: create the node first then look if it was correct to do so cur = self.__class__(x, cur) try: os.stat(cur.abspath()) except: del cur.parent.children[x] return None ret = cur try: while not getattr(cur.parent, 'cache_isdir', None): cur = cur.parent cur.cache_isdir = True except AttributeError: pass return ret