Skip to content

Commit 2d2b077

Browse files
authored
MAINT: Discontinue use of sphinxcontrib-versioning (#78)
* wip * fix: new approach to multiversioned docs This PR relies on a little javascript to create the dropdown menu to select the version. The sphinxcontrib-versioning package is not anymore used, and the different versions of documentation are just accumulated on the `gh-pages` branch of the repo. Therefore, all versions are not built anymore with every build. The new approach completely decouples the generation of versions of documentation from the chooser, allowing us flexibility to change themes or completely change the structure, so long the new theme or documentation scheme is capable of interpreting the `versions.json` file at the root of `gh-pages`.
1 parent 96b9f1f commit 2d2b077

File tree

6 files changed

+93
-115
lines changed

6 files changed

+93
-115
lines changed

.circleci/config.yml

Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,3 @@
1-
docs_deploy: &docs
2-
docker:
3-
- image: node:8.10.0
4-
steps:
5-
- checkout
6-
- attach_workspace:
7-
at: docs/_build
8-
- run:
9-
name: Disable jekyll builds
10-
command: touch docs/_build/html/.nojekyll
11-
- run:
12-
name: Install and configure dependencies
13-
command: |
14-
npm install -g --silent [email protected]
15-
git config user.email "[email protected]"
16-
git config user.name "ci-build"
17-
- add_ssh_keys:
18-
fingerprints:
19-
- "ae:95:0c:cc:09:84:64:99:92:82:b7:b5:f4:a7:e9:23"
20-
- run:
21-
name: Deploy docs to gh-pages branch
22-
command: gh-pages --dotfiles --message "doc(update) [skip ci]" --dist docs/_build/html
23-
241
version: 2
252
jobs:
263
tests:
@@ -149,14 +126,6 @@ jobs:
149126
- FSLOUTPUTTYPE: NIFTI
150127
- SUBJECTS_DIR: /tmp/subjects
151128
steps:
152-
- restore_cache:
153-
keys:
154-
- docs-v1-{{ .Branch }}-{{ .Revision }}
155-
- docs-v1-{{ .Branch }}-
156-
- docs-v1-master
157-
- docs-v1-
158-
paths:
159-
- ./docs/_build/_html
160129
- checkout
161130
- run:
162131
name: Create subjects folder
@@ -173,30 +142,9 @@ jobs:
173142
name: Build only this commit
174143
command: |
175144
python setup.py --version
176-
make -C docs SPHINXOPTS="-W" BUILDDIR="_build/no_version_html" html
145+
make -C docs SPHINXOPTS="-W" BUILDDIR="/docs" CURBRANCH="${CIRCLE_TAG}" html
177146
- store_artifacts:
178-
path: ./docs/_build/no_version_html
179-
- run:
180-
name: Generate Versioned Docs
181-
command: |
182-
set +e
183-
force_versioned="$( git log --format=oneline -n 1 $CIRCLE_SHA1 | grep -i -E '\[docs?[ _]?versions?\]' )"
184-
set -e
185-
if [[ "x${CIRCLE_TAG}" = "x" && "${CIRCLE_BRANCH}" != "master" && "x${force_versioned}" = "x" ]]; then
186-
echo "Not a tag or master branch - skipping versioned docs."
187-
circleci step halt
188-
else
189-
make -f ./docs/Makefile versioned CURBRANCH=${CIRCLE_TAG:-$CIRCLE_BRANCH}
190-
fi
191-
- save_cache:
192-
key: docs-v1-{{ .Branch }}-{{ .Revision }}
193-
paths:
194-
- ./docs/_build/_html
195-
- persist_to_workspace:
196-
root: docs/_build
197-
paths: html
198-
- store_artifacts:
199-
path: ./docs/_build/html
147+
path: /docs/
200148

201149
deploy_pypi:
202150
docker:
@@ -224,12 +172,6 @@ jobs:
224172
twine check dist/*
225173
twine upload dist/*
226174
227-
deploy_docs_tag:
228-
<<: *docs
229-
230-
deploy_docs_master:
231-
<<: *docs
232-
233175
workflows:
234176
version: 2
235177
build_test_deploy:
@@ -243,7 +185,7 @@ workflows:
243185
only: /.*/
244186
- deploy_pypi:
245187
requires:
246-
- deploy_docs_tag
188+
- build_docs
247189
filters:
248190
branches:
249191
ignore: /.*/
@@ -258,26 +200,6 @@ workflows:
258200
tags:
259201
only: /.*/
260202

261-
- deploy_docs_master:
262-
requires:
263-
- tests
264-
- build_docs
265-
filters:
266-
branches:
267-
only: /master/
268-
tags:
269-
ignore: /.*/
270-
271-
- deploy_docs_tag:
272-
requires:
273-
- tests
274-
- build_docs
275-
filters:
276-
branches:
277-
ignore: /.*/
278-
tags:
279-
only: /.*/
280-
281203
nightly:
282204
triggers:
283205
- schedule:

docs/Makefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,17 @@ clean:
5555
rm -rf api/*
5656

5757
html:
58-
PYTHONPATH=$(PYTHONPATH) $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
58+
mkdir -p $(BUILDDIR)
59+
PYTHONPATH=$(PYTHONPATH) $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/$(CURBRANCH)
5960
@echo
60-
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
61+
@echo "Build finished. The HTML pages are in $(BUILDDIR)/."
62+
63+
64+
versioned:
65+
mkdir -p $(BUILDDIR)
66+
PYTHONPATH=$(PYTHONPATH) sphinx-multiversion -v . $(BUILDDIR)/
67+
@echo
68+
@echo "Multi-version build finished. The HTML pages are in $(BUILDDIR)/."
6169

6270
dirhtml:
6371
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@@ -180,6 +188,3 @@ pseudoxml:
180188
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
181189
@echo
182190
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
183-
184-
versioned:
185-
PYTHONPATH=$(PYTHONPATH) sphinx-versioning -vv -l ./docs/conf.py build -r $(CURBRANCH) ./docs/ docs/$(BUILDDIR)/html/

docs/_templates/versions.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
<span class="fa fa-book"> Other Versions</span>
4+
v: {{ version }}
5+
<span class="fa fa-caret-down"></span>
6+
</span>
7+
<div id="version-switch" class="rst-other-versions">
8+
<dt id="v-tags"></dt>
9+
<dt id="v-branches"></dt>
10+
</div>
11+
</div>
12+
13+
<script type="text/javascript">
14+
$(document).ready(function() {
15+
var pathname = window.location.pathname;
16+
var cur_ver = "/{{ current_version.name if current_version else 'master' }}/"
17+
var relpath = pathname.substring(pathname.indexOf(cur_ver) + 1).replace(/\/$/, '');
18+
var levels = relpath.split("/").length - 1
19+
if ( levels == 0 ) {
20+
levels = 1
21+
relpath += "/"
22+
}
23+
var versions_file = "../".repeat(levels) + "versions.json"
24+
relpath = "../".repeat(levels) + relpath
25+
console.log(`relative path: "${relpath}"`)
26+
27+
$.getJSON(versions_file, function (data) {
28+
29+
$.each(data["tags"], function( i, val ) {
30+
$("#v-tags").append("<dd><a href=\"" + relpath.replace(cur_ver, "/" + val + "/") + "\">" + val + "</a></dd>")
31+
});
32+
$("#v-branches").append("<dd><a href=\"" + relpath.replace(cur_ver, "/" + data["tags"][data["tags"].length - 1]+ "/") + "\">latest</a></dd>")
33+
$("#v-branches").append("<dd><a href=\"" + relpath.replace(cur_ver, "/master/") + "\">dev</a></dd>")
34+
});
35+
});
36+
</script>

docs/conf.py

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,36 @@
1010
# add these directories to sys.path here. If the directory is relative to the
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
#
13-
import os
14-
import sys
1513
from packaging.version import Version
16-
1714
from templateflow import __version__, __copyright__, __packagename__
1815

19-
sys.path.append(os.path.abspath("sphinxext"))
20-
2116
# -- Project information -----------------------------------------------------
2217
project = __packagename__
2318
copyright = __copyright__
2419
author = "The TemplateFlow Developers"
2520

26-
# The short X.Y version
27-
version = Version(__version__).public
2821
# The full version, including alpha/beta/rc tags
2922
release = __version__
3023

24+
# The short X.Y version
25+
version = (
26+
__version__ if Version(release).public == release
27+
else f"dev ({release.partition('+')[0]})"
28+
)
3129

3230
# -- General configuration ---------------------------------------------------
3331
extensions = [
3432
"sphinx.ext.autodoc",
33+
"sphinx.ext.coverage",
3534
"sphinx.ext.doctest",
35+
"sphinx.ext.githubpages",
36+
"sphinx.ext.ifconfig",
3637
"sphinx.ext.intersphinx",
37-
"sphinx.ext.coverage",
3838
"sphinx.ext.mathjax",
39-
"sphinx.ext.ifconfig",
39+
"sphinx.ext.napoleon",
4040
"sphinx.ext.viewcode",
41-
"sphinx.ext.githubpages",
4241
"sphinxcontrib.apidoc",
43-
"sphinxcontrib.napoleon",
42+
"sphinx_multiversion",
4443
]
4544

4645
autodoc_mock_imports = [
@@ -55,16 +54,17 @@
5554
"svgutils",
5655
"transforms3d",
5756
]
57+
autodoc_autoreload = True
5858

5959
# Accept custom section names to be parsed for numpy-style docstrings
6060
# of parameters.
6161
# Requires pinning sphinxcontrib-napoleon to a specific commit while
6262
# https://github.com/sphinx-contrib/napoleon/pull/10 is merged.
63-
napoleon_use_param = False
64-
napoleon_custom_sections = [
65-
("Inputs", "Parameters"),
66-
("Outputs", "Parameters"),
67-
]
63+
# napoleon_use_param = False
64+
# napoleon_custom_sections = [
65+
# ("Inputs", "Parameters"),
66+
# ("Outputs", "Parameters"),
67+
# ]
6868

6969
# Add any paths that contain templates here, relative to this directory.
7070
templates_path = ["_templates"]
@@ -213,14 +213,31 @@
213213

214214
apidoc_module_dir = "../templateflow"
215215
apidoc_output_dir = "api"
216-
apidoc_excluded_paths = ["conftest.py", "*/tests/*", "tests/*", "data/*"]
216+
apidoc_excluded_paths = [
217+
"conftest.py",
218+
"*/tests/*",
219+
"tests/*",
220+
"data/*",
221+
]
217222
apidoc_separate_modules = True
218223
apidoc_extra_args = ["--module-first", "-d 1", "-T"]
219224

220225
# -- Options for intersphinx extension ---------------------------------------
221226

222227
# Example configuration for intersphinx: refer to the Python standard library.
223-
intersphinx_mapping = {"https://docs.python.org/": None}
228+
intersphinx_mapping = {
229+
"bids": ("https://bids-standard.github.io/pybids/", None),
230+
"matplotlib": ("https://matplotlib.org/", None),
231+
"nibabel": ("https://nipy.org/nibabel/", None),
232+
"nipype": ("https://nipype.readthedocs.io/en/latest/", None),
233+
"numpy": ("https://numpy.org/doc/stable/", None),
234+
"pandas": ("http://pandas.pydata.org/pandas-docs/dev", None),
235+
"python": ("https://docs.python.org/3/", None),
236+
"scipy": ("https://docs.scipy.org/doc/scipy/reference", None),
237+
}
224238

225239
# -- Options for versioning extension ----------------------------------------
226-
scv_show_banner = True
240+
smv_branch_whitelist = r"^master$"
241+
smv_tag_whitelist = r"^\d+\.\d+\.\d+(?!rc|dev).*$"
242+
smv_released_pattern = r'^tags/.*$'
243+
smv_rebuild_tags = False

docs/requirements.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
git+https://github.com/AleksandarPetrov/napoleon.git@0dc3f28a309ad602be5f44a9049785a1026451b3#egg=sphinxcontrib-napoleon
2-
git+https://github.com/rwblair/sphinxcontrib-versioning.git@39b40b0b84bf872fc398feff05344051bbce0f63#egg=sphinxcontrib-versioning
31
nbsphinx
42
packaging
53
pybids>=0.11.1
64
pydot>=1.2.3
75
pydotplus
86
requests
97
sphinx-argparse
10-
sphinx>=2.1.2
11-
sphinx_rtd_theme
12-
sphinxcontrib-apidoc ~= 0.3.0
8+
sphinx ~= 4.0
9+
sphinx_rtd_theme >= 0.4.3
10+
sphinxcontrib-apidoc
11+
sphinx_multiversion
1312
tqdm

setup.cfg

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ doc =
6161
pydot>=1.2.3
6262
pydotplus
6363
sphinx-argparse
64-
sphinx>=2.1.2
65-
sphinx_rtd_theme
66-
sphinxcontrib-apidoc ~= 0.3.0
67-
sphinxcontrib-napoleon
68-
sphinxcontrib-versioning
64+
sphinx ~= 4.0
65+
sphinx_rtd_theme >= 0.4.3
66+
sphinxcontrib-apidoc
67+
sphinx_multiversion
6968
docs =
7069
%(doc)s
7170
test =

0 commit comments

Comments
 (0)