Mercurial > piecrust2
diff piecrust/main.py @ 371:c2ca72fb7f0b 2.0.0a8
caching: Use separate caches for config variants and other contexts.
* The `_cache` directory is now organized in multiple "sub-caches" for
different contexts.
* A new context is created when config variants or overrides are applied.
* `serve` context uses a different context that the other commends, to prevent
the `bake` command's output from messing up the preview server (e.g. with
how asset URLs are generated differently between the two).
* Fix a few places where the cache directory was referenced directly.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 03 May 2015 23:59:46 -0700 |
parents | d8677ad748f0 |
children | d241585412ad |
line wrap: on
line diff
--- a/piecrust/main.py Sun May 03 23:45:32 2015 -0700 +++ b/piecrust/main.py Sun May 03 23:59:46 2015 -0700 @@ -181,14 +181,19 @@ else: app = PieCrust(root, cache=pre_args.cache, debug=pre_args.debug) + # Build a hash for a custom cache directory. + cache_key = 'default' + # Handle a configuration variant. if pre_args.config_variant is not None: if not root: raise SiteNotFoundError("Can't apply any variant.") app.config.applyVariant('variants/' + pre_args.config_variant) + cache_key += ',variant=%s' % pre_args.config_variant for name, value in pre_args.config_values: logger.debug("Setting configuration '%s' to: %s" % (name, value)) app.config.set(name, value) + cache_key += ',%s=%s' % (name, value) # Setup the arg parser. parser = argparse.ArgumentParser( @@ -234,6 +239,7 @@ p = subparsers.add_parser(c.name, help=c.description) c.setupParser(p, app) p.set_defaults(func=c.checkedRun) + p.set_defaults(cache_name=c.cache_name) help_cmd = next(filter(lambda c: c.name == 'help', commands), None) if help_cmd and help_cmd.has_topics: @@ -253,6 +259,10 @@ parser.print_help() return 0 + # Use a customized cache for the command and current config. + if result.cache_name != 'default' or cache_key != 'default': + app.useSubCache(result.cache_name, cache_key) + # Run the command! ctx = CommandContext(app, parser, result) exit_code = result.func(ctx)