configuration.rst 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. .. _configuration:
  2. =============
  3. Configuration
  4. =============
  5. ``sphinx-multiversion`` reads your Sphinx :file:`conf.py` file for configuration.
  6. As usual, you can also override certain options by using ``-D var=value`` on the command line.
  7. This is what the default configuration looks like:
  8. .. code-block:: python
  9. # Whitelist pattern for tags (set to None to ignore all tags)
  10. smv_tag_whitelist = r'^.*$'
  11. # Whitelist pattern for branches (set to None to ignore all branches)
  12. smv_branch_whitelist = r'^.*$'
  13. # Whitelist pattern for remotes (set to None to use local branches only)
  14. smv_remote_whitelist = None
  15. # Pattern for released versions
  16. smv_released_pattern = r'^tags/.*$'
  17. # Format for versioned output directories inside the build directory
  18. smv_outputdir_format = '{ref.name}'
  19. # Determines whether remote or local git branches/tags are preferred if their output dirs conflict
  20. smv_prefer_remote_refs = False
  21. You can override all of these values inside your :file:`conf.py`.
  22. .. note::
  23. You can check which tags/branches are matched by running ``sphinx-multiversion`` with the ``--dump-metadata`` flag. Branches or tags that don't contain both the sphinx source directory and the :file:`conf.py` file will be skipped automatically.
  24. Tag/Branch/Remote whitelists
  25. ============================
  26. Tags, Branches and Remotes are included by `Regular Expressions <python_regex_>`_.
  27. Here are some examples:
  28. .. code-block:: python
  29. smv_tag_whitelist = r'^.*$' # Include all tags
  30. smv_tag_whitelist = r'^v\d+\.\d+$' # Include tags like "v2.1"
  31. smv_branch_whitelist = r'^.*$' # Include all branches
  32. smv_branch_whitelist = r'^(?!master).*$' # Include all branches except "master"
  33. smv_remote_whitelist = None # Only use local branches
  34. smv_remote_whitelist = r'^.*$' # Use branches from all remotes
  35. smv_remote_whitelist = r'^(origin|upstream)$' # Use branches from origin and upstream
  36. .. note::
  37. To list values to match, you can use ``git branch``, ``git tag`` and ``git remote``.
  38. Release Pattern
  39. ===============
  40. A Regular Expression is used to determine if a version of the documentation has been released or if it's a development version.
  41. To allow more flexibility, the regex is evaluated over the full refname.
  42. Here are some examples:
  43. .. code-block:: python
  44. smv_released_pattern = r'^tags/.*$' # Tags only
  45. smv_released_pattern = r'^heads/\d+\.\d+$' # Branches like "2.1"
  46. smv_released_pattern = r'^(tags/.*|heads/\d+\.\d+)$' # Branches like "2.1" and all tags
  47. smv_released_pattern = r'^(heads|remotes/[^/]+)/(?!:master).*$' # Everything except master branch
  48. .. note::
  49. To list all refnames , you can use:
  50. .. code-block:: bash
  51. git for-each-ref --format "%(refname)" | sed 's/^refs\///g'
  52. Output Directory Format
  53. =======================
  54. Each version will be built into a seperate subdirectory of the Sphinx output directory.
  55. The ``smv_outputdir_format`` setting determines the directory structure for the subdirectories. It is a new-style Python formatting string with two parameters - ``ref`` and ``config``.
  56. Here are some examples:
  57. .. code-block:: python
  58. smv_outputdir_format = '{ref.name}' # Use the branch/tag name
  59. smv_outputdir_format = '{ref.commit}' # Use the commit hash
  60. smv_outputdir_format = '{ref.commit:.7s}' # Use the commit hash truncated to 7 characters
  61. smv_outputdir_format = '{ref.refname}' # Use the full refname
  62. smv_outputdir_format = '{ref.source}/{ref.name}' # Equivalent to the previous example
  63. smv_outputdir_format = 'versions/{config.release}' # Use "versions" as parent directory and the "release" variable from conf.py
  64. smv_outputdir_format = '{config.version}/{ref.name}' # Use the version from conf.py as parent directory and the branch/tag name as subdirectory
  65. .. seealso::
  66. Have a look at `PyFormat <python_format_>`_ for information how to use new-style Python formatting.
  67. Overriding Configuration Variables
  68. ==================================
  69. You can override configuration variables the same way as you're used to with ``sphinx-build``.
  70. Since ``sphinx-multiversion`` copies the branch data into a temporary directory and builds them there while leaving the current working directory unchanged, relative paths in your :file:`conf.py` will refer to the path of the version *you're building from*, not the path of the version you are trying to build documentation for.
  71. Sometimes it might be necessary to override the configured path via a command line overide.
  72. ``sphinx-multiversion`` allows you to insert placeholders into your override strings that will automatically be replaced with the correct value for the version you're building the documentation for.
  73. Here's an example for the `exhale extension <exhale_>`_:
  74. .. code-block:: python
  75. sphinx-multiversion docs build/html -D 'exhale_args.containmentFolder=${sourcedir}/api'
  76. .. note::
  77. Make sure to enclose the override string in single quotes (``'``) to prevent the shell from treating it as an environment variable and replacing it before it's passed to ``sphinx-multiversion``.
  78. .. note::
  79. To see a list of available placeholder names and their values for each version you can use the ``--dump-metadata`` flag.
  80. .. _python_regex: https://docs.python.org/3/howto/regex.html
  81. .. _python_format: https://pyformat.info/
  82. .. _exhale: https://exhale.readthedocs.io/en/latest/