/
conf.py
157 lines (120 loc) · 4.8 KB
/
conf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2019-2021 releng-tool
from releng_tool_docbuilder_locale import L
from releng_tool_docbuilder_locale import add_translation_to_context
from releng_tool_docbuilder_locale import register_message_catalog
import os
import sys
if 'RELENG_TARGET_DIR' not in os.environ:
raise SyntaxError('target directory not provided')
base_dir = os.path.dirname(os.path.abspath(__file__))
releng_tool_dir = os.path.abspath(os.environ['RELENG_TARGET_DIR'])
releng_tool_doc_dir = os.path.join(releng_tool_dir, 'Documentation')
# inject releng-tool into system path to allow autodocs content to render
sys.path.insert(0, releng_tool_dir)
# load releng-tool's sphinx configuration
releng_tool_conf = os.path.join(releng_tool_doc_dir, 'conf.py')
with open(releng_tool_conf, 'rb') as source_file:
code = compile(source_file.read(), releng_tool_conf, 'exec')
exec(code, globals(), locals())
try:
releng_tool_doc_setup = setup
except NameError:
releng_tool_doc_setup = None
# builder sphinx configuration
canonical_url = 'https://docs.releng.io/'
html_show_copyright = False
html_show_sphinx = True
# check if we are using a legacy theme (v0.9 and older), as we will still apply
# an older theme on older revisions
legacy_theme = html_theme != 'furo'
# theme overrides
if not legacy_theme:
templates_path = [
os.path.join(base_dir, 'templates/'),
]
html_js_files = [
'jquery-3.6.3.slim.min.js',
'theme_overrides_global.js',
]
html_static_path.append(os.path.join(base_dir, '_static/'))
# legacy theme
else:
templates_path = [
os.path.join(base_dir, 'legacy', 'templates/'),
]
html_theme_options['canonical_url'] = canonical_url
html_static_path.append(os.path.join(base_dir, 'legacy', '_static/'))
# note: v0.8 older injected into the html context
try:
html_context
except NameError:
html_context = {}
# version/language information
if 'RELENG_VERSION' not in os.environ:
raise SyntaxError('version not provided')
version = os.environ['RELENG_VERSION']
if 'RELENG_VERSIONS' not in os.environ:
raise SyntaxError('supported versions not provided')
html_context['versions'] = os.environ['RELENG_VERSIONS'].split(',')
if 'RELENG_STABLE' not in os.environ:
raise SyntaxError('stable version not provided')
most_stable_version = os.environ['RELENG_STABLE']
if 'RELENG_LANGUAGE' not in os.environ:
raise SyntaxError('language not provided')
language = os.environ['RELENG_LANGUAGE']
if 'RELENG_LANGUAGES' not in os.environ:
raise SyntaxError('supported languages not provided')
html_context['languages'] = os.environ['RELENG_LANGUAGES'].split(',')
if 'RELENG_LOCALE_DIR' not in os.environ:
raise SyntaxError('locale directory not provided')
locale_dirs = [os.environ['RELENG_LOCALE_DIR']]
def build_announcement():
announcement = None
stable_text = L('Stable v{}').format(most_stable_version)
stable_data = '<a href="{}/{}/latest/">{}</a>'.format(
canonical_url,
language,
stable_text
)
if version == 'development':
announcement = L('Development Version') + ' | ' + stable_data
elif version != most_stable_version and version != 'latest':
announcement = L('Legacy Version') + ' | ' + stable_data
return announcement
def configure_furo_announcement(app, config):
# inject an announcement message into furo theme (if needed)
announcement = build_announcement()
if announcement:
html_theme_options['announcement'] = build_announcement()
def configure_lang_context(app, pagename, templatename, context, doctree):
# configure a version string for the version box's title area
if version == 'development':
context['version_str'] = L('Development')
elif version == 'latest':
context['version_str'] = L('Latest')
else:
context['version_str'] = version
# inject an announcement message into legacy theme (if needed)
announcement = build_announcement()
if announcement:
context['version_warning'] = announcement
def setup(app):
theme_override = 'theme_overrides_global.css'
# invoke releng-tool's documentation setup
if releng_tool_doc_setup:
releng_tool_doc_setup(app)
# inject additional theme overrides
app.add_css_file(theme_override)
else:
html_context['css_files'].append('_static/' + theme_override)
# point application documentation to releng-tool's set
app.confdir = releng_tool_doc_dir
app.srcdir = releng_tool_doc_dir
# register locale support
app.connect('config-inited', register_message_catalog)
app.connect('html-page-context', add_translation_to_context)
app.connect('html-page-context', configure_lang_context)
if not legacy_theme:
app.connect('config-inited', configure_furo_announcement)