diff --git a/conans/client/conan_command_output.py b/conans/client/conan_command_output.py index 13a44533d71..aa3e69a6f48 100644 --- a/conans/client/conan_command_output.py +++ b/conans/client/conan_command_output.py @@ -139,6 +139,11 @@ def _grab_info_data(self, deps_graph, grab_paths): item_data["build_id"] = build_id(conanfile) item_data["context"] = conanfile.context + python_requires = getattr(conanfile, "python_requires", None) + if python_requires and not isinstance(python_requires, dict): # no old python requires + item_data["python_requires"] = [repr(r) + for r in conanfile.python_requires.all_refs()] + # Paths if isinstance(ref, ConanFileReference) and grab_paths: package_layout = self._cache.package_layout(ref, conanfile.short_paths) diff --git a/conans/client/printer.py b/conans/client/printer.py index af7e9f8509b..ce53de19e7b 100644 --- a/conans/client/printer.py +++ b/conans/client/printer.py @@ -124,6 +124,11 @@ def _print(it_field, show_field=None, name=None, color=Color.BRIGHT_GREEN): _print("scm", show_field="scm", name="scm") + if show("python_requires") and "python_requires" in it: + self._out.writeln(" Python-requires:", Color.BRIGHT_GREEN) + for d in it["python_requires"]: + self._out.writeln(" %s" % d, Color.BRIGHT_YELLOW) + if show("required") and "required_by" in it: self._out.writeln(" Required by:", Color.BRIGHT_GREEN) for d in it["required_by"]: diff --git a/conans/test/integration/command/info/info_test.py b/conans/test/integration/command/info/info_test.py index 380093b14c3..608fe9f1fea 100644 --- a/conans/test/integration/command/info/info_test.py +++ b/conans/test/integration/command/info/info_test.py @@ -697,3 +697,26 @@ def test_context_build(self): assert info[0]["context"] == "build" assert info[1]["reference"] == "pkg/1.0" assert info[1]["context"] == "host" + + +class TestInfoPythonRequires: + # https://github.com/conan-io/conan/issues/9277 + + def test_python_requires(self): + client = TestClient() + client.save({"conanfile.py": GenConanfile()}) + client.run("export . tool/0.1@") + conanfile = textwrap.dedent(""" + from conans import ConanFile + class Pkg(ConanFile): + python_requires = "tool/0.1" + """) + client.save({"conanfile.py": conanfile}) + + client.run("info .") + assert "Python-requires:" in client.out + assert "tool/0.1#f3367e0e7d170aa12abccb175fee5f97" in client.out + + client.run("info . --json=file.json") + info = json.loads(client.load("file.json")) + assert info[0]["python_requires"] == ['tool/0.1#f3367e0e7d170aa12abccb175fee5f97']