|
37 | 37 | 'exclude_patterns', |
38 | 38 | 'automodule_options', |
39 | 39 | 'max_depth', |
| 40 | + 'template_dir', |
40 | 41 | }) |
41 | 42 |
|
42 | 43 |
|
@@ -169,7 +170,24 @@ def _parse_module_options( |
169 | 170 | ) |
170 | 171 | ] |
171 | 172 |
|
172 | | - # TODO template_dir |
| 173 | + template_dir = _normalize_template_dir(defaults.template_dir, confdir=confdir) |
| 174 | + if 'template_dir' in options: |
| 175 | + if options['template_dir'] is None: |
| 176 | + template_dir = None |
| 177 | + elif isinstance(options['template_dir'], str): |
| 178 | + template_dir = _normalize_template_dir( |
| 179 | + options['template_dir'], confdir=confdir |
| 180 | + ) |
| 181 | + else: |
| 182 | + LOGGER.warning( |
| 183 | + __("apidoc_modules item %i '%s' must be a string"), |
| 184 | + i, |
| 185 | + 'template_dir', |
| 186 | + type='apidoc', |
| 187 | + ) |
| 188 | + template_dir = _normalize_template_dir( |
| 189 | + defaults.template_dir, confdir=confdir |
| 190 | + ) |
173 | 191 |
|
174 | 192 | max_depth = defaults.max_depth |
175 | 193 | if 'max_depth' in options: |
@@ -227,6 +245,7 @@ def _parse_module_options( |
227 | 245 | implicit_namespaces=bool_options['implicit_namespaces'], |
228 | 246 | automodule_options=automodule_options, |
229 | 247 | header=module_path.name, |
| 248 | + template_dir=template_dir, |
230 | 249 | ) |
231 | 250 |
|
232 | 251 |
|
@@ -261,3 +280,18 @@ def _check_collection_of_strings( |
261 | 280 | ) |
262 | 281 | return default |
263 | 282 | return options[key] |
| 283 | + |
| 284 | + |
| 285 | +def _normalize_template_dir( |
| 286 | + value: str | Path | None, |
| 287 | + *, |
| 288 | + confdir: Path, |
| 289 | +) -> Path | None: |
| 290 | + """Return a template directory path resolved relative to *confdir*.""" |
| 291 | + if value is None: |
| 292 | + return None |
| 293 | + |
| 294 | + path = Path(value) |
| 295 | + if not path.is_absolute(): |
| 296 | + path = confdir / path |
| 297 | + return path |
0 commit comments