Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/pkg subgraph manifests #17166

Draft
wants to merge 2 commits into
base: develop2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions conans/client/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ def __init__(self, ref, conanfile, context, recipe=None, path=None, test=False):
self.is_conf = False
self.replaced_requires = {} # To track the replaced requires for self.dependencies[old-ref]

def subgraph(self):
nodes = [self]
opened = [self]
while opened:
new_opened = []
for o in opened:
for n in o.neighbors():
if n not in nodes:
nodes.append(n)
if n not in opened:
new_opened.append(n)
opened = new_opened

graph = DepsGraph()
graph.nodes = nodes
return graph

def __lt__(self, other):
"""
@type other: Node
Expand Down
4 changes: 4 additions & 0 deletions conans/model/conan_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def output(self):
def context(self):
return self._conan_node.context

@property
def subgraph(self):
return self._conan_node.subgraph()

@property
def dependencies(self):
# Caching it, this object is requested many times
Expand Down
41 changes: 41 additions & 0 deletions test/integration/graph/test_subgraph_reports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import json
import os
import textwrap

from conan.test.assets.genconanfile import GenConanfile
from conan.test.utils.tools import TestClient
from conans.util.files import load


def test_subgraph_reports():
c = TestClient()
subgraph_hook = textwrap.dedent("""\
import os, json
from conan.tools.files import save
from conans.model.graph_lock import Lockfile

def post_package(conanfile):
subgraph = conanfile.subgraph

save(conanfile, os.path.join(conanfile.package_folder, "conangraph.json"),
json.dumps(subgraph.serialize(), indent=2))
save(conanfile, os.path.join(conanfile.package_folder, "conan.lock"),
Lockfile(subgraph).dumps())
""")

c.save_home({"extensions/hooks/subgraph_hook/hook_subgraph.py": subgraph_hook})
c.save({"dep/conanfile.py": GenConanfile("dep", "0.1"),
"pkg/conanfile.py": GenConanfile("pkg", "0.1").with_requirement("dep/0.1"),
"app/conanfile.py": GenConanfile("app", "0.1").with_requirement("pkg/0.1")})
c.run("export dep")
c.run("export pkg")
c.run("create app --build=missing --format=json")

graph = json.loads(c.stdout)
folder = graph["graph"]["nodes"]["2"]["package_folder"]
graph = load(os.path.join(folder, "conangraph.json"))
print(graph)
lock = load(os.path.join(folder, "conan.lock"))
print(lock)

# Save it in metadata files? => extensible for future manifests