Repository: conan-io/conan

Issue:
[feature] exclude some deps from conan dependency graph 
Conan dependency graph is a very useful feature but it become very difficult to use when having too many dependencies.  

This is how our current dependency graph looks like, it is almost unreadable and we are adding more dependencies. 

<img width="721" alt="Screen Shot 2021-07-21 at 2 30 38 PM" src="https://user-images.githubusercontent.com/7117696/126497056-6a7695f8-c58b-44c7-b076-1e7ca5c58d59.png">

It would be very handy to add the ability to exclude some dependencies from this graph. For example excluding third party deps that rarely get changed.



Discussion:
Hi @boussaffawalid 

I think the best approach for this at the moment would be to customize the html/javascript template that is used to generate this graph, not to do it from the Conan client side: https://docs.conan.io/en/latest/extending/template_system/info_graph.html

I understand this would be a nice to have, but at the moment this wouldn't be a priority. If someone is willing to contribute an improved html/js template for the graph, with more powerful features, like hiding/showing packages, etc., it will be very welcome.
@memsharded it seems that info_graph.html does the trick! Thanks!. I will try to contribute to the html/js template.

Hello, me and my UMICH group want to contribute to this issue! I assume this is still available since it has the appropriate milestone mark. Do you happen to have any suggestions on how to start tackling this issue? Thank you!
The html graph got a very major update very recently in https://github.com/conan-io/conan/pull/15846

I think that PR would alleviate most of the problems referenced in this ticket., but the "filtering" one is not.
I suggest adding another textbox that accepts a comma separated list of patters of packages to hide.
If we want to make the functionality equivalent in the search box, it could be done the same, and extend the search to a comma separated list of patterns.
> The html graph got a very major update very recently in #15846
> 
> I think that PR would alleviate most of the problems referenced in this ticket., but the "filtering" one is not. I suggest adding another textbox that accepts a comma separated list of patters of packages to hide. If we want to make the functionality equivalent in the search box, it could be done the same, and extend the search to a comma separated list of patterns.

Thank you! We will move forward with that implementation in mind. 

Resolving patch:
diff --git a/conan/cli/formatters/graph/info_graph_html.py b/conan/cli/formatters/graph/info_graph_html.py
--- a/conan/cli/formatters/graph/info_graph_html.py
+++ b/conan/cli/formatters/graph/info_graph_html.py
@@ -44,7 +44,10 @@
                     <label for="show_package_type">Show package type</label>
                 </div>
                  <div>
-                    <input type="search" placeholder="Search package..." oninput="searchPackage(this)">
+                    <input type="search" placeholder="Search packages..." oninput="searchPackages(this)">
+                </div>
+                 <div>
+                    <input type="search" placeholder="Exclude packages..." title="Add a comma to exclude an additional package" oninput="excludePackages(this)">
                 </div>
                 <div>
                     <input type="checkbox" onchange="showhideclass('controls')" id="show_controls"/>
@@ -60,7 +63,8 @@
             const graph_data = {{ deps_graph | tojson }};
             let hide_build = false;
             let hide_test = false;
-            let search_pkg = null;
+            let search_pkgs = null;
+            let excluded_pkgs = null;
             let collapse_packages = false;
             let show_package_type = false;
             let color_map = {Cache: "SkyBlue",
@@ -101,6 +105,15 @@
                         if (existing) continue;
                         collapsed_packages[label] = node_id;
                     }
+                    if (excluded_pkgs) {
+                        let patterns = excluded_pkgs.split(',')
+                            .map(pattern => pattern.trim())
+                            .filter(pattern => pattern.length > 0)
+                            .map(pattern => pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
+                        if (patterns.some(pattern => label.match(pattern))) {
+                            continue;
+                        }
+                    }
                     if (show_package_type) {
                          label = "<b>" + label + "\n" + "<i>" + node.package_type + "</i>";
                     }
@@ -114,9 +127,15 @@
                         color = "Black";
                         shape = "circle";
                     }
-                    if (search_pkg && label.match(search_pkg)) {
-                        borderWidth = 3;
-                        borderColor = "Magenta";
+                    if (search_pkgs) {
+                        let patterns = search_pkgs.split(',')
+                            .map(pattern => pattern.trim())
+                            .filter(pattern => pattern.length > 0)
+                            .map(pattern => pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));
+                        if (patterns.some(pattern => label.match(pattern))) {
+                            borderWidth = 3;
+                            borderColor = "Magenta";
+                        }
                     }
                     if (node.test) {
                         font.background = "lightgrey";
@@ -293,8 +312,12 @@
                 collapse_packages = !collapse_packages;
                 draw();
             }
-            function searchPackage(e) {
-                search_pkg = e.value;
+            function searchPackages(e) {
+                search_pkgs = e.value;
+                draw();
+            }
+            function excludePackages(e) {
+                excluded_pkgs = e.value;
                 draw();
             }
             function showPackageType(e) {


Test patch: