Skip to content

Commit

Permalink
Installing the recipe twice should not break
Browse files Browse the repository at this point in the history
Remove use of `global`
  • Loading branch information
gotcha committed Sep 23, 2024
1 parent 6acf6f0 commit 924eeeb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
2 changes: 2 additions & 0 deletions news/198.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Installing the recipe twice should not break; remove use of `global`
[gotcha]
28 changes: 14 additions & 14 deletions src/plone/recipe/zope2instance/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -929,35 +925,39 @@ 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(
sys.platform, wsgi_server_main_templates["default"]
)
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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 18 additions & 4 deletions src/plone/recipe/zope2instance/tests/test_wsgi_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 924eeeb

Please sign in to comment.