comparison piecrust/processing/pipeline.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 61d606fbc313
comparison
equal deleted inserted replaced
665:5dc13c816045 666:81d9c3a3a0b5
25 self.base_dir = base_dir 25 self.base_dir = base_dir
26 self.mount_info = mount_info 26 self.mount_info = mount_info
27 27
28 28
29 class ProcessorPipeline(object): 29 class ProcessorPipeline(object):
30 def __init__(self, app, out_dir, force=False): 30 def __init__(self, app, out_dir, force=False,
31 applied_config_variant=None,
32 applied_config_values=None):
31 assert app and out_dir 33 assert app and out_dir
32 self.app = app 34 self.app = app
33 self.out_dir = out_dir 35 self.out_dir = out_dir
34 self.force = force 36 self.force = force
35 37 self.applied_config_variant = applied_config_variant
36 tmp_dir = app.sub_cache_dir 38 self.applied_config_values = applied_config_values
39
40 tmp_dir = app.cache_dir
37 if not tmp_dir: 41 if not tmp_dir:
38 import tempfile 42 import tempfile
39 tmp_dir = os.path.join(tempfile.gettempdir(), 'piecrust') 43 tmp_dir = os.path.join(tempfile.gettempdir(), 'piecrust')
40 self.tmp_dir = os.path.join(tmp_dir, 'proc') 44 self.tmp_dir = os.path.join(tmp_dir, 'proc')
41 45
244 job = ProcessingWorkerJob(ctx.base_dir, ctx.mount_info, path, 248 job = ProcessingWorkerJob(ctx.base_dir, ctx.mount_info, path,
245 force=force_this) 249 force=force_this)
246 ctx.jobs.append(job) 250 ctx.jobs.append(job)
247 251
248 def _createWorkerPool(self): 252 def _createWorkerPool(self):
253 from piecrust.app import PieCrustFactory
249 from piecrust.workerpool import WorkerPool 254 from piecrust.workerpool import WorkerPool
250 from piecrust.processing.worker import ( 255 from piecrust.processing.worker import (
251 ProcessingWorkerContext, ProcessingWorker) 256 ProcessingWorkerContext, ProcessingWorker)
252 257
258 appfactory = PieCrustFactory(
259 self.app.root_dir,
260 cache=self.app.cache.enabled,
261 cache_key=self.app.cache_key,
262 config_variant=self.applied_config_variant,
263 config_values=self.applied_config_values,
264 debug=self.app.debug,
265 theme_site=self.app.theme_site)
266
253 ctx = ProcessingWorkerContext( 267 ctx = ProcessingWorkerContext(
254 self.app.root_dir, self.out_dir, self.tmp_dir, 268 appfactory,
255 force=self.force, debug=self.app.debug, 269 self.out_dir, self.tmp_dir,
256 theme_site=self.app.theme_site) 270 force=self.force)
257 ctx.enabled_processors = self.enabled_processors 271 ctx.enabled_processors = self.enabled_processors
258 if self.additional_processors_factories is not None: 272 if self.additional_processors_factories is not None:
259 ctx.additional_processors = [ 273 ctx.additional_processors = [
260 proc_fac() 274 proc_fac()
261 for proc_fac in self.additional_processors_factories] 275 for proc_fac in self.additional_processors_factories]