Skip to content

Commit

Permalink
Fix wsgi_ini_template creation when recipe is called multiple times i…
Browse files Browse the repository at this point in the history
…n buildout
  • Loading branch information
petschki committed Sep 20, 2024
1 parent a2cc527 commit 5baffe5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/plone/recipe/zope2instance/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ def __init__(self, buildout, name, options):
zope
""".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 @@ -924,13 +929,11 @@ def build_wsgi_ini(self):
"cannot be used together."
)

global wsgi_ini_template

# Load custom wsgi and logging template from file
if wsgi_ini_template_path:
try:
with open(wsgi_ini_template_path) as fp:
wsgi_ini_template = fp.read()
self._wsgi_ini_template = fp.read()
except OSError:
raise

Expand All @@ -939,22 +942,22 @@ def build_wsgi_ini(self):
try:
with open(wsgi_logging_ini_template_path) as fp:
# Add custom wsgi logging template to wsgi template
wsgi_ini_template += fp.read()
self._wsgi_ini_template += fp.read()
except OSError:
raise

# Load default global wsgi and logging template
else:
global wsgi_logging_ini_template
wsgi_ini_template += wsgi_logging_ini_template
self._wsgi_ini_template += wsgi_logging_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 = wsgi_ini_template % wsgi_options
wsgi_ini = self._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
6 changes: 6 additions & 0 deletions src/plone/recipe/zope2instance/tests/test_wsgi_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def test_wsgi_ini_template(self):
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
"""
TEMPLATE_CONTENT = """
[section]
Expand Down

0 comments on commit 5baffe5

Please sign in to comment.