Skip to content

Commit 1b9948b

Browse files
niksirbisfmigpre-commit-ci[bot]
authored
Set up multi-version docs (#111)
* use multi-version action * configure version switcher * fix movement URLs * lowe pin movement dependency * fix typo * linkcheck ignore figshare * update binder config to work with multiversion * Update docs/source/conf.py Signed-off-by: sfmig <33267254+sfmig@users.noreply.github.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Check fix for 403 * Revert "Check fix for 403" This reverts commit 491a8a7. * Use mirror in data release --------- Signed-off-by: sfmig <33267254+sfmig@users.noreply.github.com> Co-authored-by: sfmig <33267254+sfmig@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 3771987 commit 1b9948b

File tree

12 files changed

+70
-19
lines changed

12 files changed

+70
-19
lines changed

.binder/.postBuild

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# This script runs in a Binder context within a git checkout of the
4+
# neuroinformatics-unit/ethology repository. It generates Jupyter notebooks
5+
# from the ethology Python examples.
6+
# The script was adapted from https://github.com/scikit-learn/scikit-learn/blob/1.8.0rc1/.binder/postBuild
7+
8+
set -euo pipefail # fail immediately on errors and undefined vars
9+
10+
# Safety check: exit if not running inside a docker container.
11+
: "${REPO_DIR:?This script is for repo2docker and REPO_DIR must be set. \
12+
Exiting because this script can delete data if run outside of a repo2docker context.}"
13+
14+
# Create a temporary directory for staging the examples
15+
TMP_DIR=$(mktemp -d /tmp/ethology-XXXXXX)
16+
# Clean up temporary directory on exit
17+
trap 'rm -rf "$TMP_DIR"' EXIT
18+
19+
# Stage the examples in a temporary directory
20+
cp -r examples "$TMP_DIR/"
21+
# Recursively convert all python scripts to notebooks
22+
find "$TMP_DIR/examples" -name '*.py' -exec sphinx_gallery_py2jupyter '{}' +
23+
# Remove all non-notebook files
24+
find "$TMP_DIR/examples" -type f ! -name '*.ipynb' -delete
25+
26+
# Remove everything except the existing .binder folder to present a clean workspace
27+
# (the .binder folder is kept for debugging purposes)
28+
find . -mindepth 1 -maxdepth 1 ! -name '.binder' -exec rm -rf {} +
29+
30+
# Move the generated notebook files to where Binder expects
31+
mkdir -p notebooks
32+
mv "$TMP_DIR/examples" notebooks/

.binder/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
. # ethology itself

.binder/runtime.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-3.13

