Skip to content

Commit

Permalink
adding python-requires to info output (#9290)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded committed Jul 20, 2021
1 parent 51b6675 commit 0e22f9e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions conans/client/conan_command_output.py
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions conans/client/printer.py
Expand Up @@ -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"]:
Expand Down
23 changes: 23 additions & 0 deletions conans/test/integration/command/info/info_test.py
Expand Up @@ -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']

0 comments on commit 0e22f9e

Please sign in to comment.