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

Fix serialization of tool_requires in conan profile show --format=json #15185

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
6 changes: 4 additions & 2 deletions conans/model/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ def __repr__(self):
return self.dumps()

def serialize(self):
# TODO: Remove it seems dead
def _serialize_tool_requires():
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
return {pattern: [repr(ref) for ref in refs]
for pattern, refs in self.tool_requires.items()}
return {
"settings": self.settings,
"package_settings": self.package_settings,
"options": self.options.serialize(),
"tool_requires": self.tool_requires,
"tool_requires": _serialize_tool_requires(),
"conf": self.conf.serialize(),
# FIXME: Perform a serialize method for ProfileEnvironment
"build_env": self.buildenv.dumps()
Expand Down
8 changes: 6 additions & 2 deletions conans/test/integration/command/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,13 @@ def test_shorthand_syntax():

def test_profile_show_json():
c = TestClient()
c.save({"myprofilewin": "[settings]\nos=Windows",
c.save({"myprofilewin": "[settings]\nos=Windows\n[tool_requires]\nmytool/*:mytool/1.0",
"myprofilelinux": "[settings]\nos=Linux"})
c.run("profile show -pr:b=myprofilewin -pr:h=myprofilelinux --format=json")
profile = json.loads(c.stdout)
assert profile["build"]["settings"] == {"os": "Windows"}
assert profile["host"]["settings"] == {"os": "Linux"}

assert profile["build"]["settings"] == {"os": "Windows"}
# Check that tool_requires are properly serialized in json format
# https://github.com/conan-io/conan/issues/15183
assert profile["build"]["tool_requires"] == {'mytool/*': ["mytool/1.0"]}
11 changes: 6 additions & 5 deletions conans/test/unittests/model/profile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ def test_profile_serialize():
profile.settings["compiler.version"] = "12"
profile.tool_requires["*"] = ["zlib/1.2.8"]
profile.update_package_settings({"MyPackage": [("os", "Windows")]})
expected_json = '{"settings": {"arch": "x86_64", "compiler": "Visual Studio", "compiler.version": "12"}, ' \
'"package_settings": {"MyPackage": {"os": "Windows"}}, ' \
'"options": {}, "tool_requires": {"*": ["zlib/1.2.8"]}, ' \
'"conf": {"user.myfield:value": "MyVal"}, "build_env": "VAR1=1\\nVAR2=2\\n"}'
assert expected_json == json.dumps(profile.serialize())
expected_json = {
"settings": {"arch": "x86_64", "compiler": "Visual Studio", "compiler.version": "12"},
"package_settings": {"MyPackage": {"os": "Windows"}}, "options": {},
"tool_requires": {"*": ["'zlib/1.2.8'"]}, "conf": {"user.myfield:value": "MyVal"},
"build_env": "VAR1=1\nVAR2=2\n"}
assert expected_json == profile.serialize()