Skip to content

Commit de3738b

Browse files
committed
Move conf.py, _static/, and _templates/ here.
New options to build_docs* scripts allow users to specify custom paths if they don't want to use the ones built in to doc-builder. Requires the parent repo to have a substitutions.py file next to doc-builder.
1 parent 1026875 commit de3738b

File tree

12 files changed

+568
-11
lines changed

12 files changed

+568
-11
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
ce25647921a8f82c3b5009bdd07a620545b91a0c
22
8762f2d8834a9ba391b73ca4ac36f3bb19b169ed
33
04f3a94bdb9fc8c402286ebdc3ff9cb688c1e4b6
4+
81b7b35c4e07551459a98b7be17b6b6400d12e3a

_static/css/custom.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Make equation numbers float to the right */
2+
.eqno {
3+
margin-left: 5px;
4+
float: right;
5+
}
6+
/* Hide the link... */
7+
.math .headerlink {
8+
display: none;
9+
visibility: hidden;
10+
}
11+
/* ...unless the equation is hovered */
12+
.math:hover .headerlink {
13+
display: inline-block;
14+
visibility: visible;
15+
/* Place link in margin and keep equation number aligned with boundary */
16+
margin-right: -0.7em;
17+
}

_templates/footer.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% extends "!footer.html" %}
2+
{% block extrafooter %}
3+
{{ super() }}
4+
<script>var version_json_loc = "{{ pathto('../../versions.json', 1) }}";</script>
5+
{% endblock %}

_templates/landing.index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta http-equiv="refresh" content="0; url=PATH/TO/LANDING/PAGE.HTML" />
5+
</head>
6+
</html>

_templates/versions.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="versions">
2+
<span class="rst-current-version" data-toggle="rst-current-version">
3+
Version: {{ current_version }}
4+
<span class="fa fa-caret-down"></span>
5+
</span>
6+
<div class="rst-other-versions">
7+
{% if languages|length >= 1 %}
8+
<dl>
9+
<dt>{{ _('Languages') }}</dt>
10+
{% for the_language, url in languages %}
11+
<dd><a href="{{ url }}/index.html">{{ the_language }}</a></dd>
12+
{% endfor %}
13+
</dl>
14+
{% endif %}
15+
{% if versions|length >= 1 %}
16+
<dl>
17+
<dt>{{ _('Versions') }}</dt>
18+
{% for the_version, url in versions %}
19+
<dd><a href="{{ url }}/index.html">{{ the_version }}</a></dd>
20+
{% endfor %}
21+
</dl>
22+
{% endif %}
23+
<br>
24+
</dl>
25+
</div>
26+
</div>

build_docs_to_publish

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ sys.path.insert(0, os.getcwd())
2626

