|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | # |
3 | | -# clmdoc documentation build configuration file, created by |
4 | | -# sphinx-quickstart on Thu Feb 23 17:14:30 2017. |
5 | | -# |
6 | 3 | # This file is execfile()d with the current directory set to its |
7 | 4 | # containing dir. |
8 | 5 | # |
|
18 | 15 | # |
19 | 16 | import os |
20 | 17 | import sys |
21 | | -# Note that we need a specific version of sphinx_rtd_theme. This can be obtained with: |
22 | | -# pip install git+https://github.com/esmci/sphinx_rtd_theme.git@version-dropdown-with-fixes |
23 | 18 | import sphinx_rtd_theme |
24 | | -# sys.path.insert(0, os.path.abspath('.')) |
| 19 | + |
| 20 | +# Assumes you have substitutions.py on your path |
| 21 | +# pylint: disable=wrong-import-position |
| 22 | +dir2add = os.path.join(os.path.dirname(__file__)) |
| 23 | +print(dir2add) |
| 24 | +sys.path.insert(0, dir2add) |
| 25 | +import substitutions as subs # pylint: disable=import-error |
| 26 | +from version_list import VERSION_LIST |
25 | 27 |
|
26 | 28 |
|
27 | 29 | # -- General configuration ------------------------------------------------ |
|
37 | 39 | 'sphinx.ext.autodoc', |
38 | 40 | 'sphinx.ext.todo', |
39 | 41 | 'sphinx.ext.coverage', |
40 | | - 'sphinx.ext.imgmath', |
41 | | - 'sphinx.ext.githubpages'] |
| 42 | + 'sphinx.ext.githubpages', |
| 43 | + 'sphinx_mdinclude', |
| 44 | + ] |
42 | 45 |
|
43 | 46 | # Add any paths that contain templates here, relative to this directory. |
44 | 47 | templates_path = ['_templates'] |
45 | 48 |
|
46 | 49 | # The suffix(es) of source filenames. |
47 | 50 | # You can specify multiple suffix as a list of string: |
48 | 51 | # |
49 | | -# source_suffix = ['.rst', '.md'] |
50 | | -source_suffix = '.rst' |
| 52 | +source_suffix = ['.rst', '.md'] |
| 53 | +# source_suffix = '.rst' |
51 | 54 |
|
52 | 55 | # The master toctree document. |
53 | | -master_doc = 'index' |
| 56 | +source_start_file = 'index' |
54 | 57 |
|
55 | | -# General information about the project. |
56 | | -project = u'ctsm' |
57 | | -copyright = u'2020, UCAR' |
58 | | -author = u'' |
59 | | - |
60 | | -# The version info for the project you're documenting, acts as replacement for |
61 | | -# |version| and |release|, also used in various other places throughout the |
62 | | -# built documents. |
63 | | -# |
64 | | -# The short X.Y version. |
65 | | -version = u'CLM5.0' |
66 | | -# The full version, including alpha/beta/rc tags. |
67 | | -release = u'release-clm5.0' |
68 | | -# CTSM-specific: version label used at the top of some pages. |
69 | | -version_label = 'CLM5.0 (CESM2.1)' |
| 58 | +# Save standard Sphinx substitution vars separately |
| 59 | +project = subs.project |
| 60 | +copyright = subs.copyright # pylint: disable=redefined-builtin |
| 61 | +author = subs.author |
| 62 | +version = subs.version |
| 63 | +release = subs.release |
70 | 64 |
|
71 | 65 | # version_label is not a standard sphinx variable, so we need some custom rst to allow |
72 | 66 | # pages to use it. We need a separate replacement for the bolded version because it |
73 | 67 | # doesn't work to have variable replacements within formatting. |
74 | 68 | rst_epilog = """ |
75 | 69 | .. |version_label| replace:: {version_label} |
76 | 70 | .. |version_label_bold| replace:: **{version_label}** |
77 | | -""".format(version_label=version_label) |
| 71 | +""".format(version_label=subs.version_label) |
78 | 72 |
|
79 | 73 | # The language for content autogenerated by Sphinx. Refer to documentation |
80 | 74 | # for a list of supported languages. |
81 | 75 | # |
82 | 76 | # This is also used if you do content translation via gettext catalogs. |
83 | 77 | # Usually you set "language" from the command line for these cases. |
84 | | -language = None |
| 78 | +language = "en" |
85 | 79 |
|
86 | 80 | # List of patterns, relative to source directory, that match files and |
87 | 81 | # directories to ignore when looking for source files. |
|
94 | 88 | # If true, `todo` and `todoList` produce output, else they produce nothing. |
95 | 89 | todo_include_todos = True |
96 | 90 |
|
97 | | -imgmath_image_format = 'svg' |
98 | | - |
99 | 91 | # -- Options for HTML output ---------------------------------------------- |
100 | 92 |
|
101 | 93 | # The theme to use for HTML and HTML Help pages. See the documentation for |
|
106 | 98 | # Theme options are theme-specific and customize the look and feel of a theme |
107 | 99 | # further. For a list of options available for each theme, see the |
108 | 100 | # documentation. |
109 | | -# |
110 | | -# The 'versions' option needs to have at least two versions to work, but it doesn't need |
111 | | -# to have all versions: others will be added dynamically. Note that this maps from version |
112 | | -# names to html links. The current version can link to the current location (i.e., do |
113 | | -# nothing). For the other version, we just add a place-holder; its name and value are |
114 | | -# unimportant because these versions will get replaced dynamically. |
115 | | -html_theme_options = {} |
116 | | -html_theme_options['versions'] = {version: ''} |
117 | | -html_theme_options['versions']['[placeholder]'] = '' |
118 | 101 |
|
119 | 102 | # Add any paths that contain custom static files (such as style sheets) here, |
120 | 103 | # relative to this directory. They are copied after the builtin static files, |
|
124 | 107 |
|
125 | 108 | # -- Options for HTMLHelp output ------------------------------------------ |
126 | 109 |
|
127 | | -# Output file base name for HTML help builder. |
128 | | -htmlhelp_basename = 'clmdocdoc' |
| 110 | +if getattr(subs, "htmlhelp", False): |
| 111 | + htmlhelp_basename = subs.htmlhelp["basename"] |
129 | 112 |
|
130 | 113 |
|
131 | 114 | # -- Options for LaTeX output --------------------------------------------- |
132 | | - |
133 | | -latex_elements = { |
134 | | - # The paper size ('letterpaper' or 'a4paper'). |
135 | | - # |
136 | | - # 'papersize': 'letterpaper', |
137 | | - |
138 | | - # The font size ('10pt', '11pt' or '12pt'). |
139 | | - # |
140 | | - # 'pointsize': '10pt', |
141 | | - |
142 | | - # Additional stuff for the LaTeX preamble. |
143 | | - # |
144 | | - 'preamble': '\\usepackage{hyperref}', |
145 | | - |
146 | | - 'fncychap': '\\usepackage[Conny]{fncychap}', |
147 | | - |
148 | | - # Latex figure (float) alignment |
149 | | - # |
150 | | - # 'figure_align': 'htbp', |
151 | | -} |
152 | | - |
153 | | -# Grouping the document tree into LaTeX files. List of tuples |
154 | | -# (source start file, target name, title, |
155 | | -# author, documentclass [howto, manual, or own class]). |
156 | | -latex_documents = [(master_doc, 'clmdoc.tex', u'CLM5 Documentation', '', 'manual'),] |
157 | | - |
158 | | - |
159 | | -# -- Options for manual page output --------------------------------------- |
160 | | - |
161 | | -# One entry per manual page. List of tuples |
162 | | -# (source start file, name, description, authors, manual section). |
163 | | -man_pages = [ |
164 | | - (master_doc, 'clmdoc', u'clmdoc Documentation', |
165 | | - [author], 1) |
166 | | -] |
167 | | - |
168 | | - |
169 | | -# -- Options for Texinfo output ------------------------------------------- |
170 | | - |
171 | | -# Grouping the document tree into Texinfo files. List of tuples |
172 | | -# (source start file, target name, title, author, |
173 | | -# dir menu entry, description, category) |
174 | | -texinfo_documents = [ |
175 | | - (master_doc, 'clmdoc', u'clmdoc Documentation', |
176 | | - author, 'clmdoc', 'One line description of project.', |
177 | | - 'Miscellaneous'), |
178 | | -] |
179 | | - |
180 | | - |
181 | | - |
| 115 | +if getattr(subs, "latex", False): |
| 116 | + |
| 117 | + latex_elements = { |
| 118 | + # The paper size ('letterpaper' or 'a4paper'). |
| 119 | + # |
| 120 | + # 'papersize': 'letterpaper', |
| 121 | + |
| 122 | + # The font size ('10pt', '11pt' or '12pt'). |
| 123 | + # |
| 124 | + # 'pointsize': '10pt', |
| 125 | + |
| 126 | + # Additional stuff for the LaTeX preamble. |
| 127 | + # |
| 128 | + 'preamble': '\\usepackage{hyperref}', |
| 129 | + |
| 130 | + 'fncychap': '\\usepackage[Conny]{fncychap}', |
| 131 | + |
| 132 | + # Latex figure (float) alignment |
| 133 | + # |
| 134 | + # 'figure_align': 'htbp', |
| 135 | + } |
| 136 | + |
| 137 | + # Grouping the document tree into LaTeX files. List of tuples |
| 138 | + # (source start file, target name, title, |
| 139 | + # author, documentclass [howto, manual, or own class]). |
| 140 | + latex_documents = [( |
| 141 | + source_start_file, |
| 142 | + subs.latex["target_name"], |
| 143 | + subs.latex["title"], |
| 144 | + author, |
| 145 | + subs.latex["category"], |
| 146 | + )] |
| 147 | + |
| 148 | + |
| 149 | +# Options for manual page and Texinfo output |
| 150 | +if getattr(subs, "mantex", False): |
| 151 | + |
| 152 | + # One entry per manual page. List of tuples |
| 153 | + # (source start file, name, title, authors, manual section). |
| 154 | + man_pages = [ |
| 155 | + (source_start_file, subs.mantex["name"], subs.mantex["title"], [author], 1), |
| 156 | + ] |
| 157 | + |
| 158 | + if getattr(subs, "tex", False): |
| 159 | + # Grouping the document tree into Texinfo files. List of tuples |
| 160 | + # (source start file, target name, title, author, |
| 161 | + # dir menu entry, description, category) |
| 162 | + texinfo_documents = [( |
| 163 | + source_start_file, |
| 164 | + subs.mantex["name"], |
| 165 | + subs.mantex["title"], |
| 166 | + author, |
| 167 | + subs.tex["dirmenu_entry"], |
| 168 | + subs.tex["description"], |
| 169 | + subs.tex["category"]), |
| 170 | + ] |
182 | 171 |
|
183 | 172 | # Example configuration for intersphinx: refer to the Python standard library. |
184 | | -intersphinx_mapping = {'https://docs.python.org/': None} |
| 173 | +intersphinx_mapping = {'python': ('https://docs.python.org/', None)} |
185 | 174 |
|
186 | 175 | numfig = True |
187 | 176 | numfig_format = {'figure': 'Figure %s', |
|
192 | 181 | numfig_secnum_depth = 2 |
193 | 182 |
|
194 | 183 | def setup(app): |
195 | | - app.add_stylesheet('css/custom.css') |
| 184 | + app.add_css_file('css/custom.css') |
| 185 | + |
| 186 | +try: |
| 187 | + html_context |
| 188 | +except NameError: |
| 189 | + html_context = dict() |
| 190 | + |
| 191 | +html_context["display_lower_left"] = True |
| 192 | + |
| 193 | +# Whether to show the version dropdown. If not set as environment variable, or environment variable |
| 194 | +# is Python-falsey, do not show it. |
| 195 | +version_dropdown = os.environ.get("version_dropdown") |
| 196 | + |
| 197 | +if version_dropdown: |
| 198 | + html_context["current_version"] = os.environ["version_display_name"] |
| 199 | + |
| 200 | + html_context["versions"] = [] |
| 201 | + pages_root = os.environ["pages_root"] |
| 202 | + for this_version in VERSION_LIST: |
| 203 | + html_context["versions"].append([ |
| 204 | + this_version.display_name, |
| 205 | + os.path.join(pages_root, this_version.subdir()), |
| 206 | + ]) |
0 commit comments