From d4400ce58f9bbe712651afc44721a74cfdcca000 Mon Sep 17 00:00:00 2001 From: Carlos Zoido Date: Thu, 16 Feb 2023 10:23:22 +0100 Subject: [PATCH] Add basic html output to conan list (#13135) * add simple html * fix message * review * fix test * fix test --- conan/cli/formatters/list/list.py | 3 +- .../cli/formatters/list/search_table_html.py | 73 ++++++------------- conans/client/graph/install_graph.py | 12 +-- conans/test/functional/only_source_test.py | 6 +- .../install/install_missing_dep_test.py | 2 +- 5 files changed, 34 insertions(+), 62 deletions(-) diff --git a/conan/cli/formatters/list/list.py b/conan/cli/formatters/list/list.py index dc2c5cb1b46..feeb5a2fb0e 100644 --- a/conan/cli/formatters/list/list.py +++ b/conan/cli/formatters/list/list.py @@ -1,3 +1,4 @@ +import json import os from jinja2 import Template, select_autoescape @@ -15,6 +16,6 @@ def list_packages_html(result): user_template = os.path.join(template_folder, "list_packages.html") template = load(user_template) if os.path.isfile(user_template) else list_packages_html_template template = Template(template, autoescape=select_autoescape(['html', 'xml'])) - content = template.render(results=results, base_template_path=template_folder, + content = template.render(results=json.dumps(results), base_template_path=template_folder, version=client_version) cli_out_write(content) diff --git a/conan/cli/formatters/list/search_table_html.py b/conan/cli/formatters/list/search_table_html.py index 342fe760cc4..dfea0b9e764 100644 --- a/conan/cli/formatters/list/search_table_html.py +++ b/conan/cli/formatters/list/search_table_html.py @@ -1,57 +1,28 @@ list_packages_html_template = r""" - - Conan | {{ reference }} - - - - - -
-

{{ reference }}

-
-

- Depending on your package_id_mode, any combination of settings, options and requirements - can give you a different packageID. Take into account that your configuration might be - different from the one used to generate the packages. -

-
+ + conan list results + + - - - - - - - - - - - -
- - - - - - -
- - + +

+  
+  
 
 """
diff --git a/conans/client/graph/install_graph.py b/conans/client/graph/install_graph.py
index 1eaa46972c4..11ec1773ab9 100644
--- a/conans/client/graph/install_graph.py
+++ b/conans/client/graph/install_graph.py
@@ -285,10 +285,10 @@ def _raise_missing(missing):
         else:
             build_str = " ".join(list(sorted(["--build=%s" % str(pref.ref) for pref in missing_prefs])))
 
-        raise ConanException(textwrap.dedent('''\
-           Missing prebuilt package for '%s'
-           Use 'conan list packages %s --format=html -r=remote > table.html' and open the table.html file to see available packages
-           Or try to build locally from sources with '%s'
+        raise ConanException(textwrap.dedent(f'''\
+           Missing prebuilt package for '{missing_pkgs}'
+           Check the available packages using 'conan list {ref}:* -r=remote'
+           or try to build locally from sources using the '{build_str}' argument
 
-           More Info at 'https://docs.conan.io/en/latest/faq/troubleshooting.html#error-missing-prebuilt-package'
-           ''' % (missing_pkgs, ref, build_str)))
+           More Info at 'https://docs.conan.io/en/2/knowledge/faq.html#error-missing-prebuilt-package'
+           '''))
diff --git a/conans/test/functional/only_source_test.py b/conans/test/functional/only_source_test.py
index 2e4baf670d6..658cfd25865 100644
--- a/conans/test/functional/only_source_test.py
+++ b/conans/test/functional/only_source_test.py
@@ -26,18 +26,18 @@ def test_conan_test(self):
         # Will Fail because hello0/0.0 and hello1/1.1 has not built packages
         # and by default no packages are built
         client.run("create . --user=lasote --channel=stable", assert_error=True)
-        self.assertIn("Or try to build locally from sources with '--build=hello0/0.0@lasote/stable "
+        self.assertIn("or try to build locally from sources using the '--build=hello0/0.0@lasote/stable "
                       "--build=hello1/1.1@lasote/stable'",
                       client.out)
         # Only 1 reference!
-        assert "Use 'conan list packages hello0/0.0@lasote/stable" in client.out
+        assert "Check the available packages using 'conan list hello0/0.0@lasote/stable:* -r=remote'" in client.out
 
         # We generate the package for hello0/0.0
         client.run("install --requires=hello0/0.0@lasote/stable --build hello0*")
 
         # Still missing hello1/1.1
         client.run("create . --user=lasote --channel=stable", assert_error=True)
-        self.assertIn("Or try to build locally from sources with "
+        self.assertIn("or try to build locally from sources using the "
                       "'--build=hello1/1.1@lasote/stable'", client.out)
 
         # We generate the package for hello1/1.1
diff --git a/conans/test/integration/command/install/install_missing_dep_test.py b/conans/test/integration/command/install/install_missing_dep_test.py
index 47455336e34..27725c71281 100644
--- a/conans/test/integration/command/install/install_missing_dep_test.py
+++ b/conans/test/integration/command/install/install_missing_dep_test.py
@@ -50,4 +50,4 @@ def test_missing_multiple_dep(self):
         client.save({"conanfile.py": conanfile}, clean_first=True)
         client.run("create . --name=pkg --version=1.0", assert_error=True)
         self.assertIn("ERROR: Missing prebuilt package for 'dep1/1.0', 'dep2/1.0'", client.out)
-        self.assertIn("Or try to build locally from sources with '--build=dep1/1.0 --build=dep2/1.0'", client.out)
+        self.assertIn("or try to build locally from sources using the '--build=dep1/1.0 --build=dep2/1.0'", client.out)