Skip to content

Commit d79df11

Browse files
authored
Merge pull request #368 from ExaWorks/docs_multiversion
Docs multiversion
2 parents 2a4a470 + 7085601 commit d79df11

File tree

12 files changed

+434
-22
lines changed

12 files changed

+434
-22
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ stylecheck:
4444
flake8 src tests
4545

4646
.PHONY: checks
47-
checks: typecheck stylecheck
47+
checks: typecheck stylecheck docs
4848

4949
.PHONY: docs
5050
docs:
@@ -56,7 +56,8 @@ docs:
5656
.PHONY: web-docs
5757
web-docs:
5858
rm -rf docs/.generated
59-
sphinx-build -W -b html -D html_theme='cloud' -D templates_path='_templates' docs docs/.web-build/
59+
rm -rf docs/.web-build
60+
PSIJ_WEB_DOCS=1 sphinx-multiversion docs docs/.web-build
6061

6162
.PHONY: style
6263
style:

docs/_templates/layout.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
{{ super() }}
1717
{% endblock %}
1818

19+
{% block rootrellink %}
20+
<li><a href="{{ pathto(theme_roottarget) }}">{{shorttitle|e}}</a>{% if versions %}{% include "../../web/_includes/versionselect.html" %}{% endif %}{{reldelim1}}</li>
21+
{% endblock %}
22+
23+
1924
{% block footer %}
2025
{{ super() }}
2126

docs/conf.py

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@
88
import sphinx_rtd_theme
99
from sphinx.ext.apidoc import main
1010

11+
web_docs = False
12+
if 'PSIJ_WEB_DOCS' in os.environ:
13+
web_docs = True
14+
1115
needs_sphinx = '1.6'
1216

1317
# Set Sphinx variables
1418
master_doc = 'index'
1519

1620
project = u'PSI/J'
1721
copyright = u'The ExaWorks Team'
18-
19-
html_theme = 'sphinx_rtd_theme'
20-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
22+
if web_docs:
23+
html_theme = 'cloud'
24+
else:
25+
html_theme = 'sphinx_rtd_theme'
26+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
2127
html_favicon = 'favicon.ico'
2228
autoclass_content = 'both'
2329
add_module_names = False
@@ -28,6 +34,25 @@
2834
('py:class', 'distutils.version.Version')
2935
]
3036

37+
if web_docs:
38+
templates_path = ['_templates']
39+
# Unfortunately sphinx-multiversion does not properly deal with
40+
# setting the title to the proper version. You either get some
41+
# default like "0.0.1" or you get whatever the current conf.py
42+
# sets (i.e., the latest version).
43+
# See, e.g., https://github.com/Holzhaus/sphinx-multiversion/issues/61
44+
#
45+
# But we already have the version selector that displays the version,
46+
# so we can display that where the broken version would otherwise
47+
# have appeared.
48+
html_title = "PSI/J"
49+
# Multi-version
50+
smv_branch_whitelist = '^matchmeifyoucan$'
51+
smv_remote_whitelist = None
52+
smv_released_pattern = r'^\d+\.\d+\.\d+(\..*)?$'
53+
smv_outputdir_format = 'v/{ref.name}'
54+
55+
3156
html_sidebars = {'**': ['globaltoc.html', 'relations.html', 'sourcelink.html', 'searchbox.html']}
3257

3358
# These are needed for the dhtml trickery
@@ -44,20 +69,29 @@
4469
'sphinx.ext.viewcode',
4570
]
4671

72+
if web_docs:
73+
extensions.append('sphinx_multiversion')
74+
4775
autodoc_typehints = "description"
4876
autodoc_typehints_format = "short"
4977

78+
release = None
79+
version = None
80+
src_dir = None
81+
82+
def read_version(docs_dir):
83+
global release, version, src_dir
84+
src_dir = os.path.abspath(os.path.join(docs_dir, '../src'))
5085

51-
script_dir = os.path.normpath(os.path.dirname(__file__))
52-
src_dir = os.path.abspath(os.path.join(script_dir, '../src'))
86+
sys.path.insert(0, src_dir)
5387

54-
print(src_dir + "/")
88+
import psij
89+
release = psij.__version__
90+
version = release
5591

56-
sys.path.insert(0, src_dir)
5792

58-
import psij
59-
release = psij.__version__
60-
version = release
93+
my_dir = os.path.normpath(os.path.dirname(__file__))
94+
read_version(my_dir)
6195

