Как распечатать версию документа в заголовке? - PullRequest
0 голосов
/ 05 февраля 2019

Я только что создал документ Sphinx, используя sphinx-quickstart.exe с темой alabaster.

И я хотел бы напечатать версию документа где-нибудь в заголовке.

Я заполнил version и release переменных в conf.py

# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.

# -- Project information -----------------------------------------------------

project = 'MWE'
copyright = '2019, and1er'
author = 'and1er'

# The short X.Y version
version = '2.4.12'
# The full version, including alpha/beta/rc tags
release = 'beta'

extensions = [
]

templates_path = ['_templates']
source_suffix = '.rst'

master_doc = 'index'
language = None
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
pygments_style = 'sphinx'

html_theme = 'alabaster'

html_static_path = ['_static']
htmlhelp_basename = 'MWEdoc'

index.rst

.. MWE documentation master file, created by
    sphinx-quickstart on Tue Feb  5 14:51:07 2019.
    You can adapt this file completely to your liking, but it should at least
    contain the root `toctree` directive.

Welcome to MWE's documentation!
===============================

.. toctree::
    :maxdepth: 2
    :caption: Contents:

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

Полученный документ не имеет строк 2.4.12 или beta.

Resulting document

Ответы [ 2 ]

0 голосов
/ 05 февраля 2019

В дополнение к подстановке, упомянутой @Slam, вы можете избежать обновления этого параметра вручную для каждого выпуска в conf.py.

import pkg_resources
version = pkg_resources.get_distribution('myproject').version
release = version

. Затем |release| можно поместить в источник reST.файлы или {{ release }} в шаблонах вашей темы.

0 голосов
/ 05 февраля 2019

Работает ли |version| замена у вас?

UPD Обновленный MWE

index.rst

.. MWE documentation master file, created by
   sphinx-quickstart on Tue Feb  5 14:51:07 2019.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to MWE's documentation!
===============================

.. toctree::
   :maxdepth: 2
   :caption: Contents:

Document version:
|version|
|release|


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

The expected result

...