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

adding python-requires to info output #9290

Merged
merged 1 commit into from Jul 20, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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']