-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
conf.py
310 lines (241 loc) · 9.48 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
"""Configuration file for the Sphinx documentation builder.
"""
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
import datetime
import glob
import os
import re
import sys
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('_extensions'))
# import sphinx_rtd_theme
# import picard_theme
this_year = datetime.datetime.now().year
copyright_year = str(this_year) if this_year == 2020 else f'2020-{this_year}'
# -- Project information -----------------------------------------------------
project = 'MusicBrainz Picard'
# The full version, including alpha/beta/rc tags (must start with a 'v' and not contain any spaces)
version = 'v2.12.3'
author = 'Bob Swift'
# copyright = 'MusicBrainz Picard User Guide by Bob Swift is licensed under CC0 1.0. To view a copy of this license, visit https://creativecommons.org/publicdomain/zero/1.0'
copyright = 'This documentation is licensed under CC0 1.0.' # pylint: disable=redefined-builtin
# -- Language information ----------------------------------------------------
default_language = 'en'
supported_languages = [
('en', 'English'),
('fr', 'Français'),
# ('de', 'Deutsch'),
# ('es', 'Español'),
]
# -- Base file name for PDF and EPUB files -----------------------------------
base_filename = 'musicbrainzpicard'
# -- Notice for Back of Title Page in LaTex Output ---------------------------
my_notice = r'''\vspace*{\fill}
MusicBrainz Picard User Guide by Bob Swift is licensed under CC0 1.0. To view a
copy of this license, visit https://creativecommons.org/publicdomain/zero/1.0
\vspace{0.1\textheight}'''
# -- General configuration ---------------------------------------------------
# The master toctree document.
master_doc = 'index'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"recommonmark",
"notfound.extension",
"taggerscript",
"sphinxcontrib.youtube",
# "sphinx_rtd_theme",
# "picard_theme",
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = [
'_build',
'_images',
'_ignored',
'_locale',
'Thumbs.db',
'.DS_Store',
'README.md',
'html',
'docs',
'.git',
'.github',
'images',
'testing',
'README.md',
'TODO.md',
]
# -- Options for Internationalization ----------------------------------------
language = default_language
locale_dirs = ['_locale']
gettext_compact = False
# gettext_compact = True
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
# html_theme = 'alabaster'
html_theme = "sphinx_rtd_theme"
# html_theme = "picard_theme"
# html_theme = "basic"
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_js_files = ['/version_links.js']
# Major.minor portion of the version number used for naming the download files
major_minor = re.match(r'^(v[0-9]+\.[0-9]+)', version).group(1)
html_context = {
'extra_css_files': [
'_static/css/extra.css',
],
'default_language': default_language,
'supported_languages': supported_languages,
'major_minor': major_minor,
'release': version,
}
html_favicon = '_static/picard-icon.png'
html_copy_source = False
# -- Options for LaTeX / PDF output ------------------------------------------
release = version # For display on cover of PDF document
latex_documents = [
('pdf', f'{base_filename}.tex', project, '', 'manual', False),
# ('pdf', '{0}.tex'.format(base_filename), project, 'Edited by Bob Swift', 'manual', False),
# ('pdf', '{0}.tex'.format(base_filename), project, '', 'howto', False),
]
# latex_toplevel_sectioning = 'part'
# latex_toplevel_sectioning = 'section' # Use with 'howto' document style
# latex_toplevel_sectioning = 'chapter'
# latex_show_urls = 'inline'
# latex_show_urls = 'footnote'
latex_show_urls = 'no'
latex_elements = {
'papersize': 'letterpaper',
'pointsize': '11pt',
# 'preamble': '\\hyphenation{Music-Brainz}',
'preamble': r'''\hyphenation{Music-Brainz}
\usepackage{fontspec}
\setmainfont{DejaVu Sans}
\setsansfont{DejaVu Sans}
\setmonofont{DejaVu Sans Mono}
\newcommand\sphinxbackoftitlepage{''' + my_notice + r'''}
''',
'extraclassoptions': 'openany',
# 'maketitle': r'\newcommand\sphinxbackoftitlepage{<Extra material>}\sphinxmaketitle',
# 'maketitle': r'\newcommand\sphinxbackoftitlepage{<Extra material>}\sphinxmaketitle',
}
latex_domain_indices = True
# -- Options for epub output ------------------------------------------
epub_basename = base_filename
epub_theme = 'epub'
# Metadata included in the epub file.
epub_title = f'{project} User Guide ({major_minor})'
epub_description = 'A User Guide for MusicBrainz Picard.'
epub_author = 'Bob Swift (Editor)'
epub_contributor = 'Members of the MusicBrainz Community'
epub_publisher = 'MetaBrainz Foundation'
epub_uid = 'MusicBrainzPicardUserGuide'
epub_tocdepth = 3
epub_tocscope = 'includehidden'
epub_cover = ('_static/picard_logo_256.png', 'epub-cover.html')
epub_guide = (('cover', 'epub-cover.xhtml', 'Cover Page'),)
# epub_show_urls = 'inline'
# epub_show_urls = 'footnote'
epub_show_urls = 'no'
epub_use_index = True
epub_post_files = [
('genindex.xhtml', 'INDEX'),
]
def _exclude_files_helper():
excludes = [
'404.xhtml',
'index.xhtml',
'not_found.xhtml',
'pdf.xhtml',
'examples/examples.xhtml',
]
for filepath in glob.glob('tutorials/v_*'):
if filepath.endswith('.rst'):
excludes.append(filepath[:-3] + 'xhtml')
return excludes
epub_exclude_files = _exclude_files_helper()
# -- Options for custom 404 page --------------------------------------
# sphinx-notfound-page
# https://github.com/readthedocs/sphinx-notfound-page
notfound_template = 'custom_404.html'
notfound_title = 'Page Not Found'
notfound_text_1 = "We're sorry but we are unable to find the requested page. Please use the table " \
+ "of contents or the search box in the left-hand sidebar to locate your topic."
notfound_text_2 = "If you believe that you have received this message in error, please report it in " \
+ "a <a href='https://tickets.metabrainz.org/issues/?filter=12025' target='_blank'>ticket</a> " \
+ "under the Picard project (Documentation component). Thanks."
notfound_script = r'''
<script>
var target_language = 'en';
var target_version = 'latest';
var src_host = window.location.hostname;
var src_protocol = window.location.protocol;
var src_path = window.location.pathname;
var src_path_parts = src_path.split('/');
var target_path = '';
var target_url = src_protocol + '//' + src_host + '/en/latest/not_found.html';
const re_language = /^[a-z][a-z](-[A-Z][A-Z])?$/;
const re_version_1 = /^[0-9][0-9\.]*$/;
const re_version_2 = /^(latest|stable)$/;
const re_version_3 = /^v[0-9][0-9\.]*$/;
function is_language(test_language) {
if (test_language.search(re_language) < 0) {
return false
}
target_language = test_language;
return true;
}
function is_rtd_version(test_version) {
return ((test_version.search(re_version_1) >= 0) || (test_version.search(re_version_2) >= 0));
}
function is_version(test_version) {
if (test_version.search(re_version_3) < 0) {
return false;
}
target_version = test_version.substring(1, 1000);
return true;
}
function test_url() {
var counter = 1;
if ((is_language(src_path_parts[counter])) && (is_rtd_version(src_path_parts[counter + 1]))) {
return true;
}
if (is_version(src_path_parts[counter])) {
counter += 1;
}
if (counter < src_path_parts.length) {
if (is_language(src_path_parts[counter])) {
target_path += '/' + target_language + '/' + target_version;
counter += 1;
while (counter < src_path_parts.length) {
target_path += '/' + src_path_parts[counter];
counter += 1;
}
target_url = src_protocol + '//' + src_host + target_path;
document.getElementById('content').innerHTML = '<p>The page may have been moved to <a href="' + target_url + '">' + target_url + '</a>.</p>';
window.location.replace(target_url);
}
}
}
test_url();
</script>
'''
notfound_context = {
'title': notfound_title,
'body': "\n<h1>" + notfound_title + "</h1>\n<p>\n" + notfound_text_1 + "\n</p>\n<div id='content'></div>\n<p>\n" + notfound_text_2 + "\n</p>\n" + notfound_script,
}