Mercurial > piecrust2
diff piecrust/serving/wrappers.py @ 666:81d9c3a3a0b5
internal: Get rid of the whole "sub cache" business.
* Compute cache keys up front, so the cache directory is only chosen once.
* Buffer up config variants to apply before loading the config. Makes it
possible to cache variant-resulting configs, too.
* Make a factory class to reuse the logic that creates the `PieCrust` object
correctly for multi-process workers and such.
* Add a test.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 03 Mar 2016 08:22:41 -0800 |
parents | 3ceeca7bb71c |
children | b91fe30ae7aa |
line wrap: on
line diff
--- a/piecrust/serving/wrappers.py Thu Mar 03 08:19:28 2016 -0800 +++ b/piecrust/serving/wrappers.py Thu Mar 03 08:22:41 2016 -0800 @@ -8,9 +8,7 @@ logger = logging.getLogger(__name__) -def run_werkzeug_server(root_dir, host, port, - debug_piecrust=False, theme_site=False, - sub_cache_dir=None, +def run_werkzeug_server(appfactory, host, port, use_debugger=False, use_reloader=False): from werkzeug.serving import run_simple @@ -24,10 +22,7 @@ return (not use_reloader or os.environ.get('WERKZEUG_RUN_MAIN') == 'true') - app = _get_piecrust_server(root_dir, - debug=debug_piecrust, - theme_site=theme_site, - sub_cache_dir=sub_cache_dir, + app = _get_piecrust_server(appfactory, run_sse_check=_run_sse_check) # We need to do a few things to get Werkzeug to properly shutdown or @@ -79,10 +74,7 @@ raise -def run_gunicorn_server(root_dir, - debug_piecrust=False, theme_site=False, - sub_cache_dir=None, - gunicorn_options=None): +def run_gunicorn_server(appfactory, gunicorn_options=None): from gunicorn.app.base import BaseApplication class PieCrustGunicornApplication(BaseApplication): @@ -99,28 +91,20 @@ def load(self): return self.app - app = _get_piecrust_server(root_dir, - debug=debug_piecrust, - theme_site=theme_site, - sub_cache_dir=sub_cache_dir) + app = _get_piecrust_server(appfactory) gunicorn_options = gunicorn_options or {} app_wrapper = PieCrustGunicornApplication(app, gunicorn_options) app_wrapper.run() -def _get_piecrust_server( - root_dir, debug=False, theme_site=False, - sub_cache_dir=None, run_sse_check=None): +def _get_piecrust_server(appfactory, run_sse_check=None): from piecrust.serving.middlewares import ( StaticResourcesMiddleware, PieCrustDebugMiddleware) from piecrust.serving.server import WsgiServer - app = WsgiServer(root_dir, debug=debug, theme_site=theme_site, - sub_cache_dir=sub_cache_dir) + app = WsgiServer(appfactory) app = StaticResourcesMiddleware(app) - app = PieCrustDebugMiddleware(app, root_dir, - theme_site=theme_site, - sub_cache_dir=sub_cache_dir, - run_sse_check=run_sse_check) + app = PieCrustDebugMiddleware( + app, appfactory, run_sse_check=run_sse_check) return app