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
|
# Create a single plugin
|
||||||
with unittest.mock.patch.object(
|
with unittest.mock.patch.object(
|
||||||
env.plugins,
|
env.plugins,
|
||||||
"iter_templates",
|
"iter_template_roots",
|
||||||
return_value=[("plugin1", plugin_templates)],
|
return_value=[("plugin1", plugin_templates)],
|
||||||
):
|
):
|
||||||
with tempfile.TemporaryDirectory() as root:
|
with tempfile.TemporaryDirectory() as root:
|
||||||
@ -136,7 +136,7 @@ class EnvTests(unittest.TestCase):
|
|||||||
|
|
||||||
with unittest.mock.patch.object(
|
with unittest.mock.patch.object(
|
||||||
env.plugins,
|
env.plugins,
|
||||||
"iter_templates",
|
"iter_template_roots",
|
||||||
return_value=[("myplugin", plugin_templates)],
|
return_value=[("myplugin", plugin_templates)],
|
||||||
):
|
):
|
||||||
# Load env a second time
|
# Load env a second time
|
||||||
|
@ -179,7 +179,7 @@ class PluginsTests(unittest.TestCase):
|
|||||||
[("plugin1", ["myclient"])], list(plugins.iter_hooks({}, "init"))
|
[("plugin1", ["myclient"])], list(plugins.iter_hooks({}, "init"))
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_iter_templates(self):
|
def test_iter_template_roots(self):
|
||||||
class plugin1:
|
class plugin1:
|
||||||
templates = "/tmp/templates"
|
templates = "/tmp/templates"
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ class PluginsTests(unittest.TestCase):
|
|||||||
plugins.Plugins, "iter_enabled", return_value=[("plugin1", plugin1)]
|
plugins.Plugins, "iter_enabled", return_value=[("plugin1", plugin1)]
|
||||||
):
|
):
|
||||||
self.assertEqual(
|
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):
|
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:
|
if cls.ENVIRONMENT_CONFIG != config:
|
||||||
# Load template roots
|
# Load template roots
|
||||||
template_roots = [TEMPLATES_ROOT]
|
template_roots = [TEMPLATES_ROOT]
|
||||||
for _, plugin_templates in plugins.iter_templates(config):
|
for _, plugin_template_root in plugins.iter_template_roots(config):
|
||||||
template_roots.append(plugin_templates)
|
template_roots.append(plugin_template_root)
|
||||||
|
|
||||||
# Create environment
|
# Create environment
|
||||||
environment = jinja2.Environment(
|
environment = jinja2.Environment(
|
||||||
@ -119,7 +119,7 @@ def render_full(root, config):
|
|||||||
"""
|
"""
|
||||||
for subdir in ["android", "apps", "build", "dev", "k8s", "local", "webui"]:
|
for subdir in ["android", "apps", "build", "dev", "k8s", "local", "webui"]:
|
||||||
save_subdir(subdir, root, config)
|
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_plugin_templates(plugin, path, root, config)
|
||||||
save_file(VERSION_FILENAME, root, config)
|
save_file(VERSION_FILENAME, root, config)
|
||||||
save_file("kustomization.yml", 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.
|
Determines whether a file should be rendered or not.
|
||||||
"""
|
"""
|
||||||
basename = os.path.basename(path)
|
basename = os.path.basename(path)
|
||||||
return not (
|
is_excluded = False
|
||||||
basename.startswith(".")
|
is_excluded = is_excluded or basename.startswith(".") or basename.endswith(".pyc")
|
||||||
or basename.endswith(".pyc")
|
is_excluded = is_excluded or basename == "__pycache__" or basename == "partials"
|
||||||
or basename == "__pycache__"
|
return not is_excluded
|
||||||
or basename == "partials"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def template_path(*path):
|
def template_path(*path):
|
||||||
|
@ -46,7 +46,7 @@ class Plugins:
|
|||||||
self.config = deepcopy(config)
|
self.config = deepcopy(config)
|
||||||
self.patches = {}
|
self.patches = {}
|
||||||
self.hooks = {}
|
self.hooks = {}
|
||||||
self.templates = {}
|
self.template_roots = {}
|
||||||
|
|
||||||
for plugin_name, plugin in self.iter_enabled():
|
for plugin_name, plugin in self.iter_enabled():
|
||||||
patches = get_callable_attr(plugin, "patches", {})
|
patches = get_callable_attr(plugin, "patches", {})
|
||||||
@ -61,9 +61,9 @@ class Plugins:
|
|||||||
self.hooks[hook_name] = {}
|
self.hooks[hook_name] = {}
|
||||||
self.hooks[hook_name][plugin_name] = services
|
self.hooks[hook_name][plugin_name] = services
|
||||||
|
|
||||||
templates = get_callable_attr(plugin, "templates")
|
templates_root = get_callable_attr(plugin, "templates")
|
||||||
if templates:
|
if templates_root:
|
||||||
self.templates[plugin_name] = templates
|
self.template_roots[plugin_name] = templates_root
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def clear(cls):
|
def clear(cls):
|
||||||
@ -102,8 +102,8 @@ class Plugins:
|
|||||||
def iter_hooks(self, hook_name):
|
def iter_hooks(self, hook_name):
|
||||||
yield from self.hooks.get(hook_name, {}).items()
|
yield from self.hooks.get(hook_name, {}).items()
|
||||||
|
|
||||||
def iter_templates(self):
|
def iter_template_roots(self):
|
||||||
yield from self.templates.items()
|
yield from self.template_roots.items()
|
||||||
|
|
||||||
|
|
||||||
def get_callable_attr(plugin, attr_name, default=None):
|
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)
|
yield from Plugins.instance(config).iter_hooks(hook_name)
|
||||||
|
|
||||||
|
|
||||||
def iter_templates(config):
|
def iter_template_roots(config):
|
||||||
yield from Plugins.instance(config).iter_templates()
|
yield from Plugins.instance(config).iter_template_roots()
|
||||||
|
|
||||||
|
|
||||||
def iter_commands():
|
def iter_commands():
|
||||||
|
Loading…
Reference in New Issue
Block a user