mirror of
https://github.com/ChristianLight/tutor.git
synced 2024-12-12 06:07:56 +00:00
Minor internal function renaming
This commit is contained in:
parent
9b10c1b470
commit
c1e47cec82
@ -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
|
||||
|
@ -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):
|
||||
|
16
tutor/env.py
16
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):
|
||||
|
@ -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():
|
||||
|
Loading…
Reference in New Issue
Block a user