Mercurial > piecrust2
diff piecrust/sources/pageref.py @ 411:e7b865f8f335
bake: Enable multiprocess baking.
Baking is now done by running a worker per CPU, and sending jobs to them.
This changes several things across the codebase:
* Ability to not cache things related to pages other than the 'main' page
(i.e. the page at the bottom of the execution stack).
* Decouple the baking process from the bake records, so only the main process
keeps track (and modifies) the bake record.
* Remove the need for 'batch page getters' and loading a page directly from
the page factories.
There are various smaller changes too included here, including support for
scope performance timers that are saved with the bake record and can be
printed out to the console. Yes I got carried away.
For testing, the in-memory 'mock' file-system doesn't work anymore, since
we're spawning processes, so this is replaced by a 'tmpfs' file-system which
is saved in temporary files on disk and deleted after tests have run.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 12 Jun 2015 17:09:19 -0700 |
parents | 4b1019bb2533 |
children | ab5c6a8ae90a |
line wrap: on
line diff
--- a/piecrust/sources/pageref.py Sat May 30 15:41:52 2015 -0700 +++ b/piecrust/sources/pageref.py Fri Jun 12 17:09:19 2015 -0700 @@ -42,7 +42,6 @@ @property def source_name(self): - self._checkHits() return self._first_valid_hit.source_name @property @@ -51,23 +50,25 @@ @property def rel_path(self): - self._checkHits() return self._first_valid_hit.rel_path @property def path(self): - self._checkHits() return self._first_valid_hit.path @property def metadata(self): - self._checkHits() return self._first_valid_hit.metadata @property - def possible_rel_paths(self): + def possible_ref_specs(self): self._load() - return [h.rel_path for h in self._hits] + return ['%s:%s' % (h.source_name, h.rel_path) for h in self._hits] + + @property + def possible_split_ref_specs(self): + self._load() + return [(h.source_name, h.rel_path) for h in self._hits] @property def possible_paths(self): @@ -80,17 +81,23 @@ @property def _first_valid_hit(self): + self._checkHits() return self._hits[self._first_valid_hit_index] def _load(self): if self._hits is not None: return + self._hits = [] + + if self._page_ref is None: + self._first_valid_hit_index = self._INDEX_NOT_FOUND + return + it = list(page_ref_pattern.finditer(self._page_ref)) if len(it) == 0: raise Exception("Invalid page ref: %s" % self._page_ref) - self._hits = [] for m in it: source_name = m.group('src') source = self.app.getSource(source_name) @@ -111,15 +118,17 @@ def _checkHits(self): if self._first_valid_hit_index >= 0: return + + if self._first_valid_hit_index == self._INDEX_NEEDS_LOADING: + self._load() + self._first_valid_hit_index = self._INDEX_NOT_FOUND + for i, hit in enumerate(self._hits): + if os.path.isfile(hit.path): + self._first_valid_hit_index = i + break + if self._first_valid_hit_index == self._INDEX_NOT_FOUND: raise PageNotFoundError( "No valid paths were found for page reference: %s" % self._page_ref) - self._load() - self._first_valid_hit_index = self._INDEX_NOT_FOUND - for i, hit in enumerate(self._hits): - if os.path.isfile(hit.path): - self._first_valid_hit_index = i - break -