forked from conan-io/conan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] User can override templates for table and graph (conan-io#7176
) * let the user override templates in '<cache>/templates' folder * value explicit * pass 'base_template_path' * test 'base_template_path' * expose raw data in graph * test documented fields of grapher * topics without quotes
- Loading branch information
Showing
10 changed files
with
166 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
import unittest | ||
|
||
from conans.assets.templates import SEARCH_TABLE_HTML, INFO_GRAPH_DOT, INFO_GRAPH_HTML | ||
from conans.client.tools import save | ||
from conans.model.ref import ConanFileReference | ||
from conans.test.utils.tools import TestClient, GenConanfile | ||
|
||
|
||
class UserOverridesTemplatesTestCase(unittest.TestCase): | ||
lib_ref = ConanFileReference.loads("lib/version") | ||
app_ref = ConanFileReference.loads("app/version") | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.t = TestClient() | ||
cls.t.save({'lib.py': GenConanfile().with_setting("os"), | ||
'app.py': GenConanfile().with_setting("os").with_require(cls.lib_ref)}) | ||
cls.t.run("create lib.py {}@ -s os=Windows".format(cls.lib_ref)) | ||
cls.t.run("create lib.py {}@ -s os=Linux".format(cls.lib_ref)) | ||
cls.t.run("create app.py {}@ -s os=Windows".format(cls.app_ref)) | ||
cls.t.run("create app.py {}@ -s os=Linux".format(cls.app_ref)) | ||
|
||
def test_table_html(self): | ||
table_template_path = os.path.join(self.t.cache_folder, 'templates', SEARCH_TABLE_HTML) | ||
save(table_template_path, content='{{ base_template_path }}') | ||
self.t.run("search {}@ --table=output.html".format(self.lib_ref)) | ||
content = self.t.load("output.html") | ||
self.assertEqual(os.path.join(self.t.cache_folder, 'templates', 'output'), content) | ||
|
||
def test_graph_html(self): | ||
table_template_path = os.path.join(self.t.cache_folder, 'templates', INFO_GRAPH_HTML) | ||
save(table_template_path, content='{{ base_template_path }}') | ||
self.t.run("info {}@ --graph=output.html".format(self.app_ref)) | ||
content = self.t.load("output.html") | ||
self.assertEqual(os.path.join(self.t.cache_folder, 'templates', 'output'), content) | ||
|
||
def test_graph_dot(self): | ||
table_template_path = os.path.join(self.t.cache_folder, 'templates', INFO_GRAPH_DOT) | ||
save(table_template_path, content='{{ base_template_path }}') | ||
self.t.run("info {}@ --graph=output.dot".format(self.app_ref)) | ||
content = self.t.load("output.dot") | ||
self.assertEqual(os.path.join(self.t.cache_folder, 'templates', 'output'), content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import textwrap | ||
|
||
from conans.client.graph.grapher import Grapher, Node | ||
from conans.model.profile import Profile | ||
from conans.test.functional.cross_building.graph._base_test_case import CrossBuildingBaseTestCase | ||
|
||
|
||
class GrapherTestCase(CrossBuildingBaseTestCase): | ||
""" Written on top of the cross-building tests, so I can get a more interesting graph that | ||
serves for the future when users start to need information related to cross-building | ||
scenarios. | ||
""" | ||
|
||
application = textwrap.dedent(""" | ||
from conans import ConanFile | ||
class Protoc(ConanFile): | ||
name = "application" | ||
version = "testing" | ||
url = "http://myurl.com" | ||
topics = "conan", "center" | ||
settings = "os" | ||
def requirements(self): | ||
self.requires("protobuf/testing@user/channel") | ||
def build_requirements(self): | ||
self.build_requires("protoc/testing@user/channel", force_host_context=False) | ||
# Make it explicit that these should be for host_machine | ||
self.build_requires("protoc/testing@user/channel", force_host_context=True) | ||
self.build_requires("gtest/testing@user/channel", force_host_context=True) | ||
""") | ||
|
||
def setUp(self): | ||
super(GrapherTestCase, self).setUp() | ||
self._cache_recipe(self.protobuf_ref, self.protobuf) | ||
self._cache_recipe(self.protoc_ref, self.protoc) | ||
self._cache_recipe(self.gtest_ref, self.gtest) | ||
self._cache_recipe(self.app_ref, self.application) | ||
|
||
profile_host = Profile() | ||
profile_host.settings["os"] = "Host" | ||
profile_host.process_settings(self.cache) | ||
|
||
profile_build = Profile() | ||
profile_build.settings["os"] = "Build" | ||
profile_build.process_settings(self.cache) | ||
|
||
deps_graph = self._build_graph(profile_host=profile_host, profile_build=profile_build) | ||
|
||
self.grapher = Grapher(deps_graph) | ||
|
||
def test_node_colors(self): | ||
# Every node gets one color | ||
for n in self.grapher.nodes: | ||
color = self.grapher.binary_color(node=n) | ||
self.assertIsInstance(color, str) | ||
|
||
def test_nodes(self): | ||
self.assertEqual(len(self.grapher.nodes), 7) | ||
sorted_nodes = sorted(list(self.grapher.nodes), key=lambda it: (it.label, it.package_id)) | ||
|
||
protobuf = sorted_nodes[4] | ||
self.assertEqual(protobuf.label, "protobuf/testing@user/channel") | ||
self.assertEqual(protobuf.short_label, "protobuf/testing") | ||
self.assertEqual(protobuf.package_id, "c31c69c9792316eb5e1a5641419abe169b44f775") | ||
self.assertEqual(protobuf.is_build_requires, True) | ||
self.assertEqual(protobuf.binary, "Build") | ||
self.assertDictEqual(protobuf.data(), {'author': None, 'build_id': None, 'homepage': None, | ||
'license': None, 'topics': None, 'url': None}) | ||
|
||
app = sorted_nodes[0] | ||
self.assertEqual(app.label, "app/testing@user/channel") | ||
self.assertEqual(app.short_label, "app/testing") | ||
self.assertEqual(app.package_id, "28220efa62679ebe67eb9e4792449f5e03ef9f8c") | ||
self.assertEqual(app.is_build_requires, False) | ||
self.assertEqual(app.binary, "Build") | ||
self.assertDictEqual(app.data(), {'author': None, 'build_id': None, 'homepage': None, | ||
'license': None, 'topics': ('conan', 'center'), | ||
'url': 'http://myurl.com'}) | ||
|
||
def test_edges(self): | ||
self.assertEqual(len(self.grapher.edges), 7) | ||
sorted_edges = sorted(list(self.grapher.edges), | ||
key=lambda it: (it[0].label, it[0].package_id, it[1].label)) | ||
|
||
app_node, gtest_node = sorted_edges[0] | ||
self.assertIsInstance(app_node, Node) | ||
self.assertIsInstance(gtest_node, Node) |