configuration.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 an override all of these values inside you :file:`conf.py`.
  22. .. note::
  23. You can check which tags/branches are matched by running ``sphinx-multiversion`` with the ``--dump-metadata`` flag.
  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-stye Python formatting.
  67. .. _python_regex: https://docs.python.org/3/howto/regex.html
  68. .. _python_format: https://pyformat.info/