.github/workflows/docs_build_and_deploy.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ jobs:
5959
if: (github.event_name == 'push' && (github.ref == 'refs/heads/main' || needs.check_tag.outputs.tag_on_main == 'true')) || github.event_name == 'workflow_dispatch'
6060
runs-on: ubuntu-latest
6161
steps:
62-
- uses: neuroinformatics-unit/actions/deploy_sphinx_docs@v2
62+
- uses: neuroinformatics-unit/actions/deploy_sphinx_docs_multiversion@v2
6363
with:
6464
secret_input: ${{ secrets.GITHUB_TOKEN }}
6565
use-make: true
66+
switcher-url: https://ethology.neuroinformatics.dev/latest/_static/switcher.json

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,17 @@ make clean html linkcheck
300300
```
301301
:::
302302

303+
We use [sphinx-gallery](sphinx-gallery:)
304+
to create the [examples](target-examples).
305+
To add new examples, you will need to create a new `.py` file in `examples/`.
306+
The file should be structured as specified in the relevant
307+
[sphinx-gallery documentation](sphinx-gallery:syntax).
303308

309+
We are using sphinx-gallery's [integration with binder](sphinx-gallery:configuration#binder-links), to provide interactive versions of the examples.
310+
This is configured in `docs/source/conf.py` under the `sphinx_gallery_conf` variable,
311+
and further customised for our repository by the `.binder/postBuild` script.
312+
If your examples rely on packages that are not among `movement`'s dependencies,
313+
you will need to add them to the `.binder/requirements.txt` file.
304314

305315
## Test data
306316

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ recursive-exclude docs *
1010
recursive-exclude tests *
1111
recursive-exclude examples *
1212
recursive-include docs *
13+
recursive-include .binder *
1314

1415
# Include json schemas
1516
recursive-include ethology/validators/json_schemas/schemas *.json
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Related projects
22

3-
We are the same developer team as the one behind [`movement`](https://movement.neuroinformatics.dev/index.html#), a Python package for analysing animal body movements across space and time. We interact very closely with their community to make sure our tools are interoperable and we follow very similar conventions and standards.
3+
We are the same developer team as the one behind [`movement`](https://movement.neuroinformatics.dev), a Python package for analysing animal body movements across space and time. We interact very closely with their community to make sure our tools are interoperable and we follow very similar conventions and standards.

docs/source/conf.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
# with a dummy version
2727
release = "0.0.0"
2828

29+
is_dev = "dev" in release
30+
doc_version = "dev" if is_dev else f"v{release}"
31+
binder_branch = "main" if is_dev else f"v{release}"
32+
2933
# -- General configuration ---------------------------------------------------
3034
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
3135

@@ -117,6 +121,11 @@
117121
"type": "fontawesome",
118122
},
119123
],
124+
"switcher": {
125+
"json_url": "https://ethology.neuroinformatics.dev/latest/_static/switcher.json",
126+
"version_match": doc_version,
127+
},
128+
"navbar_end": ["version-switcher", "theme-switcher", "navbar-icon-links"],
120129
"logo": {
121130
"text": f"{project} v{release}",
122131
},
@@ -151,7 +160,9 @@
151160
]
152161
# A list of regular expressions that match URIs that should not be checked
153162
linkcheck_ignore = [
154-
"https://opensource.org/license/bsd-3-clause/", # to avoid odd 403 error
163+
# to avoid odd 403 client errors
164+
"https://opensource.org/license/bsd-3-clause/",
165+
"https://figshare.com/articles/dataset/Australian_Camera_Trap_Data_ACTD_/27177912",
155166
]
156167

157168
myst_url_schemes = {
@@ -227,9 +238,9 @@
227238
"binder": {
228239
"org": "neuroinformatics-unit",
229240
"repo": "ethology",
230-
"branch": "gh-pages",
241+
"branch": binder_branch, # Can be any branch, tag, or commit
231242
"binderhub_url": "https://mybinder.org",
232-
"dependencies": ["environment.yml"],
243+
"dependencies": ["../../.binder/requirements.txt"],
233244
},
234245
"reference_url": {"ethology": None},
235246
"default_thumb_file": "source/_static/dark-logo-niu.png",

docs/source/environment.yml

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

examples/approximate_subset_sum_split.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,16 @@
7474
# For this example, we will use the `Australian Camera Trap Dataset
7575
# <https://figshare.com/articles/dataset/Australian_Camera_Trap_Data_ACTD_/27177912>`_
7676
# which comprises images from camera traps across various sites in Victoria,
77-
# Australia.
77+
# Australia. This dataset is licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
78+
# and authored by Sameeruddin Muhammad, Scott Mann, Callum Luke,
79+
# Chris Pocknee, Supriya Nair and Jay Nair.
7880
#
7981
# We use the `pooch <https://github.com/fatiando/pooch/>`_ library to download
8082
# the dataset to the ``.ethology`` cache directory.
8183

8284
# %%
8385
data_source = {
84-
"url": "https://figshare.com/ndownloader/files/53674187",
86+
"url": "https://github.com/neuroinformatics-unit/ethology/releases/download/data-ACTD/ACTD_COCO_files.zip",
8587
"hash": "4019bb11cd360d66d13d9309928195638adf83e95ddec7b0b23e693ec8c7c26b",
8688
}
8789

0 commit comments

Comments
 (0)