2727
# Import our definitions of each documentation version.
2828
# pylint: disable=wrong-import-position
29-
from source.version_list import (
29+
from version_list import (
3030
LATEST_REF,
3131
VERSION_LIST,
3232
)
@@ -35,10 +35,8 @@ from source.version_list import (
3535
# Path to certain important files
3636
# TODO: Make these cmd-line options
3737
SOURCE = "source"
38-
CONF_PY = os.path.join(SOURCE, "conf.py")
39-
VERSIONS_PY = os.path.join(SOURCE, "version_list.py")
40-
STATIC_DIR = os.path.join(SOURCE, "_static")
41-
TEMPLATES_DIR = os.path.join(SOURCE, "_templates")
38+
VERSIONS_PY = os.path.join("version_list.py")
39+
MAKEFILE = "Makefile"
4240

4341

4442
def checkout_and_build(version, args):
@@ -51,7 +49,7 @@ def checkout_and_build(version, args):
5149

5250
# Some files/directories/submodules must stay the same for all builds. We list these in
5351
# the permanent_files list.
54-
permanent_files = [CONF_PY, VERSIONS_PY, STATIC_DIR, TEMPLATES_DIR, "doc-builder"]
52+
permanent_files = [VERSIONS_PY, "doc-builder", MAKEFILE]
5553

5654
# Check some things about "permanent" files before checkout
5755
for filename in permanent_files:
@@ -79,6 +77,12 @@ def checkout_and_build(version, args):
7977
]
8078
if args.build_with_docker:
8179
build_args += ["-d"]
80+
if args.conf_py_path:
81+
build_args += ["--conf-py-path", args.conf_py_path]
82+
if args.static_path:
83+
build_args += ["--static-path", args.static_path]
84+
if args.templates_path:
85+
build_args += ["--templates-path", args.templates_path]
8286
print(" ".join(build_args))
8387
build_docs(build_args)
8488

conf.py

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# This file is execfile()d with the current directory set to its
4+
# containing dir.
5+
#
6+
# Note that not all possible configuration values are present in this
7+
# autogenerated file.
8+
#
9+
# All configuration values have a default; values that are commented out
10+
# serve to show the default.
11+
12+
# If extensions (or modules to document with autodoc) are in another directory,
13+
# add these directories to sys.path here. If the directory is relative to the
14+
# documentation root, use os.path.abspath to make it absolute, like shown here.
15+
#
16+
import os
17+
import sys
18+
import sphinx_rtd_theme
19+
20+
# Assumes substitutions.py and version_list.py are in the parent dir of doc-builder
21+
# pylint: disable=wrong-import-position
22+
dir2add = os.path.join(os.path.dirname(__file__), os.pardir)
23+
sys.path.insert(0, dir2add)
24+
import substitutions as subs # pylint: disable=import-error
25+
from version_list import VERSION_LIST # pylint: disable=import-error
26+
27+
28+
# -- General configuration ------------------------------------------------
29+
30+
# If your documentation needs a minimal Sphinx version, state it here.
31+
#
32+
# needs_sphinx = '1.0'
33+
34+
# Add any Sphinx extension module names here, as strings. They can be
35+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
36+
# ones.
37+
extensions = ['sphinx.ext.intersphinx',
38+
'sphinx.ext.autodoc',
39+
'sphinx.ext.todo',
40+
'sphinx.ext.coverage',
41+
'sphinx.ext.githubpages',
42+
'sphinx_mdinclude',
43+
]
44+
45+
# Add any paths that contain templates here, relative to this directory.
46+
if os.environ["templates_path"]:
47+
templates_path = [os.environ["templates_path"]]
48+
if not all(os.path.isdir(x) for x in templates_path):
49+
raise RuntimeError(f"Some member of templates_path does not exist: {templates_path}")
50+
51+
# The suffix(es) of source filenames.
52+
# You can specify multiple suffix as a list of string:
53+
#
54+
source_suffix = ['.rst', '.md']
55+
# source_suffix = '.rst'
56+
57+
# The master toctree document.
58+
source_start_file = 'index'
59+
60+
# Save standard Sphinx substitution vars separately
61+
project = subs.project
62+
copyright = subs.copyright # pylint: disable=redefined-builtin
63+
author = subs.author
64+
version = subs.version
65+
release = subs.release
66+
67+
# version_label is not a standard sphinx variable, so we need some custom rst to allow
68+
# pages to use it. We need a separate replacement for the bolded version because it
69+
# doesn't work to have variable replacements within formatting.
70+
rst_epilog = """
71+
.. |version_label| replace:: {version_label}
72+
.. |version_label_bold| replace:: **{version_label}**
73+
""".format(version_label=subs.version_label)
74+
75+
# The language for content autogenerated by Sphinx. Refer to documentation
76+
# for a list of supported languages.
77+
#
78+
# This is also used if you do content translation via gettext catalogs.
79+
# Usually you set "language" from the command line for these cases.
80+
language = "en"
81+
82+
# List of patterns, relative to source directory, that match files and
83+
# directories to ignore when looking for source files.
84+
# This patterns also effect to html_static_path and html_extra_path
85+
exclude_patterns = []
86+
87+
# The name of the Pygments (syntax highlighting) style to use.
88+
pygments_style = 'sphinx'
89+
90+
# If true, `todo` and `todoList` produce output, else they produce nothing.
91+
todo_include_todos = True
92+
93+
# -- Options for HTML output ----------------------------------------------
94+
95+
# The theme to use for HTML and HTML Help pages. See the documentation for
96+
# a list of builtin themes.
97+
#
98+
html_theme = 'sphinx_rtd_theme'
99+
100+
# Theme options are theme-specific and customize the look and feel of a theme
101+
# further. For a list of options available for each theme, see the
102+
# documentation.
103+
104+
# Add any paths that contain custom static files (such as style sheets) here,
105+
# relative to this directory. They are copied after the builtin static files,
106+
# so a file named "default.css" will overwrite the builtin "default.css".
107+
html_static_path = [os.environ["html_static_path"]]
108+
109+
110+
# -- Options for HTMLHelp output ------------------------------------------
111+
112+
if getattr(subs, "htmlhelp", False):
113+
htmlhelp_basename = subs.htmlhelp["basename"]
114+
115+
116+
# -- Options for LaTeX output ---------------------------------------------
117+
if getattr(subs, "latex", False):
118+
119+
latex_elements = {
120+
# The paper size ('letterpaper' or 'a4paper').
121+
#
122+
# 'papersize': 'letterpaper',
123+
124+
# The font size ('10pt', '11pt' or '12pt').
125+
#
126+
# 'pointsize': '10pt',
127+
128+
# Additional stuff for the LaTeX preamble.
129+
#
130+
'preamble': '\\usepackage{hyperref}',
131+
132+
'fncychap': '\\usepackage[Conny]{fncychap}',
133+
134+
# Latex figure (float) alignment
135+
#
136+
# 'figure_align': 'htbp',
137+
}
138+
139+
# Grouping the document tree into LaTeX files. List of tuples
140+
# (source start file, target name, title,
141+
# author, documentclass [howto, manual, or own class]).
142+
latex_documents = [(
143+
source_start_file,
144+
subs.latex["target_name"],
145+
subs.latex["title"],
146+
author,
147+
subs.latex["category"],
148+
)]
149+
150+
151+
# Options for manual page and Texinfo output
152+
if getattr(subs, "mantex", False):
153+
154+
# One entry per manual page. List of tuples
155+
# (source start file, name, title, authors, manual section).
156+
man_pages = [
157+
(source_start_file, subs.mantex["name"], subs.mantex["title"], [author], 1),
158+
]
159+
160+
if getattr(subs, "tex", False):
161+
# Grouping the document tree into Texinfo files. List of tuples
162+
# (source start file, target name, title, author,
163+
# dir menu entry, description, category)
164+
texinfo_documents = [(
165+
source_start_file,
166+
subs.mantex["name"],
167+
subs.mantex["title"],
168+
author,
169+
subs.tex["dirmenu_entry"],
170+
subs.tex["description"],
171+
subs.tex["category"]),
172+
]
173+
174+
# Example configuration for intersphinx: refer to the Python standard library.
175+
intersphinx_mapping = {'python': ('https://docs.python.org/', None)}
176+
177+
numfig = True
178+
numfig_format = {'figure': 'Figure %s',
179+
'table': 'Table %s',
180+
'code-block': 'Code %s',
181+
'section': '%s',
182+
}
183+
numfig_secnum_depth = 2
184+
185+
def setup(app):
186+
app.add_css_file('css/custom.css')
187+
188+
try:
189+
html_context
190+
except NameError:
191+
html_context = dict()
192+
193+
html_context["display_lower_left"] = True
194+
195+
# Whether to show the version dropdown. If not set as environment variable, or environment variable
196+
# is Python-falsey, do not show it.
197+
version_dropdown = os.environ.get("version_dropdown")
198+
199+
if version_dropdown:
200+
html_context["current_version"] = os.environ["version_display_name"]
201+
202+
html_context["versions"] = []
203+
pages_root = os.environ["pages_root"]
204+
for this_version in VERSION_LIST:
205+
html_context["versions"].append([
206+
this_version.display_name,
207+
os.path.join(pages_root, this_version.subdir()),
208+
])

doc_builder/build_commands.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ def get_build_command(
7474
docker_name=None,
7575
warnings_as_warnings=False,
7676
docker_image=DEFAULT_DOCKER_IMAGE,
77+
conf_py_path=None,
78+
static_path=None,
79+
templates_path=None,
7780
):
7881
# pylint: disable=too-many-arguments,too-many-locals
7982
"""Return a string giving the build command.
@@ -94,6 +97,7 @@ def get_build_command(
9497
build_target=build_target,
9598
num_make_jobs=num_make_jobs,
9699
warnings_as_warnings=warnings_as_warnings,
100+
conf_py_path=conf_py_path,
97101
)
98102

99103
# But if we're using Docker, we have more work to do to create the command....
@@ -103,7 +107,9 @@ def get_build_command(
103107
# check this assumption below).
104108
docker_mountpoint = os.path.expanduser("~")
105109

106-
errmsg_if_not_under_mountpoint = "build_docs must be run from somewhere in your home directory"
110+
errmsg_if_not_under_mountpoint = (
111+
"build_docs must be run from somewhere in your home directory"
112+
)
107113
docker_workdir = _docker_path_from_local_path(
108114
local_path=run_from_dir,
109115
docker_mountpoint=docker_mountpoint,
@@ -129,6 +135,7 @@ def get_build_command(
129135
build_target=build_target,
130136
num_make_jobs=num_make_jobs,
131137
warnings_as_warnings=warnings_as_warnings,
138+
conf_py_path=conf_py_path,
132139
)
133140

134141
docker_command = [
@@ -151,7 +158,9 @@ def get_build_command(
151158
return docker_command
152159

153160

154-
def _get_make_command(build_dir, build_target, num_make_jobs, warnings_as_warnings):
161+
def _get_make_command(
162+
build_dir, build_target, num_make_jobs, warnings_as_warnings, conf_py_path
163+
):
155164
"""Return the make command to run (as a list)
156165
157166
Args:
@@ -162,11 +171,20 @@ def _get_make_command(build_dir, build_target, num_make_jobs, warnings_as_warnin
162171
builddir_arg = f"BUILDDIR={build_dir}"
163172
sphinxopts = "SPHINXOPTS="
164173
if not warnings_as_warnings:
165-
sphinxopts += "-W --keep-going"
174+
sphinxopts += "-W --keep-going "
175+
if conf_py_path:
176+
if not os.path.exists(conf_py_path):
177+
raise FileNotFoundError(f"--conf-py-path not found: '{conf_py_path}'")
178+
if not os.path.isdir(conf_py_path):
179+
conf_py_path = os.path.dirname(conf_py_path)
180+
sphinxopts += f"-c '{conf_py_path}' "
181+
sphinxopts = sphinxopts.rstrip()
166182
return ["make", sphinxopts, builddir_arg, "-j", str(num_make_jobs), build_target]
167183

168184

169-
def _docker_path_from_local_path(local_path, docker_mountpoint, errmsg_if_not_under_mountpoint):
185+
def _docker_path_from_local_path(
186+
local_path, docker_mountpoint, errmsg_if_not_under_mountpoint
187+
):
170188
"""Given a path on the local file system, return the equivalent path in Docker space
171189
172190
Args:

0 commit comments

Comments
 (0)