Skip to content

Commit ae3ef2a

Browse files
authored
Upgrade docs build (#241)
* Improve build setup for docs * update pydata theme options * Add README for docs folder * Fix demo notebook build * Finish build setup * update git workflow * add timeout to workflow * add timeout also to docs build * switch build back to sphinx for gh actions * attempt to fix build workflow * update to sphinx-build * fix build workflow * fix indent error * fix build system * revert demos to main * increase timeout to 30
1 parent b2357fd commit ae3ef2a

File tree

13 files changed

+149
-112
lines changed

13 files changed

+149
-112
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ tests/
55
third_party/
66
tools/
77
PKGBUILD
8+
9+
!docs/requirements.txt

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010

1111
jobs:
1212
build:
13+
timeout-minutes: 30
1314
strategy:
1415
fail-fast: true
1516
matrix:

.github/workflows/docs.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ jobs:
5757
path: docs/source/demo_notebooks
5858
ref: main
5959

60-
- name: Set up Python ${{ matrix.python-version }}
60+
- name: Set up Python 3.10
6161
uses: actions/setup-python@v5
6262
with:
63-
python-version: ${{ matrix.python-version }}
63+
python-version: "3.10"
6464

6565
- name: Install package
6666
run: |
@@ -69,17 +69,21 @@ jobs:
6969
# as of 29/10/23. Ubuntu 22.04 which is used for ubuntu-latest only has an
7070
# old pandoc version (2.9.). We will hence install the latest version manually.
7171
# previou: sudo apt-get install -y pandoc
72-
wget https://github.com/jgm/pandoc/releases/download/3.1.9/pandoc-3.1.9-1-amd64.deb
73-
sudo dpkg -i pandoc-3.1.9-1-amd64.deb
74-
rm pandoc-3.1.9-1-amd64.deb
75-
pip install torch --extra-index-url https://download.pytorch.org/whl/cpu
76-
pip install '.[docs]'
72+
# NOTE(stes): Updated to latest version as of 17/04/2025, v3.6.4.
73+
wget -q https://github.com/jgm/pandoc/releases/download/3.6.4/pandoc-3.6.4-1-amd64.deb
74+
sudo dpkg -i pandoc-3.6.4-1-amd64.deb
75+
rm pandoc-3.6.4-1-amd64.deb
76+
pip install -r docs/requirements.txt
7777
78+
- name: Check software versions
79+
run: |
80+
sphinx-build --version
81+
pandoc --version
7882
7983
- name: Build docs
8084
run: |
8185
ls docs/source/cebra-figures
82-
# later also add the -n option to check for broken links
86+
export SPHINXBUILD="sphinx-build"
8387
export SPHINXOPTS="-W --keep-going -n"
8488
make docs
8589

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ exports/
88
demo_notebooks/
99
assets/
1010

11+
# demo run
12+
.vscode/
13+
auxiliary_behavior_data.h5
14+
cebra_model.pt
15+
data.npz
16+
grid_search_models/
17+
neural_data.npz
18+
saved_models/
19+
1120
# Binary files
1221
*.png
1322
*.jpg

cebra/models/criterions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def infonce(
9595
9696
Note:
9797
- The behavior of this function changed beginning in CEBRA 0.3.0.
98-
The InfoNCE implementation is numerically stabilized.
98+
The InfoNCE implementation is numerically stabilized.
9999
"""
100100
with torch.no_grad():
101101
c, _ = neg_dist.max(dim=1, keepdim=True)

docs/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM python:3.10
2+
3+
RUN apt-get update && apt-get install -y \
4+
git \
5+
make \
6+
pandoc \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
COPY docs/requirements.txt .
10+
RUN pip install -r requirements.txt
11+
12+
#COPY setup.cfg .
13+
#COPY pyproject.toml .
14+
#COPY cebra/ .

docs/Makefile

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# You can set these variables from the command line, and also
55
# from the environment for the first two.
6-
SPHINXOPTS ?=
6+
SPHINXOPTS ?= -W --keep-going -n
77
SPHINXBUILD ?= sphinx-build
88
SOURCEDIR = source
99
BUILDDIR = build
@@ -33,12 +33,26 @@ clean:
3333
source/cebra-figures:
3434
git clone --depth 1 [email protected]:AdaptiveMotorControlLab/cebra-figures.git source/cebra-figures
3535

36+
source/demo_notebooks:
37+
git clone --depth 1 [email protected]:AdaptiveMotorControlLab/cebra-demos.git source/demo_notebooks
38+
3639
# Update the figures. Note that this might prompt you for an SSH key
3740
figures: source/cebra-figures
3841
cd source/cebra-figures && git pull --ff-only origin main
3942

43+
demos: source/demo_notebooks
44+
cd source/demo_notebooks && git pull --ff-only origin main
45+
46+
source/assets:
47+
git clone --depth 1 [email protected]:AdaptiveMotorControlLab/cebra-assets.git source/assets
48+
49+
assets: source/assets
50+
cd source/assets && git pull --ff-only origin main
51+
cp -r source/assets/docs/* .
52+
#rm -rf source/assets
53+
4054
# Build the page with pre-built figures
41-
page: source/cebra-figures html
55+
page: source/cebra-figures source/demo_notebooks html
4256
mkdir -p page/
4357
mkdir -p page/docs
4458
mkdir -p page/staging/docs

docs/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# CEBRA documentation
2+
3+
This directory contains the documentation for CEBRA.
4+
5+
To build the docs, head to *the root folder of the repository* and run:
6+
7+
```bash
8+
./tools/build_docs.sh
9+
```
10+
11+
This will build the docker container in [Dockerfile](Dockerfile) and run the `make docs` command from the root repo.
12+
The exact requirements for building the docs are now listed in [requirements.txt](requirements.txt).
13+
14+
For easier local development, docs are not using `sphinx-autobuild` and will by default be served at [http://127.0.0.1:8000](http://127.0.0.1:8000).

docs/requirements.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
sphinx==7.4.7
2+
nbsphinx==0.9.6
3+
pydata-sphinx-theme==0.16.1
4+
pytest-sphinx==0.6.3
5+
sphinx-autobuild==2024.10.3
6+
sphinx-autodoc-typehints==1.19.0
7+
sphinx-copybutton==0.5.2
8+
sphinx-gallery==0.19.0
9+
sphinx-tabs==3.4.7
10+
sphinx-togglebutton==0.3.2
11+
sphinx_design==0.6.0
12+
sphinx_pydata_theme==0.1.0
13+
sphinxcontrib-applehelp==2.0.0
14+
sphinxcontrib-devhelp==2.0.0
15+
sphinxcontrib-htmlhelp==2.1.0
16+
sphinxcontrib-jsmath==1.0.1
17+
sphinxcontrib-qthelp==2.0.0
18+
sphinxcontrib-serializinghtml==2.0.0
19+
20+
literate_dataclasses
21+
# For IPython.sphinxext.ipython_console_highlighting extension
22+
ipython
23+
numpy

docs/source/conf.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@
2626
# list see the documentation:
2727
# https://www.sphinx-doc.org/en/master/usage/configuration.html
2828

29-
# -- Path setup --------------------------------------------------------------
30-
3129
import datetime
3230
import os
31+
import pathlib
3332
import sys
3433

3534
sys.path.insert(0, os.path.abspath("."))
3635

37-
import cebra # noqa: E402
38-
3936

4037
def get_years(start_year=2021):
4138
year = datetime.datetime.now().year
@@ -49,8 +46,17 @@ def get_years(start_year=2021):
4946
project = "cebra"
5047
copyright = f"""{get_years(2021)}"""
5148
author = "See AUTHORS.md"
52-
# The full version, including alpha/beta/rc tags
53-
release = cebra.__version__
49+
version_file = pathlib.Path(
50+
__file__).parent.parent.parent / "cebra" / "__init__.py"
51+
assert version_file.exists(), f"Could not find version file: {version_file}"
52+
with version_file.open("r") as f:
53+
for line in f:
54+
if line.startswith("__version__"):
55+
version = line.split("=")[1].strip().strip('"').strip("'")
56+
print("Building docs for version:", version)
57+
break
58+
else:
59+
raise ValueError("Could not find version in __init__.py")
5460

5561
# -- General configuration ---------------------------------------------------
5662

@@ -60,8 +66,7 @@ def get_years(start_year=2021):
6066

6167
#https://github.com/spatialaudio/nbsphinx/issues/128#issuecomment-1158712159
6268
html_js_files = [
63-
"require.min.js", # Add to your _static
64-
"custom.js",
69+
"https://cdn.plot.ly/plotly-latest.min.js", # Add Plotly.js
6570
]
6671

6772
extensions = [
@@ -122,7 +127,8 @@ def get_years(start_year=2021):
122127

123128
autodoc_member_order = "bysource"
124129
autodoc_mock_imports = [
125-
"torch", "nlb_tools", "tqdm", "h5py", "pandas", "matplotlib", "plotly"
130+
"torch", "nlb_tools", "tqdm", "h5py", "pandas", "matplotlib", "plotly",
131+
"joblib", "scikit-learn", "scipy", "requests", "sklearn"
126132
]
127133
# autodoc_typehints = "none"
128134

@@ -134,7 +140,8 @@ def get_years(start_year=2021):
134140
# This pattern also affects html_static_path and html_extra_path.
135141
exclude_patterns = [
136142
"**/todo", "**/src", "cebra-figures/figures.rst", "cebra-figures/*.rst",
137-
"*/cebra-figures/*.rst", "demo_notebooks/README.rst"
143+
"*/cebra-figures/*.rst", "*/demo_notebooks/README.rst",
144+
"demo_notebooks/README.rst"
138145
]
139146

140147
# -- Options for HTML output -------------------------------------------------
@@ -185,23 +192,26 @@ def get_years(start_year=2021):
185192
"icon": "fas fa-graduation-cap",
186193
},
187194
],
188-
"external_links": [
189-
# {"name": "Mathis Lab", "url": "http://www.mackenziemathislab.org/"},
190-
],
191195
"collapse_navigation": False,
192-
"navigation_depth": 4,
196+
"navigation_depth": 1,
193197
"show_nav_level": 2,
194198
"navbar_align": "content",
195199
"show_prev_next": False,
200+
"navbar_end": ["theme-switcher", "navbar-icon-links.html"],
201+
"navbar_persistent": [],
202+
"header_links_before_dropdown": 7
196203
}
197204

198-
html_context = {"default_mode": "dark"}
205+
html_context = {"default_mode": "light"}
199206
html_favicon = "_static/img/logo_small.png"
200207
html_logo = "_static/img/logo_large.png"
201208

202-
# Remove the search field for now
209+
# Replace with this configuration to enable "on this page" navigation
203210
html_sidebars = {
204-
"**": ["search-field.html", "sidebar-nav-bs.html"],
211+
"**": ["search-field.html", "sidebar-nav-bs", "page-toc.html"],
212+
"demos": ["search-field.html", "sidebar-nav-bs"],
213+
"api": ["search-field.html", "sidebar-nav-bs"],
214+
"figures": ["search-field.html", "sidebar-nav-bs"],
205215
}
206216

207217
# Disable links for embedded images
@@ -289,3 +299,12 @@ def get_years(start_year=2021):
289299
"""
290300
# fmt: on
291301
# flake8: enable=E501
302+
303+
# Configure nbsphinx to properly render Plotly plots
304+
nbsphinx_execute = 'auto'
305+
nbsphinx_allow_errors = True
306+
nbsphinx_requirejs_path = 'https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.7/require.js'
307+
nbsphinx_execute_arguments = [
308+
"--InlineBackend.figure_formats={'png', 'svg', 'pdf'}",
309+
"--InlineBackend.rc=figure.dpi=96",
310+
]

0 commit comments

Comments
 (0)