^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) # -*- coding: utf-8; mode: python -*-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # pylint: disable=R0903, C0330, R0914, R0912, E0401
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) import os
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) import sys
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) from sphinx.util.pycompat import execfile_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) # ------------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) def loadConfig(namespace):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) # ------------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) u"""Load an additional configuration file into *namespace*.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) The name of the configuration file is taken from the environment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) ``SPHINX_CONF``. The external configuration file extends (or overwrites) the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) configuration values from the origin ``conf.py``. With this you are able to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) maintain *build themes*. """
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) config_file = os.environ.get("SPHINX_CONF", None)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) if (config_file is not None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) and os.path.normpath(namespace["__file__"]) != os.path.normpath(config_file) ):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) config_file = os.path.abspath(config_file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) # Let's avoid one conf.py file just due to latex_documents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) start = config_file.find('Documentation/')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) if start >= 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) start = config_file.find('/', start + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) end = config_file.rfind('/')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) if start >= 0 and end > 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) dir = config_file[start + 1:end]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) print("source directory: %s" % dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) new_latex_docs = []
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) latex_documents = namespace['latex_documents']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) for l in latex_documents:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if l[0].find(dir + '/') == 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) has = True
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) fn = l[0][len(dir) + 1:]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) new_latex_docs.append((fn, l[1], l[2], l[3], l[4]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) break
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) namespace['latex_documents'] = new_latex_docs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) # If there is an extra conf.py file, load it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if os.path.isfile(config_file):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) sys.stdout.write("load additional sphinx-config: %s\n" % config_file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) config = namespace.copy()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) config['__file__'] = config_file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) execfile_(config_file, config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) del config['__file__']
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) namespace.update(config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) else:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) config = namespace.copy()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) config['tags'].add("subproject")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) namespace.update(config)