load_config.py 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. # -*- coding: utf-8; mode: python -*-
  2. # pylint: disable=R0903, C0330, R0914, R0912, E0401
  3. import os
  4. import sys
  5. from sphinx.util.pycompat import execfile_
  6. # ------------------------------------------------------------------------------
  7. def loadConfig(namespace):
  8. # ------------------------------------------------------------------------------
  9. u"""Load an additional configuration file into *namespace*.
  10. The name of the configuration file is taken from the environment
  11. ``SPHINX_CONF``. The external configuration file extends (or overwrites) the
  12. configuration values from the origin ``conf.py``. With this you are able to
  13. maintain *build themes*. """
  14. config_file = os.environ.get("SPHINX_CONF", None)
  15. if (config_file is not None
  16. and os.path.normpath(namespace["__file__"]) != os.path.normpath(config_file) ):
  17. config_file = os.path.abspath(config_file)
  18. if os.path.isfile(config_file):
  19. sys.stdout.write("load additional sphinx-config: %s\n" % config_file)
  20. config = namespace.copy()
  21. config['__file__'] = config_file
  22. execfile_(config_file, config)
  23. del config['__file__']
  24. namespace.update(config)
  25. else:
  26. sys.stderr.write("WARNING: additional sphinx-config not found: %s\n" % config_file)