Mercurial > piecrust2
comparison piecrust/sources/autoconfig.py @ 979:45ad976712ec
tests: Big push to get the tests to pass again.
- Lots of fixes everywhere in the code.
- Try to handle debug logging in the multiprocessing worker pool when running in pytest. Not perfect, but usable for now.
- Replace all `.md` test files with `.html` since now a auto-format extension always sets the format.
- Replace `out` with `outfiles` in most places since now blog archives are added to the bake output and I don't want to add expected outputs for blog archives everywhere.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 29 Oct 2017 22:51:57 -0700 |
parents | f070a4fc033c |
children | 8adc27285d93 |
comparison
equal
deleted
inserted
replaced
978:7e51d14097cb | 979:45ad976712ec |
---|---|
24 raise ConfigurationError("Capture mode in source '%s' must be " | 24 raise ConfigurationError("Capture mode in source '%s' must be " |
25 "one of: path, dirname, filename" % | 25 "one of: path, dirname, filename" % |
26 name) | 26 name) |
27 | 27 |
28 def _finalizeContent(self, parent_group, items, groups): | 28 def _finalizeContent(self, parent_group, items, groups): |
29 DefaultContentSource._finalizeContent(parent_group, items, groups) | 29 super()._finalizeContent(parent_group, items, groups) |
30 | 30 |
31 # If `capture_mode` is `dirname`, we don't need to recompute it | 31 # If `capture_mode` is `dirname`, we don't need to recompute it |
32 # for each filename, so we do it here. | 32 # for each filename, so we do it here. |
33 if self.capture_mode == 'dirname': | 33 if self.capture_mode == 'dirname': |
34 rel_dirpath = os.path.relpath(parent_group.spec, | 34 rel_dirpath = '.' |
35 self.fs_endpoint_path) | 35 if parent_group is not None: |
36 rel_dirpath = os.path.relpath(parent_group.spec, | |
37 self.fs_endpoint_path) | |
36 config = self._extractConfigFragment(rel_dirpath) | 38 config = self._extractConfigFragment(rel_dirpath) |
37 | 39 |
38 for i in items: | 40 for i in items: |
39 # Compute the confif for the other capture modes. | 41 # Compute the config for the other capture modes. |
40 if self.capture_mode == 'path': | 42 if self.capture_mode == 'path': |
41 rel_path = os.path.relpath(i.spec, self.fs_endpoint_path) | 43 rel_path = os.path.relpath(i.spec, self.fs_endpoint_path) |
42 config = self._extractConfigFragment(rel_path) | 44 config = self._extractConfigFragment(rel_path) |
43 elif self.capture_mode == 'filename': | 45 elif self.capture_mode == 'filename': |
44 fname = os.path.basename(i.spec) | 46 fname = os.path.basename(i.spec) |
58 """ | 60 """ |
59 SOURCE_NAME = 'autoconfig' | 61 SOURCE_NAME = 'autoconfig' |
60 | 62 |
61 def __init__(self, app, name, config): | 63 def __init__(self, app, name, config): |
62 config['capture_mode'] = 'dirname' | 64 config['capture_mode'] = 'dirname' |
63 AutoConfigContentSourceBase.__init__(app, name, config) | 65 super().__init__(app, name, config) |
64 | 66 |
65 self.setting_name = config.get('setting_name', name) | 67 self.setting_name = config.get('setting_name', name) |
66 self.only_single_values = config.get('only_single_values', False) | 68 self.only_single_values = config.get('only_single_values', False) |
67 self.collapse_single_values = config.get('collapse_single_values', | 69 self.collapse_single_values = config.get('collapse_single_values', |
68 False) | 70 False) |
106 config = self._extractConfigFragment(rel_path) | 108 config = self._extractConfigFragment(rel_path) |
107 metadata = {'slug': slug, 'config': config} | 109 metadata = {'slug': slug, 'config': config} |
108 return ContentItem(path, metadata) | 110 return ContentItem(path, metadata) |
109 return None | 111 return None |
110 | 112 |
113 def _makeSlug(self, path): | |
114 slug = super()._makeSlug(path) | |
115 return os.path.basename(slug) | |
116 | |
111 | 117 |
112 class OrderedContentSource(AutoConfigContentSourceBase): | 118 class OrderedContentSource(AutoConfigContentSourceBase): |
113 """ A content source that assigns an "order" to its pages based on a | 119 """ A content source that assigns an "order" to its pages based on a |
114 numerical prefix in their filename. Page iterators will automatically | 120 numerical prefix in their filename. Page iterators will automatically |
115 sort pages using that order. | 121 sort pages using that order. |
118 | 124 |
119 re_pattern = re.compile(r'(^|[/\\])(?P<num>\d+)_') | 125 re_pattern = re.compile(r'(^|[/\\])(?P<num>\d+)_') |
120 | 126 |
121 def __init__(self, app, name, config): | 127 def __init__(self, app, name, config): |
122 config['capture_mode'] = 'path' | 128 config['capture_mode'] = 'path' |
123 AutoConfigContentSourceBase.__init__(app, name, config) | 129 super().__init__(app, name, config) |
124 | 130 |
125 self.setting_name = config.get('setting_name', 'order') | 131 self.setting_name = config.get('setting_name', 'order') |
126 self.default_value = config.get('default_value', 0) | 132 self.default_value = config.get('default_value', 0) |
127 | 133 |
128 def findContent(self, route_params): | 134 def findContent(self, route_params): |