diff --git a/tests/test_env.py b/tests/test_env.py index cd52abc..0542d19 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -123,3 +123,14 @@ class EnvTests(unittest.TestCase): self.assertTrue(os.path.exists(dst_rendered)) with open(dst_rendered) as f: self.assertEqual("Hello my ID is abcd", f.read()) + + def test_renderer_is_reset_on_config_change(self): + config = {"PLUGINS": []} + env1 = env.Renderer.environment(config) + config["PLUGINS"].append("minio") + env2 = env.Renderer.environment(config) + + self.assertNotIn( + "minio/hooks/mino-client/pre-init", env1.loader.list_templates() + ) + self.assertIn("minio/hooks/minio-client/pre-init", env2.loader.list_templates()) diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 97766fe..7940551 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -189,3 +189,11 @@ class PluginsTests(unittest.TestCase): self.assertEqual( [("plugin1", "/tmp/templates")], list(plugins.iter_templates({})) ) + + def test_plugins_are_updated_on_config_change(self): + config = {"PLUGINS": []} + instance1 = plugins.Plugins(config) + self.assertEqual(0, len(list(instance1.iter_enabled()))) + config["PLUGINS"].append("minio") + instance2 = plugins.Plugins(config) + self.assertEqual(1, len(list(instance2.iter_enabled()))) diff --git a/tutor/env.py b/tutor/env.py index 9cb2ed7..bc47131 100644 --- a/tutor/env.py +++ b/tutor/env.py @@ -1,4 +1,5 @@ import codecs +from copy import deepcopy import os import shutil @@ -22,7 +23,6 @@ class Renderer: @classmethod def environment(cls, config): if cls.ENVIRONMENT_CONFIG != config: - cls.ENVIRONMENT_CONFIG = config template_roots = [TEMPLATES_ROOT] for _, plugin_templates in plugins.iter_templates(config): template_roots.append(plugin_templates) @@ -35,6 +35,8 @@ class Renderer: environment.filters["reverse_host"] = utils.reverse_host environment.filters["walk_templates"] = walk_templates environment.globals["TUTOR_VERSION"] = __version__ + + cls.ENVIRONMENT_CONFIG = deepcopy(config) cls.ENVIRONMENT = environment return cls.ENVIRONMENT @@ -42,6 +44,7 @@ class Renderer: @classmethod def reset(cls): cls.ENVIRONMENT = None + cls.ENVIRONMENT_CONFIG = None @classmethod def render_str(cls, config, text): diff --git a/tutor/plugins.py b/tutor/plugins.py index 532215e..0448b07 100644 --- a/tutor/plugins.py +++ b/tutor/plugins.py @@ -1,3 +1,4 @@ +from copy import deepcopy import pkg_resources from . import exceptions @@ -42,7 +43,7 @@ class Plugins: EXTRA_INSTALLED = {} def __init__(self, config): - self.config = config + self.config = deepcopy(config) self.patches = {} self.hooks = {} self.templates = {}