load_config.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. # Let's avoid one conf.py file just due to latex_documents
  19. start = config_file.find('Documentation/')
  20. if start >= 0:
  21. start = config_file.find('/', start + 1)
  22. end = config_file.rfind('/')
  23. if start >= 0 and end > 0:
  24. dir = config_file[start + 1:end]
  25. print("source directory: %s" % dir)
  26. new_latex_docs = []
  27. latex_documents = namespace['latex_documents']
  28. for l in latex_documents:
  29. if l[0].find(dir + '/') == 0:
  30. has = True
  31. fn = l[0][len(dir) + 1:]
  32. new_latex_docs.append((fn, l[1], l[2], l[3], l[4]))
  33. break
  34. namespace['latex_documents'] = new_latex_docs
  35. # If there is an extra conf.py file, load it
  36. if os.path.isfile(config_file):
  37. sys.stdout.write("load additional sphinx-config: %s\n" % config_file)
  38. config = namespace.copy()
  39. config['__file__'] = config_file
  40. execfile_(config_file, config)
  41. del config['__file__']
  42. namespace.update(config)
  43. else:
  44. config = namespace.copy()
  45. config['tags'].add("subproject")
  46. namespace.update(config)