on engine-data help sign in
searx/utils/site-python/sphinx_build_tools.py
48 lines 1.7 kB history raw
1# -*- coding: utf-8; mode: python -*-
2"""Implement some sphinx-build tools.
4"""
6import os
7import sys
8from sphinx.util.pycompat import execfile_
10# ------------------------------------------------------------------------------
11def load_sphinx_config(namespace):
12# ------------------------------------------------------------------------------
14 u"""Load an additional configuration file into *namespace*.
16 The name of the configuration file is taken from the environment
17 ``SPHINX_CONF``. The external configuration file extends (or overwrites) the
18 configuration values from the origin ``conf.py``. With this you are able to
19 maintain *build themes*. To your docs/conf.py add::
21 from sphinx_build_tools import load_sphinx_config
22 ...
24 # Since loadConfig overwrites settings from the global namespace, it has to be
25 # the last statement in the conf.py file
27 load_sphinx_config(globals())
29 """
31 config_file = os.environ.get("SPHINX_CONF", None)
32 if (config_file is not None
33 and os.path.normpath(namespace["__file__"]) != os.path.normpath(config_file) ):
34 config_file = os.path.abspath(config_file)
36 if os.path.isfile(config_file):
37 sys.stdout.write(
38 "load additional sphinx-config: %s\n"
39 % config_file)
40 config = namespace.copy()
41 config['__file__'] = config_file
42 execfile_(config_file, config)
43 del config['__file__']
44 namespace.update(config)
45 else:
46 sys.stderr.write(
47 "WARNING: additional sphinx-config not found: %s\n"
48 % config_file)