diff piecrust/commands/builtin/serving.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 4850f8c21b6e
line wrap: on
line diff
--- a/piecrust/commands/builtin/serving.py	Thu Mar 03 08:19:28 2016 -0800
+++ b/piecrust/commands/builtin/serving.py	Thu Mar 03 08:22:41 2016 -0800
@@ -42,12 +42,19 @@
         port = int(ctx.args.port)
         debug = ctx.args.debug or ctx.args.use_debugger
 
+        from piecrust.app import PieCrustFactory
+        appfactory = PieCrustFactory(
+                ctx.app.root_dir,
+                cache=ctx.app.cache.enabled,
+                cache_key=ctx.app.cache_key,
+                config_variant=ctx.config_variant,
+                config_values=ctx.config_values,
+                debug=ctx.app.debug,
+                theme_site=ctx.app.theme_site)
+
         if ctx.args.wsgi == 'werkzeug':
             run_werkzeug_server(
-                    root_dir, host, port,
-                    debug_piecrust=debug,
-                    theme_site=ctx.args.theme,
-                    sub_cache_dir=ctx.app.sub_cache_dir,
+                    appfactory, host, port,
                     use_debugger=debug,
                     use_reloader=ctx.args.use_reloader)
 
@@ -60,10 +67,5 @@
                 options['loglevel'] = 'debug'
             if ctx.args.use_reloader:
                 options['reload'] = True
-            run_gunicorn_server(
-                    root_dir,
-                    debug_piecrust=debug,
-                    theme_site=ctx.args.theme,
-                    sub_cache_dir=ctx.app.sub_cache_dir,
-                    gunicorn_options=options)
+            run_gunicorn_server(appfactory, gunicorn_options=options)