diff --git a/news/198.bugfix b/news/198.bugfix new file mode 100644 index 0000000..757584c --- /dev/null +++ b/news/198.bugfix @@ -0,0 +1,2 @@ +Installing the recipe twice should not break; remove use of `global` +[gotcha] diff --git a/src/plone/recipe/zope2instance/recipe.py b/src/plone/recipe/zope2instance/recipe.py index 7db1a04..915a26c 100644 --- a/src/plone/recipe/zope2instance/recipe.py +++ b/src/plone/recipe/zope2instance/recipe.py @@ -117,10 +117,6 @@ def __init__(self, buildout, name, options): """.strip() ) - # instantinate base wsgi_ini_template - global wsgi_ini_template - self._wsgi_ini_template = wsgi_ini_template - # Get Scripts' attributes return Scripts.__init__(self, buildout, name, options) @@ -929,27 +925,31 @@ def build_wsgi_ini(self): "cannot be used together." ) - # Load custom wsgi and logging template from file + # Load custom wsgi template from file if wsgi_ini_template_path: try: with open(wsgi_ini_template_path) as fp: - self._wsgi_ini_template = fp.read() + wsgi_ini_template = fp.read() except OSError: raise - # Load default global wsgi template and load custom wsgi logging template + # Load default wsgi template and load custom wsgi logging template elif wsgi_logging_ini_template_path: + wsgi_ini_template = default_wsgi_ini_template try: with open(wsgi_logging_ini_template_path) as fp: # Add custom wsgi logging template to wsgi template - self._wsgi_ini_template += fp.read() + wsgi_ini_template += fp.read() except OSError: raise - # Load default global wsgi and logging template + # Load default wsgi and logging templates else: - global wsgi_logging_ini_template - self._wsgi_ini_template += wsgi_logging_ini_template + wsgi_ini_template = ( + default_wsgi_ini_template + default_wsgi_logging_ini_template + ) + + assert wsgi_ini_template # generate a different [server:main] - useful for Windows wsgi_server_main_template = wsgi_server_main_templates.get( @@ -957,7 +957,7 @@ def build_wsgi_ini(self): ) wsgi_options["server_main"] = wsgi_server_main_template % wsgi_options - wsgi_ini = self._wsgi_ini_template % wsgi_options + wsgi_ini = wsgi_ini_template % wsgi_options # Catch errors in generated wsgi.ini by parsing it before writing the file configparser.ConfigParser().read_string(wsgi_ini) @@ -1504,7 +1504,7 @@ def render_file_storage(self, file_storage, blob_storage, base_dir, var_dir, zli max_request_body_size = %(max_request_body_size)s """ -wsgi_ini_template = """\ +default_wsgi_ini_template = """\ [server:main] %(server_main)s @@ -1539,7 +1539,7 @@ def render_file_storage(self, file_storage, blob_storage, base_dir, var_dir, zli """ -wsgi_logging_ini_template = """\ +default_wsgi_logging_ini_template = """\ [loggers] keys = root, plone, waitress.queue, waitress, wsgi diff --git a/src/plone/recipe/zope2instance/tests/test_wsgi_template.py b/src/plone/recipe/zope2instance/tests/test_wsgi_template.py index 425fa32..33ea741 100644 --- a/src/plone/recipe/zope2instance/tests/test_wsgi_template.py +++ b/src/plone/recipe/zope2instance/tests/test_wsgi_template.py @@ -24,23 +24,37 @@ def tearDown(self): sample_buildout = self.globs["sample_buildout"] shutil.rmtree(sample_buildout, ignore_errors=True) - def test_wsgi_ini_template(self): + def test_two_instances(self): BUILDOUT_CONTENT = """ [buildout] -parts = instance +parts = instance instance2 find-links = %(sample_buildout)s/eggs [instance] recipe = plone.recipe.zope2instance eggs = user = me:me -wsgi-ini-template = %(sample_buildout)s/wsgi_tmpl.ini [instance2] -# check multiple recipe call recipe = plone.recipe.zope2instance eggs = user = me:me +""" + buildout_testing.write("buildout.cfg", BUILDOUT_CONTENT % self.globs) + output = buildout_testing.system(join("bin", "buildout"), with_exit_code=True) + self.assertTrue("EXIT CODE: 0" in output, output) + + def test_wsgi_ini_template(self): + BUILDOUT_CONTENT = """ +[buildout] +parts = instance +find-links = %(sample_buildout)s/eggs + +[instance] +recipe = plone.recipe.zope2instance +eggs = +user = me:me +wsgi-ini-template = %(sample_buildout)s/wsgi_tmpl.ini """ TEMPLATE_CONTENT = """ [section]