Mercurial > piecrust2
annotate piecrust/pathutil.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 | 9c074aec60a6 |
children | 3ceeca7bb71c |
rev | line source |
---|---|
38
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
1 import re |
0 | 2 import os |
3 import os.path | |
62
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
4 import fnmatch |
0 | 5 |
6 | |
115
9c074aec60a6
Fix search for root folder. Must have been drunk when I wrote this originally.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
7 re_terminal_path = re.compile(r'^(\w\:)?[/\\]$') |
38
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
8 |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
9 |
0 | 10 class SiteNotFoundError(Exception): |
38
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
11 def __init__(self, root=None, msg=None): |
0 | 12 if not root: |
13 root = os.getcwd() | |
38
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
14 full_msg = ("No PieCrust website in '%s' " |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
15 "('config.yml' not found!)" % |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
16 root) |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
17 if msg: |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
18 full_msg += ": " + msg |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
19 else: |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
20 full_msg += "." |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
21 Exception.__init__(self, full_msg) |
0 | 22 |
23 | |
24 def find_app_root(cwd=None): | |
25 if cwd is None: | |
26 cwd = os.getcwd() | |
27 | |
36
485682a6de50
New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
28 while not os.path.isfile(os.path.join(cwd, 'config.yml')): |
0 | 29 cwd = os.path.dirname(cwd) |
38
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
30 if not cwd or re_terminal_path.match(cwd): |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
31 raise SiteNotFoundError(cwd) |
0 | 32 return cwd |
33 | |
62
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
34 |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
35 def multi_fnmatch_filter(names, patterns, modifier=None, inverse=True): |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
36 res = [] |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
37 for n in names: |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
38 matches = False |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
39 test_n = modifier(n) if modifier else n |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
40 for p in patterns: |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
41 if fnmatch.fnmatch(test_n, p): |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
42 matches = True |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
43 break |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
44 if matches and not inverse: |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
45 res.append(n) |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
46 elif not matches and inverse: |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
47 res.append(n) |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
48 return res |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
49 |