6296
intersphinx_mapping = {
6397
'python': ('https://docs.python.org/3', None),
@@ -69,10 +103,9 @@
69103
# Copied from https://github.com/readthedocs/readthedocs.org/issues/1139
70104

71105
# run api doc
72-
def run_apidoc(_):
73-
output_path = os.path.join(script_dir, '.generated')
74-
print(f"OUTPUT PATH = {output_path}")
75-
#exclusions = [os.path.join(src_dir, 'setup.py'),]
106+
def run_apidoc(sphinx):
107+
read_version(sphinx.srcdir) # this sets src_dir based on the version being compiled
108+
output_path = os.path.join(sphinx.srcdir, '.generated')
76109
main(['-f', '-o', output_path, src_dir])
77110

78111
# launch setup

requirements-docs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ six
1010
Sphinx==4.5.0
1111
sphinx_rtd_theme
1212
sphinx-tabs
13+
sphinx-multiversion
1314

1415
# For the web version of the docs
1516
cloud_sptheme == 1.10.1.post20200504175005

web/_includes/head.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@
1616
<link rel="stylesheet"
1717
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.4.0/styles/base16/tender.min.css">
1818
<script src="https://kit.fontawesome.com/0f2ef02e2b.js" crossorigin="anonymous"></script>
19+
<script src="{{ site.baseurl }}/versions.js"></script>
20+
<script src="{{ site.baseurl }}/versioning.js"></script>

web/_includes/versionselect.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div id="version-selector">
2+
<v-select :items="getSortedVersionLabels()" @change="setVersion" v-model="version"></v-select>
3+
</div>

web/_includes/vueinit.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
el: '#psij-app',
55
vuetify: new Vuetify(),
66
data: {
7-
maintabs: {{ page.tab }}
7+
maintabs: {{ page.tab }},
8+
version: getCurrentVersion()
9+
},
10+
methods: {
11+
getSortedVersionLabels: getSortedVersionLabels,
12+
setVersion: setVersion
813
}
914
});
1015

web/build.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,26 @@ if [ "$1" != "--quick" ]; then
1818
cp -r docs/.web-build/. web-build/docs/
1919
fi
2020

21-
cp -r web/. web-build/
22-
cp web/*.css web-build/docs/
21+
22+
cp -r web/_layouts/ web-build/
23+
cp -r web/_includes/ web-build/
24+
25+
echo -n "var DOC_VERSIONS_RAW = [" >web-build/versions.js
26+
for V in `ls web-build/docs/v`; do
27+
echo "Patching version $V"
28+
cp -r web/docs/_static web-build/docs/v/$V/
29+
30+
echo "\"$V\", " >>web-build/versions.js
31+
done
32+
echo "]" >>web-build/versions.js
33+
34+
for F in `ls web/*`; do
35+
if [ -f "$F" ]; then
36+
cp "$F" web-build/
37+
fi
38+
done
39+
40+
cp web/docs/index.html web-build/docs/
2341

2442
rm -f web-build/*.sh
25-
rm -f web-build/README
43+
rm -f web-build/README

web/docs/_static/cloud.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ ul, ol {
4040

4141
div.relbar-top {
4242
background-color: #e0e0e0;
43+
border-bottom: 1px solid var(--color-fg-lines);
4344
}
4445

4546

@@ -112,7 +113,7 @@ div.body {
112113
}
113114

114115
div.sphinxsidebar {
115-
margin-top: 32pt;
116+
margin-top: 4pt;
116117
width: 3in;
117118
font-size: 90%;
118119
line-height: 1.25em;
@@ -123,7 +124,7 @@ div.document.sidebar-hidden div.sphinxsidebar {
123124
}
124125

125126
div.sphinxsidebarwrapper {
126-
padding: 1em 0 0 10px;
127+
padding: 0 0 0 10px;
127128
}
128129

129130
div.sphinxsidebar h3, div.sphinxsidebar h4 {

web/docs/index.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: PSI/J - Python
3+
layout: raw
4+
tab: 2
5+
---
6+
7+
<!DOCTYPE html>
8+
<html>
9+
<head>
10+
<title>Documentation - PSI/J - Python</title>
11+
<script src="{{ site.baseurl }}/versions.js"></script>
12+
<script src="{{ site.baseurl }}/versioning.js"></script>
13+
</head>
14+
<body>
15+
<script type="application/javascript">
16+
var latest = getLatestVersion();
17+
document.write("Redirecting to <a href=\"v/" + latest + "\">Version " + latest + " documentation</a>");
18+
var loc = window.location.href;
19+
if (loc.endsWith(".html")) {
20+
loc = loc.substring(0, loc.lastIndexOf("/"));
21+
}
22+
if (loc.endsWith("/")) {
23+
loc = loc.substring(0, loc.length - 1);
24+
}
25+
window.location = loc + "/v/" + latest + "/";
26+
</script>
27+
</body>
28+
</html>
29+

0 commit comments

Comments
 (0)