def _print_paths(self, ref, conan, path_resolver, show): if isinstance(ref, ConanFileReference): if show("export_folder"): path = path_resolver.export(ref) self._out.writeln(" export_folder: %s" % path, Color.BRIGHT_GREEN) if show("source_folder"): path = path_resolver.source(ref, conan.short_paths) self._out.writeln(" source_folder: %s" % path, Color.BRIGHT_GREEN) if show("build_folder") and isinstance(path_resolver, SimplePaths): # @todo: check if this is correct or if it must always be package_id() bid = build_id(conan) if not bid: bid = conan.info.package_id() path = path_resolver.build(PackageReference(ref, bid), conan.short_paths) self._out.writeln(" build_folder: %s" % path, Color.BRIGHT_GREEN) if show("package_folder") and isinstance(path_resolver, SimplePaths): id_ = conan.info.package_id() path = path_resolver.package(PackageReference(ref, id_), conan.short_paths) self._out.writeln(" package_folder: %s" % path, Color.BRIGHT_GREEN)
def graph(self): nodes = [] nodes_map = {} graph_nodes = self._deps_graph.by_levels() graph_nodes = reversed([n for level in graph_nodes for n in level]) for i, node in enumerate(graph_nodes): ref, conanfile = node.conan_ref, node.conanfile nodes_map[node] = i if ref: label = "%s/%s" % (ref.name, ref.version) fulllabel = ["<h3>%s</h3>" % str(ref)] fulllabel.append("<ul>") for name, data in [ ("id", conanfile.info.package_id()), ("build_id", build_id(conanfile)), ("url", '<a href="{url}">{url}</a>'.format(url=conanfile.url)), ("homepage", '<a href="{url}">{url}</a>'.format( url=conanfile.homepage)), ("license", conanfile.license), ("author", conanfile.author), ("topics", str(conanfile.topics)) ]: if data: data = data.replace("'", '"') fulllabel.append("<li><b>%s</b>: %s</li>" % (name, data)) fulllabel.append("<ul>") fulllabel = "".join(fulllabel) else: fulllabel = label = node.conan_ref or str(node.conanfile) if node.build_require: shape = "ellipse" else: shape = "box" color = { BINARY_CACHE: "SkyBlue", BINARY_DOWNLOAD: "LightGreen", BINARY_BUILD: "Khaki", BINARY_MISSING: "OrangeRed", BINARY_UPDATE: "SeaGreen" }.get(node.binary, "White") nodes.append("{id: %d, label: '%s', shape: '%s', " "color: {background: '%s'}, fulllabel: '%s'}" % (i, label, shape, color, fulllabel)) nodes = ",\n".join(nodes) edges = [] for node in self._deps_graph.nodes: for node_to in node.neighbors(): src = nodes_map[node] dst = nodes_map[node_to] edges.append("{ from: %d, to: %d }" % (src, dst)) edges = ",\n".join(edges) result = self._template.replace("%NODES%", nodes).replace("%EDGES%", edges) visjs, viscss = self._visjs_paths() return result.replace("%VISJS%", visjs).replace("%VISCSS%", viscss)
def graph(self): nodes = [] nodes_map = {} graph_nodes = self._deps_graph.by_levels() graph_nodes = reversed([n for level in graph_nodes for n in level]) for i, node in enumerate(graph_nodes): ref, conanfile = node.conan_ref, node.conanfile nodes_map[node] = i if ref: label = "%s/%s" % (ref.name, ref.version) fulllabel = ["<h3>%s</h3>" % str(ref)] fulllabel.append("<ul>") for name, data in [ ("id", conanfile.info.package_id()), ("build_id", build_id(conanfile)), ("url", '<a href="{url}">{url}</a>'.format(url=conanfile.url)), ("license", conanfile.license), ("author", conanfile.author) ]: if data: data = data.replace("'", '"') fulllabel.append("<li><b>%s</b>: %s</li>" % (name, data)) fulllabel.append("<ul>") fulllabel = "".join(fulllabel) else: fulllabel = label = self._project_reference nodes.append( "{id: %d, label: '%s', shape: 'box', fulllabel: '%s'}" % (i, label, fulllabel)) nodes = ",\n".join(nodes) edges = [] for node in self._deps_graph.nodes: for node_to in node.neighbors(): src = nodes_map[node] dst = nodes_map[node_to] edges.append("{ from: %d, to: %d }" % (src, dst)) edges = ",\n".join(edges) return self._template.replace("%NODES%", nodes).replace("%EDGES%", edges)
def data(self): def ensure_iterable(value): if isinstance(value, (list, tuple)): return value return value, return { 'build_id': build_id(self._conanfile), 'url': self._conanfile.url, 'homepage': self._conanfile.homepage, 'license': self._conanfile.license, 'author': self._conanfile.author, 'topics': ensure_iterable(self._conanfile.topics) if self._conanfile.topics else None }
def graph(self): nodes = [] nodes_map = {} graph_nodes = self._deps_graph.by_levels() graph_nodes = reversed([n for level in graph_nodes for n in level]) for i, node in enumerate(graph_nodes): ref, conanfile = node nodes_map[node] = i if ref: label = "%s/%s" % (ref.name, ref.version) fulllabel = ["<h3>%s</h3>" % str(ref)] fulllabel.append("<ul>") for name, data in [("id", conanfile.info.package_id()), ("build_id", build_id(conanfile)), ("url", '<a href="{url}">{url}</a>'.format(url=conanfile.url)), ("license", conanfile.license), ("author", conanfile.author)]: if data: data = data.replace("'", '"') fulllabel.append("<li><b>%s</b>: %s</li>" % (name, data)) fulllabel.append("<ul>") fulllabel = "".join(fulllabel) else: fulllabel = label = self._project_reference nodes.append("{id: %d, label: '%s', shape: 'box', fulllabel: '%s'}" % (i, label, fulllabel)) nodes = ",\n".join(nodes) edges = [] for node in self._deps_graph.nodes: for node_to in self._deps_graph.neighbors(node): src = nodes_map[node] dst = nodes_map[node_to] edges.append("{ from: %d, to: %d }" % (src, dst)) edges = ",\n".join(edges) return self._template.replace("%NODES%", nodes).replace("%EDGES%", edges)
def graph(self): nodes = [] nodes_map = {} graph_nodes = self._deps_graph.by_levels() graph_nodes = reversed([n for level in graph_nodes for n in level]) for i, node in enumerate(graph_nodes): ref, conanfile = node nodes_map[node] = i if ref: label = "%s/%s" % (ref.name, ref.version) fulllabel = [str(ref)] fulllabel.append("") fulllabel.append("id: %s" % conanfile.info.package_id()) fulllabel.append("build_id: %s" % build_id(conanfile)) if conanfile.url: fulllabel.append("url: %s" % conanfile.url) if conanfile.license: fulllabel.append("license: %s" % conanfile.license) if conanfile.author: fulllabel.append("author: %s" % conanfile.author) fulllabel = r"\n".join(fulllabel) else: fulllabel = label = self._project_reference nodes.append( "{id: %d, label: '%s', shape: 'box', fulllabel: '%s'}" % (i, label, fulllabel)) nodes = ",\n".join(nodes) edges = [] for node in self._deps_graph.nodes: for node_to in self._deps_graph.neighbors(node): src = nodes_map[node] dst = nodes_map[node_to] edges.append("{ from: %d, to: %d }" % (src, dst)) edges = ",\n".join(edges) return self._template.replace("%NODES%", nodes).replace("%EDGES%", edges)
def _grab_info_data(self, deps_graph, grab_paths): """ Convert 'deps_graph' into consumible information for json and cli """ compact_nodes = OrderedDict() for node in sorted(deps_graph.nodes): compact_nodes.setdefault((node.ref, node.package_id), []).append(node) build_time_nodes = deps_graph.build_time_nodes() remotes = self._cache.registry.load_remotes() ret = [] for (ref, package_id), list_nodes in compact_nodes.items(): node = list_nodes[0] if node.recipe == RECIPE_VIRTUAL: continue item_data = {} conanfile = node.conanfile if node.recipe == RECIPE_CONSUMER: ref = str(conanfile) else: item_data["revision"] = ref.revision item_data["reference"] = str(ref) item_data["is_ref"] = isinstance(ref, ConanFileReference) item_data["display_name"] = conanfile.display_name item_data["id"] = package_id item_data["build_id"] = build_id(conanfile) # Paths if isinstance(ref, ConanFileReference) and grab_paths: package_layout = self._cache.package_layout( ref, conanfile.short_paths) item_data["export_folder"] = package_layout.export() item_data["source_folder"] = package_layout.source() pref_build_id = build_id(conanfile) or package_id pref = PackageReference(ref, pref_build_id) item_data["build_folder"] = package_layout.build(pref) pref = PackageReference(ref, package_id) item_data["package_folder"] = package_layout.package(pref) try: reg_remote = self._cache.package_layout( ref).load_metadata().recipe.remote reg_remote = remotes.get(reg_remote) if reg_remote: item_data["remote"] = { "name": reg_remote.name, "url": reg_remote.url } except Exception: pass def _add_if_exists(attrib, as_list=False): value = getattr(conanfile, attrib, None) if value: if not as_list: item_data[attrib] = value else: item_data[attrib] = list(value) if isinstance(value, (list, tuple, set)) \ else [value, ] _add_if_exists("url") _add_if_exists("homepage") _add_if_exists("license", as_list=True) _add_if_exists("author") _add_if_exists("description") _add_if_exists("topics", as_list=True) if isinstance(ref, ConanFileReference): item_data["recipe"] = node.recipe if get_env("CONAN_CLIENT_REVISIONS_ENABLED", False) and node.ref.revision: item_data["revision"] = node.ref.revision item_data["binary"] = node.binary if node.binary_remote: item_data["binary_remote"] = node.binary_remote.name node_times = self._read_dates(deps_graph) if node_times and node_times.get(ref, None): item_data["creation_date"] = node_times.get(ref, None) if isinstance(ref, ConanFileReference): dependants = [ n for node in list_nodes for n in node.inverse_neighbors() ] required = [ d.conanfile for d in dependants if d.recipe != RECIPE_VIRTUAL ] if required: item_data["required_by"] = [ d.display_name for d in required ] depends = node.neighbors() requires = [d for d in depends if d not in build_time_nodes] build_requires = [ d for d in depends if d in build_time_nodes ] # TODO: May use build_require_context information if requires: item_data["requires"] = [ repr(d.ref.copy_clear_rev()) for d in requires ] if build_requires: item_data["build_requires"] = [ repr(d.ref.copy_clear_rev()) for d in build_requires ] ret.append(item_data) return ret
def print_info(self, deps_graph, project_reference, _info, registry, graph_updates_info=None, remote=None, node_times=None, path_resolver=None, package_filter=None, show_paths=False): """ Print the dependency information for a conan file Attributes: deps_graph: the dependency graph of conan file references to print placeholder_reference: the conan file reference that represents the conan file for a project on the path. This may be None, in which case the project itself will not be part of the printed dependencies. remote: Remote specified in install command. Could be different from the registry one. """ if _info is None: # No filter def show(_): return True else: _info_lower = [s.lower() for s in _info.split(",")] def show(field): return field in _info_lower graph_updates_info = graph_updates_info or {} for node in sorted(deps_graph.nodes): ref, conan = node if not ref: # ref is only None iff info is being printed for a project directory, and # not a passed in reference if project_reference is None: continue else: ref = project_reference if package_filter and not fnmatch.fnmatch(str(ref), package_filter): continue self._out.writeln("%s" % str(ref), Color.BRIGHT_CYAN) reg_remote = registry.get_ref(ref) # Excludes PROJECT fake reference remote_name = remote if reg_remote and not remote: remote_name = reg_remote.name if show("id"): id_ = conan.info.package_id() self._out.writeln(" ID: %s" % id_, Color.BRIGHT_GREEN) if show("build_id"): bid = build_id(conan) self._out.writeln(" BuildID: %s" % bid, Color.BRIGHT_GREEN) if show_paths: self._print_paths(ref, conan, path_resolver, show) if isinstance(ref, ConanFileReference) and show("remote"): if reg_remote: self._out.writeln( " Remote: %s=%s" % (reg_remote.name, reg_remote.url), Color.BRIGHT_GREEN) else: self._out.writeln(" Remote: None", Color.BRIGHT_GREEN) url = getattr(conan, "url", None) license_ = getattr(conan, "license", None) author = getattr(conan, "author", None) if url and show("url"): self._out.writeln(" URL: %s" % url, Color.BRIGHT_GREEN) if license_ and show("license"): if isinstance(license_, (list, tuple, set)): self._out.writeln(" Licenses: %s" % ", ".join(license_), Color.BRIGHT_GREEN) else: self._out.writeln(" License: %s" % license_, Color.BRIGHT_GREEN) if author and show("author"): self._out.writeln(" Author: %s" % author, Color.BRIGHT_GREEN) if isinstance( ref, ConanFileReference) and show("update"): # Excludes PROJECT update = graph_updates_info.get(ref) update_messages = { None: ("Version not checked", Color.WHITE), 0: ("You have the latest version (%s)" % remote_name, Color.BRIGHT_GREEN), 1: ("There is a newer version (%s)" % remote_name, Color.BRIGHT_YELLOW), -1: ("The local file is newer than remote's one (%s)" % remote_name, Color.BRIGHT_RED) } self._out.writeln( " Updates: %s" % update_messages[update][0], update_messages[update][1]) if node_times and node_times.get(ref, None) and show("date"): self._out.writeln( " Creation date: %s" % node_times.get(ref, None), Color.BRIGHT_GREEN) dependants = deps_graph.inverse_neighbors(node) if isinstance(ref, ConanFileReference) and show("required"): # Excludes self._out.writeln(" Required by:", Color.BRIGHT_GREEN) for d in dependants: ref = repr( d.conan_ref) if d.conan_ref else project_reference self._out.writeln(" %s" % ref, Color.BRIGHT_YELLOW) if show("requires"): depends = deps_graph.neighbors(node) if depends: self._out.writeln(" Requires:", Color.BRIGHT_GREEN) for d in depends: self._out.writeln(" %s" % repr(d.conan_ref), Color.BRIGHT_YELLOW)
def print_info(self, deps_graph, _info, registry, node_times=None, path_resolver=None, package_filter=None, show_paths=False): """ Print the dependency information for a conan file Attributes: deps_graph: the dependency graph of conan file references to print placeholder_reference: the conan file reference that represents the conan file for a project on the path. This may be None, in which case the project itself will not be part of the printed dependencies. """ if _info is None: # No filter def show(_): return True else: _info_lower = [s.lower() for s in _info] def show(field): return field in _info_lower compact_nodes = OrderedDict() for node in sorted(deps_graph.nodes): compact_nodes.setdefault((node.conan_ref, node.conanfile.info.package_id()), []).append(node) for (ref, package_id), list_nodes in compact_nodes.items(): node = list_nodes[0] conan = node.conanfile if not ref: # ref is only None iff info is being printed for a project directory, and # not a passed in reference if conan.output is None: # Identification of "virtual" node continue ref = str(conan) if package_filter and not fnmatch.fnmatch(str(ref), package_filter): continue self._out.writeln("%s" % str(ref), Color.BRIGHT_CYAN) try: # Excludes PROJECT fake reference reg_remote = registry.refs.get(ref) except: reg_remote = None if show("id"): self._out.writeln(" ID: %s" % package_id, Color.BRIGHT_GREEN) if show("build_id"): bid = build_id(conan) self._out.writeln(" BuildID: %s" % bid, Color.BRIGHT_GREEN) if show_paths: self._print_paths(ref, conan, path_resolver, show) if isinstance(ref, ConanFileReference) and show("remote"): if reg_remote: self._out.writeln(" Remote: %s=%s" % (reg_remote.name, reg_remote.url), Color.BRIGHT_GREEN) else: self._out.writeln(" Remote: None", Color.BRIGHT_GREEN) url = getattr(conan, "url", None) homepage = getattr(conan, "homepage", None) license_ = getattr(conan, "license", None) author = getattr(conan, "author", None) topics = getattr(conan, "topics", None) if url and show("url"): self._out.writeln(" URL: %s" % url, Color.BRIGHT_GREEN) if homepage and show("homepage"): self._out.writeln(" Homepage: %s" % homepage, Color.BRIGHT_GREEN) if license_ and show("license"): if isinstance(license_, (list, tuple, set)): self._out.writeln(" Licenses: %s" % ", ".join(license_), Color.BRIGHT_GREEN) else: self._out.writeln(" License: %s" % license_, Color.BRIGHT_GREEN) if author and show("author"): self._out.writeln(" Author: %s" % author, Color.BRIGHT_GREEN) if topics and show("topics"): if isinstance(topics, (list, tuple, set)): self._out.writeln(" Topics: %s" % ", ".join(topics), Color.BRIGHT_GREEN) else: self._out.writeln(" Topics: %s" % topics, Color.BRIGHT_GREEN) if isinstance(ref, ConanFileReference) and show("recipe"): # Excludes PROJECT self._out.writeln(" Recipe: %s" % node.recipe) if isinstance(ref, ConanFileReference) and show("binary"): # Excludes PROJECT self._out.writeln(" Binary: %s" % node.binary) if isinstance(ref, ConanFileReference) and show("binary_remote"): # Excludes PROJECT self._out.writeln(" Binary remote: %s" % (node.binary_remote.name if node.binary_remote else "None")) if node_times and node_times.get(ref, None) and show("date"): self._out.writeln(" Creation date: %s" % node_times.get(ref, None), Color.BRIGHT_GREEN) dependants = [n for node in list_nodes for n in node.inverse_neighbors()] if isinstance(ref, ConanFileReference) and show("required"): # Excludes self._out.writeln(" Required by:", Color.BRIGHT_GREEN) for d in dependants: ref = d.conan_ref if d.conan_ref else str(d.conanfile) self._out.writeln(" %s" % str(ref), Color.BRIGHT_YELLOW) if show("requires"): depends = node.neighbors() requires = [d for d in depends if not d.build_require] build_requires = [d for d in depends if d.build_require] if requires: self._out.writeln(" Requires:", Color.BRIGHT_GREEN) for d in requires: self._out.writeln(" %s" % repr(d.conan_ref), Color.BRIGHT_YELLOW) if build_requires: self._out.writeln(" Build Requires:", Color.BRIGHT_GREEN) for d in build_requires: self._out.writeln(" %s" % repr(d.conan_ref), Color.BRIGHT_YELLOW)
def print_info(self, deps_graph, project_reference, _info, registry, graph_updates_info=None, remote=None, node_times=None, path_resolver=None, package_filter=None, show_paths=False): """ Print the dependency information for a conan file Attributes: deps_graph: the dependency graph of conan file references to print placeholder_reference: the conan file reference that represents the conan file for a project on the path. This may be None, in which case the project itself will not be part of the printed dependencies. remote: Remote specified in install command. Could be different from the registry one. """ if _info is None: # No filter def show(_): return True else: _info_lower = [s.lower() for s in _info] def show(field): return field in _info_lower graph_updates_info = graph_updates_info or {} for node in sorted(deps_graph.nodes): ref, conan = node.conan_ref, node.conanfile if not ref: # ref is only None iff info is being printed for a project directory, and # not a passed in reference if project_reference is None: continue else: ref = project_reference if package_filter and not fnmatch.fnmatch(str(ref), package_filter): continue self._out.writeln("%s" % str(ref), Color.BRIGHT_CYAN) reg_remote = registry.get_ref(ref) # Excludes PROJECT fake reference remote_name = remote if reg_remote and not remote: remote_name = reg_remote.name if show("id"): id_ = conan.info.package_id() self._out.writeln(" ID: %s" % id_, Color.BRIGHT_GREEN) if show("build_id"): bid = build_id(conan) self._out.writeln(" BuildID: %s" % bid, Color.BRIGHT_GREEN) if show_paths: self._print_paths(ref, conan, path_resolver, show) if isinstance(ref, ConanFileReference) and show("remote"): if reg_remote: self._out.writeln(" Remote: %s=%s" % (reg_remote.name, reg_remote.url), Color.BRIGHT_GREEN) else: self._out.writeln(" Remote: None", Color.BRIGHT_GREEN) url = getattr(conan, "url", None) license_ = getattr(conan, "license", None) author = getattr(conan, "author", None) if url and show("url"): self._out.writeln(" URL: %s" % url, Color.BRIGHT_GREEN) if license_ and show("license"): if isinstance(license_, (list, tuple, set)): self._out.writeln(" Licenses: %s" % ", ".join(license_), Color.BRIGHT_GREEN) else: self._out.writeln(" License: %s" % license_, Color.BRIGHT_GREEN) if author and show("author"): self._out.writeln(" Author: %s" % author, Color.BRIGHT_GREEN) if isinstance(ref, ConanFileReference) and show("update"): # Excludes PROJECT update = graph_updates_info.get(ref) update_messages = { None: ("Version not checked", Color.WHITE), 0: ("You have the latest version (%s)" % remote_name, Color.BRIGHT_GREEN), 1: ("There is a newer version (%s)" % remote_name, Color.BRIGHT_YELLOW), -1: ("The local file is newer than remote's one (%s)" % remote_name, Color.BRIGHT_RED) } self._out.writeln(" Updates: %s" % update_messages[update][0], update_messages[update][1]) if node_times and node_times.get(ref, None) and show("date"): self._out.writeln(" Creation date: %s" % node_times.get(ref, None), Color.BRIGHT_GREEN) dependants = node.inverse_neighbors() if isinstance(ref, ConanFileReference) and show("required"): # Excludes self._out.writeln(" Required by:", Color.BRIGHT_GREEN) for d in dependants: ref = d.conan_ref if d.conan_ref else project_reference self._out.writeln(" %s" % str(ref), Color.BRIGHT_YELLOW) if show("requires"): depends = node.neighbors() if depends: self._out.writeln(" Requires:", Color.BRIGHT_GREEN) for d in depends: self._out.writeln(" %s" % repr(d.conan_ref), Color.BRIGHT_YELLOW)