Skip to content

Commit 4a0bb52

Browse files
committed
[no ci] docs: change theme to PyData Sphinx theme
1 parent 4c53138 commit 4a0bb52

File tree

8 files changed

+64
-42
lines changed

8 files changed

+64
-42
lines changed

docsrc/poly.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime
22
import logging
33
from pathlib import Path
4-
from docsrc.polyversion_patches import DynamicPip, CustomDriver
4+
from docsrc.polyversion_patches import DynamicPip, CustomDriver, PyDataVersionEncoder
55

66
from sphinx_polyversion.api import apply_overrides
77
from sphinx_polyversion.git import Git, GitRef, GitRefType, file_predicate, refs_by_type
@@ -50,7 +50,7 @@
5050
"numpydoc",
5151
"myst-nb",
5252
"sphinx_design",
53-
"sphinx-book-theme",
53+
"pydata-sphinx-theme",
5454
"sphinxcontrib-bibtex",
5555
"sphinx-polyversion==1.1.0",
5656
]
@@ -162,6 +162,7 @@ async def selector(rev, keys):
162162
pre_cmd=["python", root / src / "pre-build.py", Placeholder.SOURCE_DIR],
163163
),
164164
env=ENVIRONMENT,
165+
encoder=PyDataVersionEncoder(),
165166
selector=selector,
166167
template_dir=root / src / "polyversion/templates",
167168
static_dir=root / src / "polyversion/static",

docsrc/polyversion_patches.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import json
23
import logging
34
import os
45
from pathlib import Path
@@ -8,6 +9,9 @@
89
from sphinx_polyversion.builder import BuildError
910
from sphinx_polyversion.driver import DefaultDriver
1011
from sphinx_polyversion.pyvenv import Pip
12+
from sphinx_polyversion.json import JSONable
13+
14+
from typing import Iterator
1115

1216
import tempfile
1317

@@ -64,6 +68,35 @@ async def __aenter__(self):
6468
return self
6569

6670

71+
class PyDataVersionEncoder(json.JSONEncoder):
72+
"""Encoder to turn list of built GitRefs into a version.json consumable by Sphinx."""
73+
74+
def transform(self, o: JSONable):
75+
output = []
76+
processed_names = []
77+
for ref in o:
78+
if ref.name in processed_names:
79+
continue
80+
output.append(
81+
{
82+
"name": ref.name,
83+
"version": ref.name,
84+
"url": f"/{ref.name}",
85+
}
86+
)
87+
processed_names.append(ref.name)
88+
# do not use cast for performance reasons
89+
return output
90+
91+
def __call__(self, o: JSONable):
92+
return self.transform(o)
93+
94+
def iterencode(self, o: JSONable, _one_shot: bool = False) -> Iterator[str]:
95+
"""Encode an object."""
96+
# called for every top level object to encode
97+
return super().iterencode(self.transform(o), _one_shot)
98+
99+
67100
class CustomDriver(DefaultDriver):
68101
"""DefaultDriver which does not copy venvs for local builds.
69102
@@ -101,9 +134,10 @@ async def get_unignored_files(directory: Path) -> list[Path]:
101134
for filename in files:
102135
source = self.root / filename
103136
target = path / filename
104-
target.parent.mkdir(parents=True, exist_ok=True)
105-
if not target.exists():
106-
shutil.copy2(source, target, follow_symlinks=False)
137+
if source.exists():
138+
target.parent.mkdir(parents=True, exist_ok=True)
139+
if not target.exists():
140+
shutil.copy2(source, target, follow_symlinks=False)
107141
except CalledProcessError:
108142
logger.warning("Could not list un-ignored files using git. Copying full working directory...")
109143
shutil.copytree(self.root, path, symlinks=True, dirs_exist_ok=True)
19.3 KB
Loading

docsrc/source/_static/custom.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,3 @@
2020
.bd-sidebar-primary div#rtd-footer-container {
2121
margin: 0;
2222
}
23-
24-
ul.bd-breadcrumbs {
25-
margin-top: -1rem;
26-
margin-bottom: 0.5rem;
27-
}

docsrc/source/_templates/layout.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

docsrc/source/conf.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
]
5959

6060
intersphinx_mapping = {
61-
"python": ("https://docs.python.org/{.major}".format(sys.version_info), None),
61+
"python": ("https://docs.python.org/3", None),
6262
"numpy": ("https://numpy.org/doc/stable", None),
6363
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
6464
"matplotlib": ("https://matplotlib.org/", None),
@@ -106,7 +106,7 @@
106106
# The theme to use for HTML and HTML Help pages. See the documentation for
107107
# a list of builtin themes.
108108
#
109-
html_theme = "sphinx_book_theme"
109+
html_theme = "pydata_sphinx_theme"
110110
html_title = "BayesFlow: Amortized Bayesian Inference"
111111

112112
# Add any paths that contain custom _static files (such as style sheets) here,
@@ -116,27 +116,29 @@
116116
html_css_files = ["custom.css"]
117117
html_show_sourcelink = False
118118
html_theme_options = {
119-
"repository_url": "https://github.com/bayesflow-org/bayesflow",
120-
"repository_branch": current,
121119
"use_edit_page_button": True,
122-
"use_issues_button": True,
123-
"use_repository_button": True,
124-
"use_download_button": True,
125-
"logo": {"alt-text": "BayesFlow"},
120+
"logo": {
121+
"alt-text": "BayesFlow",
122+
"image_light": "_static/bayesflow_hor.png",
123+
"image_dark": "_static/bayesflow_hor_dark.png",
124+
},
125+
"navbar_center": ["version-switcher", "navbar-nav"],
126+
"switcher": {
127+
"json_url": "/versions.json",
128+
"version_match": current,
129+
},
130+
"check_switcher": False,
131+
}
132+
html_context = {
133+
"github_url": "https://github.com", # or your GitHub Enterprise site
134+
"github_user": "bayesflow-org",
135+
"github_repo": "bayesflow",
136+
"github_version": current,
137+
"doc_path": "docsrc",
126138
}
127139
html_logo = "_static/bayesflow_hor.png"
128140
html_favicon = "_static/bayesflow_hex.ico"
129141
html_baseurl = "https://www.bayesflow.org/"
130-
html_js_files = ["https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"]
131-
html_sidebars = {
132-
"**": [
133-
"navbar-logo.html",
134-
"icon-links.html",
135-
"search-button-field.html",
136-
"sbt-sidebar-nav.html",
137-
"versioning.html",
138-
],
139-
}
140142

141143
todo_include_todos = True
142144

docsrc/source/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ Indices
117117
:titlesonly:
118118
:hidden:
119119

120-
self
121120
examples
122121
api/bayesflow
123122
about
@@ -126,6 +125,7 @@ Indices
126125
.. toctree::
127126
:maxdepth: 1
128127
:caption: Development
128+
:hidden:
129129

130-
contributing
131-
development/index
130+
Contributing <contributing>
131+
Developer docs <development/index>

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ docs = [
3939
"numpydoc",
4040
"myst-nb",
4141
"sphinx_design",
42-
"sphinx-book-theme",
42+
"pydata-sphinx-theme",
4343
"sphinxcontrib-bibtex",
4444
"sphinx-polyversion==1.1.0",
4545
]

0 commit comments

Comments
 (0)