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

fixing regression of graph_info not having root #4458

Merged
Merged
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
11 changes: 8 additions & 3 deletions conans/model/graph_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import os

from conans.client.profile_loader import _load_profile
from conans.errors import ConanException
from conans.model.options import OptionsValues
from conans.model.ref import ConanFileReference
from conans.tools import save
from conans.util.files import load
from conans.model.ref import ConanFileReference


GRAPH_INFO_FILE = "graph_info.json"
Expand All @@ -24,7 +25,11 @@ def load(path):
if not path:
raise IOError("Invalid path")
p = path if os.path.isfile(path) else os.path.join(path, GRAPH_INFO_FILE)
return GraphInfo.loads(load(p))
content = load(p)
try:
return GraphInfo.loads(content)
except Exception as e:
raise ConanException("Error parsing GraphInfo from file '{}': {}".format(p, e))

@staticmethod
def loads(text):
Expand All @@ -38,7 +43,7 @@ def loads(text):
options = None
else:
options = OptionsValues(options)
root = graph_json["root"]
root = graph_json.get("root", {"name": None, "version": None, "user": None, "channel": None})
root_ref = ConanFileReference(root["name"], root["version"], root["user"], root["channel"],
validate=False)
return GraphInfo(profile=profile, options=options, root_ref=root_ref)
Expand Down
18 changes: 18 additions & 0 deletions conans/test/functional/command/info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from conans.test.utils.cpp_test_files import cpp_hello_conan_files
from conans.test.utils.tools import TestClient
from conans.util.files import load, save
from conans.test.utils.conanfile import TestConanFile


class InfoTest(unittest.TestCase):
Expand Down Expand Up @@ -611,3 +612,20 @@ class MyTest(ConanFile):
html_content = load(html_path)
self.assertIn("<h3>Pkg/0.2@lasote/testing</h3>", html_content)
self.assertIn("<li><b>topics</b>: foo", html_content)

def wrong_graph_info_test(self):
# https://github.com/conan-io/conan/issues/4443
conanfile = TestConanFile()
client = TestClient()
client.save({"conanfile.py": str(conanfile)})
client.run("install .")
path = os.path.join(client.current_folder, "graph_info.json")
graph_info = load(path)
graph_info = json.loads(graph_info)
graph_info.pop("root")
save(path, json.dumps(graph_info))
client.run("info .")
self.assertIn("conanfile.py (Hello/0.1@None/None)", client.out)
save(path, "broken thing")
client.run("info .", assert_error=True)
self.assertIn("ERROR: Error parsing GraphInfo from file", client.out)