Skip to content

Commit 18ca64d

Browse files
authored
Merge pull request #9 from humitos/rtd-environ-variables
Use RTD environ variables for project and version slug
2 parents 6560948 + 9113a35 commit 18ca64d

3 files changed

Lines changed: 17 additions & 11 deletions

File tree

README.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,22 @@ Then in your ``conf.py`` you have to add ``versionwarning`` in the ``extensions`
5656
'versionwarning',
5757
]
5858

59-
Enable it and setup the Read the Docs project's slug::
60-
61-
versionwarning_enabled = True
62-
versionwarning_project_slug = 'sphinx-version-warning'
6359

6460
Remember to configure the ``version`` of your Sphinx project since it's the key for this to work properly::
6561

6662
version = '0.0.1'
6763

64+
.. warning::
65+
66+
If ``READTHEDOCS_VERSION`` variable is defined, the extension will use its value.
67+
Otherwise, ``versionwarning_project_version`` will be used and if it's not defined, ``version`` as last resource.
68+
6869

6970
Customization
7071
-------------
7172

7273
Some customization can be done using the ``conf.py`` file of your Sphinx project:
7374

74-
versionwarning_enabled (bool)
75-
enable/disable version warning extension
76-
7775
versionwarning_default_admonition_type (string)
7876
type of admonition for the banner (warning, admonition or note)
7977

@@ -87,7 +85,10 @@ versionwarning_message_placeholder (string)
8785
text to be replaced by the version number link from the message
8886

8987
versionwarning_project_slug (string)
90-
slug of the project under Read the Docs
88+
slug of the project under Read the Docs (default to ``READTHEDOCS_PROJECT`` environment variable)
89+
90+
versionwarning_project_version (string)
91+
slug of the version for the current documentation (default to ``READTHEDOCS_VERSION`` environment variable or ``version`` variable from ``conf.py``)
9192

9293
versionwarning_api_url (string)
9394
API URL to retrieve all versions for this project

versionwarning/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
def setup(app):
8+
import os
89
import sphinx
910
from .signals import process_version_warning_banner, generate_versionwarning_data_json
1011

@@ -22,7 +23,6 @@ def setup(app):
2223
message=default_message.format(newest='<a href="#"></a>'),
2324
)
2425

25-
app.add_config_value('versionwarning_enabled', False, 'html')
2626
app.add_config_value('versionwarning_message_placeholder', '{newest}', 'html')
2727
app.add_config_value('versionwarning_default_admonition_type', 'warning', 'html')
2828
app.add_config_value('versionwarning_default_message', default_message, 'html')
@@ -33,7 +33,8 @@ def setup(app):
3333
app.add_config_value('versionwarning_banner_id_div', 'version-warning-banner', 'html')
3434
app.add_config_value('versionwarning_body_default_selector', 'div.body', 'html')
3535
app.add_config_value('versionwarning_body_extra_selector', 'div.document', 'html')
36-
app.add_config_value('versionwarning_project_slug', None, 'html')
36+
app.add_config_value('versionwarning_project_slug', os.environ.get('READTHEDOCS_PROJECT', None), 'html')
37+
app.add_config_value('versionwarning_project_version', os.environ.get('READTHEDOCS_VERSION', None), 'html')
3738

3839
app.connect('doctree-resolved', process_version_warning_banner)
3940

versionwarning/banner.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ def _default_admonition_type(self):
8282

8383
@property
8484
def _current_doc_version_slug(self):
85-
return self.app.config.version
85+
return (
86+
os.environ.get('READTHEDOCS_VERSION', None) or
87+
self.app.config.versionwarning_project_version or
88+
self.app.config.version
89+
)
8690

8791
@property
8892
def _latest_doc_version(self):

0 commit comments

Comments
 (0)