diff --git a/tests/test_env.py b/tests/test_env.py index c884afa..fc8b9a5 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -105,7 +105,7 @@ class EnvTests(unittest.TestCase): # Create a single plugin with unittest.mock.patch.object( env.plugins, - "iter_templates", + "iter_template_roots", return_value=[("plugin1", plugin_templates)], ): with tempfile.TemporaryDirectory() as root: @@ -136,7 +136,7 @@ class EnvTests(unittest.TestCase): with unittest.mock.patch.object( env.plugins, - "iter_templates", + "iter_template_roots", return_value=[("myplugin", plugin_templates)], ): # Load env a second time diff --git a/tests/test_plugins.py b/tests/test_plugins.py index dffea63..ba1157f 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -179,7 +179,7 @@ class PluginsTests(unittest.TestCase): [("plugin1", ["myclient"])], list(plugins.iter_hooks({}, "init")) ) - def test_iter_templates(self): + def test_iter_template_roots(self): class plugin1: templates = "/tmp/templates" @@ -187,7 +187,7 @@ class PluginsTests(unittest.TestCase): plugins.Plugins, "iter_enabled", return_value=[("plugin1", plugin1)] ): self.assertEqual( - [("plugin1", "/tmp/templates")], list(plugins.iter_templates({})) + [("plugin1", "/tmp/templates")], list(plugins.iter_template_roots({})) ) def test_plugins_are_updated_on_config_change(self): diff --git a/tutor/env.py b/tutor/env.py index 2e1d436..1cc7c93 100644 --- a/tutor/env.py +++ b/tutor/env.py @@ -29,8 +29,8 @@ class Renderer: if cls.ENVIRONMENT_CONFIG != config: # Load template roots template_roots = [TEMPLATES_ROOT] - for _, plugin_templates in plugins.iter_templates(config): - template_roots.append(plugin_templates) + for _, plugin_template_root in plugins.iter_template_roots(config): + template_roots.append(plugin_template_root) # Create environment environment = jinja2.Environment( @@ -119,7 +119,7 @@ def render_full(root, config): """ for subdir in ["android", "apps", "build", "dev", "k8s", "local", "webui"]: save_subdir(subdir, root, config) - for plugin, path in plugins.iter_templates(config): + for plugin, path in plugins.iter_template_roots(config): save_plugin_templates(plugin, path, root, config) save_file(VERSION_FILENAME, root, config) save_file("kustomization.yml", root, config) @@ -277,12 +277,10 @@ def is_part_of_env(path): Determines whether a file should be rendered or not. """ basename = os.path.basename(path) - return not ( - basename.startswith(".") - or basename.endswith(".pyc") - or basename == "__pycache__" - or basename == "partials" - ) + is_excluded = False + is_excluded = is_excluded or basename.startswith(".") or basename.endswith(".pyc") + is_excluded = is_excluded or basename == "__pycache__" or basename == "partials" + return not is_excluded def template_path(*path): diff --git a/tutor/plugins.py b/tutor/plugins.py index 09d1c51..a428c7d 100644 --- a/tutor/plugins.py +++ b/tutor/plugins.py @@ -46,7 +46,7 @@ class Plugins: self.config = deepcopy(config) self.patches = {} self.hooks = {} - self.templates = {} + self.template_roots = {} for plugin_name, plugin in self.iter_enabled(): patches = get_callable_attr(plugin, "patches", {}) @@ -61,9 +61,9 @@ class Plugins: self.hooks[hook_name] = {} self.hooks[hook_name][plugin_name] = services - templates = get_callable_attr(plugin, "templates") - if templates: - self.templates[plugin_name] = templates + templates_root = get_callable_attr(plugin, "templates") + if templates_root: + self.template_roots[plugin_name] = templates_root @classmethod def clear(cls): @@ -102,8 +102,8 @@ class Plugins: def iter_hooks(self, hook_name): yield from self.hooks.get(hook_name, {}).items() - def iter_templates(self): - yield from self.templates.items() + def iter_template_roots(self): + yield from self.template_roots.items() def get_callable_attr(plugin, attr_name, default=None): @@ -154,8 +154,8 @@ def iter_hooks(config, hook_name): yield from Plugins.instance(config).iter_hooks(hook_name) -def iter_templates(config): - yield from Plugins.instance(config).iter_templates() +def iter_template_roots(config): + yield from Plugins.instance(config).iter_template_roots() def iter_commands():