Youen
2 years ago
5 changed files with 41 additions and 3 deletions
@ -0,0 +1,21 @@ |
|||||||
|
# This module can read data from a python file in the source folder. This will read data from the version being built (as opposed to standard sphinx-multiversion behavior that executes python from the working copy) |
||||||
|
# All global variables defined in file current_version_data.py will be put in html_context['current_version_data'] which allows to use them in HTML templates. |
||||||
|
|
||||||
|
import sys |
||||||
|
|
||||||
|
current_version_data = {} |
||||||
|
|
||||||
|
def setup(app): |
||||||
|
app.add_config_value("version_sourcedir", '', "html") |
||||||
|
app.connect('config-inited', config_inited) |
||||||
|
|
||||||
|
def config_inited(app, config): |
||||||
|
app.connect('html-page-context', html_page_context) |
||||||
|
try: |
||||||
|
exec(open(app.config.version_sourcedir + '/current_version_data.py').read(), globals(), current_version_data) |
||||||
|
except: |
||||||
|
print('No file current_version_data.py found') |
||||||
|
pass |
||||||
|
|
||||||
|
def html_page_context(app, pagename, templatename, context, doctree): |
||||||
|
context['current_version_data'] = current_version_data |
Loading…
Reference in new issue