Mercurial > piecrust2
diff piecrust/pipelines/asset.py @ 853:f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
The asset pipeline is still the only function pipeline at this point.
* No more `QualifiedPage`, and several other pieces of code deleted.
* Data providers are simpler and more focused. For instance, the page iterator
doesn't try to support other types of items.
* Route parameters are proper known source metadata to remove the confusion
between the two.
* Make the baker and pipeline more correctly manage records and record
histories.
* Add support for record collapsing and deleting stale outputs in the asset
pipeline.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 21 May 2017 00:06:59 -0700 |
parents | 4850f8c21b6e |
children | 08e02c2a2a1a |
line wrap: on
line diff
--- a/piecrust/pipelines/asset.py Wed May 17 00:11:48 2017 -0700 +++ b/piecrust/pipelines/asset.py Sun May 21 00:06:59 2017 -0700 @@ -17,7 +17,7 @@ class AssetPipeline(ContentPipeline): PIPELINE_NAME = 'asset' - RECORD_CLASS = AssetPipelineRecordEntry + RECORD_ENTRY_CLASS = AssetPipelineRecordEntry def __init__(self, source): if not isinstance(source, FSContentSourceBase): @@ -68,22 +68,23 @@ if re_matchany(rel_path, self.ignore_patterns): return - record = result.record + record_entry = result.record_entry stats = self.app.env.stats # Build the processing tree for this job. with stats.timerScope('BuildProcessingTree'): builder = ProcessingTreeBuilder(self._processors) tree_root = builder.build(rel_path) - record.flags |= AssetPipelineRecordEntry.FLAG_PREPARED + record_entry.flags |= AssetPipelineRecordEntry.FLAG_PREPARED # Prepare and run the tree. print_node(tree_root, recursive=True) leaves = tree_root.getLeaves() - record.rel_outputs = [l.path for l in leaves] - record.proc_tree = get_node_name_tree(tree_root) + record_entry.out_paths = [os.path.join(ctx.out_dir, l.path) + for l in leaves] + record_entry.proc_tree = get_node_name_tree(tree_root) if tree_root.getProcessor().is_bypassing_structured_processing: - record.flags |= ( + record_entry.flags |= ( AssetPipelineRecordEntry.FLAG_BYPASSED_STRUCTURED_PROCESSING) if ctx.force: @@ -93,29 +94,11 @@ runner = ProcessingTreeRunner( self._base_dir, self.tmp_dir, ctx.out_dir) if runner.processSubTree(tree_root): - record.flags |= ( + record_entry.flags |= ( AssetPipelineRecordEntry.FLAG_PROCESSED) - def shutdown(self, ctx): - # Invoke post-processors. - proc_ctx = ProcessorContext(self, ctx) - for proc in self._processors: - proc.onPipelineEnd(proc_ctx) - - def collapseRecords(self, record_history): - for prev, cur in record_history.diffs(): - if prev and cur and not cur.was_processed: - # This asset wasn't processed, so the information from - # last time is still valid. - cur.flags = ( - prev.flags & - (~AssetPipelineRecordEntry.FLAG_PROCESSED | - AssetPipelineRecordEntry.FLAG_COLLAPSED_FROM_LAST_RUN)) - cur.out_paths = list(prev.out_paths) - cur.errors = list(prev.errors) - - def getDeletions(self, record_history): - for prev, cur in record_history.diffs(): + def getDeletions(self, ctx): + for prev, cur in ctx.record_history.diffs: if prev and not cur: for p in prev.out_paths: yield (p, 'previous asset was removed') @@ -124,6 +107,23 @@ for p in diff: yield (p, 'asset changed outputs') + def collapseRecords(self, ctx): + for prev, cur in ctx.record_history.diffs: + if prev and cur and not cur.was_processed: + # This asset wasn't processed, so the information from + # last time is still valid. + cur.flags = ( + (prev.flags & ~AssetPipelineRecordEntry.FLAG_PROCESSED) | + AssetPipelineRecordEntry.FLAG_COLLAPSED_FROM_LAST_RUN) + cur.out_paths = list(prev.out_paths) + cur.errors = list(prev.errors) + + def shutdown(self, ctx): + # Invoke post-processors. + proc_ctx = ProcessorContext(self, ctx) + for proc in self._processors: + proc.onPipelineEnd(proc_ctx) + split_processor_names_re = re.compile(r'[ ,]+')