From f775ee71c52e8d5b364be24f3aaef62664d42aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Rinc=C3=B3n?= Date: Thu, 13 Apr 2023 18:41:07 +0200 Subject: [PATCH 1/4] Add info_invalid to graph node serialization --- conans/client/graph/graph.py | 1 + .../integration/command/info/info_test.py | 41 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/conans/client/graph/graph.py b/conans/client/graph/graph.py index ed381195abb..c03ed774736 100644 --- a/conans/client/graph/graph.py +++ b/conans/client/graph/graph.py @@ -219,6 +219,7 @@ def serialize(self): result["binary"] = self.binary # TODO: This doesn't match the model, check it result["invalid_build"] = self.cant_build + result["info_invalid"] = self.conanfile.info.invalid if self.conanfile.info is not None and self.conanfile.info.invalid is not None else False # Adding the conanfile information: settings, options, etc result.update(self.conanfile.serialize()) result["context"] = self.context diff --git a/conans/test/integration/command/info/info_test.py b/conans/test/integration/command/info/info_test.py index a2d127217ac..f9e56e0cbc5 100644 --- a/conans/test/integration/command/info/info_test.py +++ b/conans/test/integration/command/info/info_test.py @@ -97,8 +97,6 @@ class MyTest(ConanFile): assert recipe["provides"] == ["bar"] - - class TestConanfilePath: def test_cwd(self): # Check the first positional argument is a relative path @@ -356,6 +354,45 @@ def export(self): assert "ERROR: Package 'dep/0.1' not resolved: dep/0.1: Cannot load" in c.out assert exit_code == ERROR_GENERAL + def test_invalid_config_validate(self): + tc = TestClient() + conanfile = textwrap.dedent(""" + from conan import ConanFile + from conan.errors import ConanInvalidConfiguration + class Pkg(ConanFile): + name = "pkg" + version = "1.0" + options = {"myoption": [True, False]} + default_options = {"myoption": False} + def validate(self): + if self.options.myoption: + raise ConanInvalidConfiguration(f"{self.ref} does not support myoption=True")""") + + tc.save({"conanfile.py": conanfile}) + tc.run("graph info .") + assert "info_invalid: False" in tc.out + tc.run("graph info . -o 'pkg/1.0:myoption=True'") + assert "info_invalid: pkg/1.0 does not support myoption=True" in tc.out + + def test_invalid_bad_settings(self): + tc = TestClient() + conanfile = textwrap.dedent(""" + from conan import ConanFile + from conan.errors import ConanInvalidConfiguration + class Pkg(ConanFile): + name = "pkg" + version = "1.0" + options = {"myoption": [True, False]} + default_options = {"myoption": False} + + def package_id(self): + del self.info.options.myoption""") + + tc.save({"conanfile.py": conanfile}) + tc.run("graph info .") + assert "info_invalid: False" in tc.out + tc.run("graph info . -o 'pkg/1.0:myoption=True'") + assert "info_invalid: pkg/1.0 does not support myoption=True" in tc.out class TestInfoUpdate: From 0c780caff2909baec87f9157cd2f18985840e588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Rinc=C3=B3n?= Date: Thu, 13 Apr 2023 19:28:49 +0200 Subject: [PATCH 2/4] Add info_invalid to graph node serialization --- .../integration/command/info/info_test.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/conans/test/integration/command/info/info_test.py b/conans/test/integration/command/info/info_test.py index f9e56e0cbc5..7515fd0e95c 100644 --- a/conans/test/integration/command/info/info_test.py +++ b/conans/test/integration/command/info/info_test.py @@ -374,25 +374,6 @@ def validate(self): tc.run("graph info . -o 'pkg/1.0:myoption=True'") assert "info_invalid: pkg/1.0 does not support myoption=True" in tc.out - def test_invalid_bad_settings(self): - tc = TestClient() - conanfile = textwrap.dedent(""" - from conan import ConanFile - from conan.errors import ConanInvalidConfiguration - class Pkg(ConanFile): - name = "pkg" - version = "1.0" - options = {"myoption": [True, False]} - default_options = {"myoption": False} - - def package_id(self): - del self.info.options.myoption""") - - tc.save({"conanfile.py": conanfile}) - tc.run("graph info .") - assert "info_invalid: False" in tc.out - tc.run("graph info . -o 'pkg/1.0:myoption=True'") - assert "info_invalid: pkg/1.0 does not support myoption=True" in tc.out class TestInfoUpdate: From f075aa41b03f94ca5f4691ceffa4d4ba4012ffd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Rinc=C3=B3n?= Date: Thu, 13 Apr 2023 19:49:50 +0200 Subject: [PATCH 3/4] Address review comments --- .../integration/command/info/info_test.py | 20 ------------------- .../integration/package_id/test_validate.py | 2 ++ 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/conans/test/integration/command/info/info_test.py b/conans/test/integration/command/info/info_test.py index 7515fd0e95c..c99e733d57d 100644 --- a/conans/test/integration/command/info/info_test.py +++ b/conans/test/integration/command/info/info_test.py @@ -354,26 +354,6 @@ def export(self): assert "ERROR: Package 'dep/0.1' not resolved: dep/0.1: Cannot load" in c.out assert exit_code == ERROR_GENERAL - def test_invalid_config_validate(self): - tc = TestClient() - conanfile = textwrap.dedent(""" - from conan import ConanFile - from conan.errors import ConanInvalidConfiguration - class Pkg(ConanFile): - name = "pkg" - version = "1.0" - options = {"myoption": [True, False]} - default_options = {"myoption": False} - def validate(self): - if self.options.myoption: - raise ConanInvalidConfiguration(f"{self.ref} does not support myoption=True")""") - - tc.save({"conanfile.py": conanfile}) - tc.run("graph info .") - assert "info_invalid: False" in tc.out - tc.run("graph info . -o 'pkg/1.0:myoption=True'") - assert "info_invalid: pkg/1.0 does not support myoption=True" in tc.out - class TestInfoUpdate: diff --git a/conans/test/integration/package_id/test_validate.py b/conans/test/integration/package_id/test_validate.py index 5bed903d277..7c7afa9feab 100644 --- a/conans/test/integration/package_id/test_validate.py +++ b/conans/test/integration/package_id/test_validate.py @@ -40,10 +40,12 @@ def validate(self): client.run("graph info --require pkg/0.1 -s os=Windows") self.assertIn("binary: Invalid", client.out) + assert "info_invalid: Windows not supported" in client.out client.run("graph info --require pkg/0.1 -s os=Windows --format json") myjson = json.loads(client.stdout) self.assertEqual(myjson["nodes"][1]["binary"], BINARY_INVALID) + assert myjson["nodes"][1]["info_invalid"] == "Windows not supported" in client.out def test_validate_header_only(self): client = TestClient() From a7cc65445abeab5d74a7a0751ba4f00372134175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Rinc=C3=B3n?= Date: Thu, 13 Apr 2023 19:57:35 +0200 Subject: [PATCH 4/4] Address review comments x2 --- conans/client/graph/graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conans/client/graph/graph.py b/conans/client/graph/graph.py index c03ed774736..cc1e12b8aa0 100644 --- a/conans/client/graph/graph.py +++ b/conans/client/graph/graph.py @@ -219,7 +219,7 @@ def serialize(self): result["binary"] = self.binary # TODO: This doesn't match the model, check it result["invalid_build"] = self.cant_build - result["info_invalid"] = self.conanfile.info.invalid if self.conanfile.info is not None and self.conanfile.info.invalid is not None else False + result["info_invalid"] = getattr(getattr(self.conanfile, "info", None), "invalid", None) # Adding the conanfile information: settings, options, etc result.update(self.conanfile.serialize()) result["context"] = self.context