Mercurial > piecrust2
comparison 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 |
comparison
equal
deleted
inserted
replaced
370:a1bbe66cba03 | 371:c2ca72fb7f0b |
---|---|
179 if not root: | 179 if not root: |
180 app = NullPieCrust() | 180 app = NullPieCrust() |
181 else: | 181 else: |
182 app = PieCrust(root, cache=pre_args.cache, debug=pre_args.debug) | 182 app = PieCrust(root, cache=pre_args.cache, debug=pre_args.debug) |
183 | 183 |
184 # Build a hash for a custom cache directory. | |
185 cache_key = 'default' | |
186 | |
184 # Handle a configuration variant. | 187 # Handle a configuration variant. |
185 if pre_args.config_variant is not None: | 188 if pre_args.config_variant is not None: |
186 if not root: | 189 if not root: |
187 raise SiteNotFoundError("Can't apply any variant.") | 190 raise SiteNotFoundError("Can't apply any variant.") |
188 app.config.applyVariant('variants/' + pre_args.config_variant) | 191 app.config.applyVariant('variants/' + pre_args.config_variant) |
192 cache_key += ',variant=%s' % pre_args.config_variant | |
189 for name, value in pre_args.config_values: | 193 for name, value in pre_args.config_values: |
190 logger.debug("Setting configuration '%s' to: %s" % (name, value)) | 194 logger.debug("Setting configuration '%s' to: %s" % (name, value)) |
191 app.config.set(name, value) | 195 app.config.set(name, value) |
196 cache_key += ',%s=%s' % (name, value) | |
192 | 197 |
193 # Setup the arg parser. | 198 # Setup the arg parser. |
194 parser = argparse.ArgumentParser( | 199 parser = argparse.ArgumentParser( |
195 prog='chef', | 200 prog='chef', |
196 description="The PieCrust chef manages your website.", | 201 description="The PieCrust chef manages your website.", |
232 subparsers = parser.add_subparsers(title='list of commands') | 237 subparsers = parser.add_subparsers(title='list of commands') |
233 for c in commands: | 238 for c in commands: |
234 p = subparsers.add_parser(c.name, help=c.description) | 239 p = subparsers.add_parser(c.name, help=c.description) |
235 c.setupParser(p, app) | 240 c.setupParser(p, app) |
236 p.set_defaults(func=c.checkedRun) | 241 p.set_defaults(func=c.checkedRun) |
242 p.set_defaults(cache_name=c.cache_name) | |
237 | 243 |
238 help_cmd = next(filter(lambda c: c.name == 'help', commands), None) | 244 help_cmd = next(filter(lambda c: c.name == 'help', commands), None) |
239 if help_cmd and help_cmd.has_topics: | 245 if help_cmd and help_cmd.has_topics: |
240 with io.StringIO() as epilog: | 246 with io.StringIO() as epilog: |
241 epilog.write("additional help topics:\n") | 247 epilog.write("additional help topics:\n") |
250 | 256 |
251 # Print the help if no command was specified. | 257 # Print the help if no command was specified. |
252 if not hasattr(result, 'func'): | 258 if not hasattr(result, 'func'): |
253 parser.print_help() | 259 parser.print_help() |
254 return 0 | 260 return 0 |
261 | |
262 # Use a customized cache for the command and current config. | |
263 if result.cache_name != 'default' or cache_key != 'default': | |
264 app.useSubCache(result.cache_name, cache_key) | |
255 | 265 |
256 # Run the command! | 266 # Run the command! |
257 ctx = CommandContext(app, parser, result) | 267 ctx = CommandContext(app, parser, result) |
258 exit_code = result.func(ctx) | 268 exit_code = result.func(ctx) |
259 if exit_code is None: | 269 if exit_code is None: |