Skip to content

Commit 660235b

Browse files
authored
Use sphinx-polyversion (#274)
* export documented symbols * wip: use polyversion instead of multiversion * fix import * use stdlib to get version * deregister extension * separate environments * disable gallery run for older version * pin builder versions * bypass makefile in PR check * separate venvs * use aliased build directory * update actions * install from fork for now * use fork for deployment build * test local build * bump action version * fix make command * try fetching the ref * print git status * rename debug step * remove smv commands * add default builder and environment
1 parent d12c0ef commit 660235b

9 files changed

Lines changed: 163 additions & 34 deletions

File tree

.github/workflows/docs.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,36 @@ jobs:
2121
runs-on: ubuntu-latest
2222
steps:
2323
- name: Checkout
24-
uses: actions/checkout@v3
24+
uses: actions/checkout@v4
2525
with:
2626
fetch-depth: 0
27+
- name: Fetch main
28+
run: |
29+
git fetch origin main:main
30+
git status
2731
- name: Setup Pages
2832
id: pages
2933
uses: actions/configure-pages@v3
3034
- name: Install dependencies
3135
run: |
3236
python -m pip install --upgrade pip
3337
pip install ".[doc]"
38+
# temporary fix for sphinx-polyversion
39+
pip install --force-reinstall git+https://github.com/ziw-liu/sphinx-polyversion.git@iohub-staging
3440
- name: Set environment
3541
run: |
3642
REPO_OWNER="${GITHUB_REPOSITORY%%/*}"
3743
REPO_NAME="${GITHUB_REPOSITORY#*/}"
3844
echo "GITHUB_PAGES_URL=https://$REPO_OWNER.github.io/$REPO_NAME" >> $GITHUB_ENV
3945
- name: Build the docs
40-
working-directory: ./docs
4146
run: |
4247
echo $GITHUB_PAGES_URL
43-
make publish
44-
touch build/html/.nojekyll
48+
make build -C docs
49+
touch docs/build/.nojekyll
4550
- name: Upload build artifacts
46-
uses: actions/upload-pages-artifact@v1
51+
uses: actions/upload-pages-artifact@v3
4752
with:
48-
path: "./docs/build/html"
53+
path: "./docs/build"
4954

5055
deploy:
5156
environment:

.github/workflows/pr.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
python-version: ["3.11"]
1919

2020
steps:
21-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@v4
2222
- name: Set up Python
2323
uses: actions/setup-python@v4
2424
with:
@@ -41,7 +41,7 @@ jobs:
4141
python-version: ["3.11"]
4242

4343
steps:
44-
- uses: actions/checkout@v3
44+
- uses: actions/checkout@v4
4545
- name: Set up Python
4646
uses: actions/setup-python@v4
4747
with:
@@ -64,7 +64,7 @@ jobs:
6464
python-version: ["3.11"]
6565

6666
steps:
67-
- uses: actions/checkout@v3
67+
- uses: actions/checkout@v4
6868
- name: Set up Python
6969
uses: actions/setup-python@v4
7070
with:
@@ -85,7 +85,7 @@ jobs:
8585
python-version: ["3.11", "3.12", "3.13"]
8686

8787
steps:
88-
- uses: actions/checkout@v3
88+
- uses: actions/checkout@v4
8989

9090
- uses: actions/setup-python@v4
9191
with:
@@ -108,7 +108,7 @@ jobs:
108108
needs: [style, lint, isort]
109109
runs-on: ubuntu-latest
110110
steps:
111-
- uses: actions/checkout@v3
111+
- uses: actions/checkout@v4
112112

113113
- uses: actions/setup-python@v4
114114
with:
@@ -118,8 +118,9 @@ jobs:
118118
run: |
119119
python -m pip install --upgrade pip
120120
pip install ".[doc]"
121+
# temporary fix for sphinx-polyversion
122+
pip install --force-reinstall git+https://github.com/ziw-liu/sphinx-polyversion.git@iohub-staging
121123
122124
- name: Test docs build
123-
working-directory: ./docs
124125
run: |
125-
make build
126+
sphinx-polyversion docs/poly.py -vvv --local

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
platform: [ubuntu-latest, windows-latest, macos-latest]
1616
python-version: ["3.11", "3.12", "3.13"]
1717
steps:
18-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
1919

2020
- uses: actions/setup-python@v4
2121
with:

docs/Makefile

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# You can set these variables from the command line.
22
SPHINXOPTS =
3-
SPHINXBUILD = sphinx-build
43
BUILDDIR = build
54

65
# Internal variables.
@@ -28,12 +27,7 @@ clean:
2827
-rm -rf source/auto_examples/*
2928

3029
build:
31-
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
30+
-sphinx-polyversion poly.py $(BUILDDIR) -vvv
31+
-cp gh-pages-redirect.html $(BUILDDIR)/index.html
3232
@echo
33-
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
34-
35-
publish:
36-
sphinx-multiversion source build/html
37-
cp gh-pages-redirect.html build/html/index.html
38-
@echo
39-
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
33+
@echo "Build finished. The HTML pages are in $(BUILDDIR)."

docs/poly.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
from datetime import datetime
2+
from functools import partial
3+
from pathlib import Path
4+
5+
from sphinx_polyversion import apply_overrides
6+
from sphinx_polyversion.driver import DefaultDriver
7+
from sphinx_polyversion.git import (
8+
Git,
9+
GitRef,
10+
GitRefType,
11+
closest_tag,
12+
file_predicate,
13+
)
14+
from sphinx_polyversion.pyvenv import Pip, VenvWrapper
15+
from sphinx_polyversion.sphinx import SphinxBuilder
16+
17+
#: Regex matching the branches to build docs for
18+
BRANCH_REGEX = r"^main$"
19+
20+
#: Regex matching the tags to build docs for
21+
TAG_REGEX = r"^v\d+\.\d+\.\d+$"
22+
23+
#: Output dir relative to project root
24+
#: !!! This name has to be choosen !!!
25+
OUTPUT_DIR = "docs/build"
26+
27+
#: Source directory
28+
SOURCE_DIR = "docs/"
29+
30+
#: Arguments to pass to `pip install`
31+
PIP_ARGS = [".[doc]"]
32+
33+
#: Mock data used for building local version
34+
MOCK_DATA = {
35+
"revisions": [
36+
GitRef(
37+
name="v0.1.0",
38+
obj="",
39+
ref="",
40+
type_=GitRefType.TAG,
41+
date=datetime(year=2024, month=2, day=13),
42+
)
43+
],
44+
"current": GitRef(
45+
name="local",
46+
obj="",
47+
ref="",
48+
type_=GitRefType.BRANCH,
49+
date=datetime.now(),
50+
),
51+
}
52+
53+
#: Whether to build using only local files and mock data
54+
MOCK = False
55+
56+
# Load overrides read from commandline to global scope
57+
apply_overrides(globals())
58+
# Determine repository root directory
59+
root = Git.root(Path(__file__).parent)
60+
61+
# Setup driver and run it
62+
src = Path(SOURCE_DIR)
63+
ENVIRONMENT = (
64+
{
65+
None: Pip.factory(
66+
venv=Path(".venv") / "default",
67+
args=PIP_ARGS,
68+
creator=VenvWrapper(),
69+
),
70+
"v0.1.0": Pip.factory(
71+
venv=Path(".venv") / "v0.1.0",
72+
args=PIP_ARGS
73+
+ [
74+
"sphinxcontrib-applehelp<=1.0.4",
75+
"sphinxcontrib-devhelp<=1.0.2",
76+
"sphinxcontrib-htmlhelp<=2.0.1",
77+
"sphinxcontrib-qthelp<=1.0.3",
78+
"sphinxcontrib-serializinghtml<=1.1.5",
79+
],
80+
creator=VenvWrapper(),
81+
),
82+
"main": Pip.factory(
83+
venv=Path(".venv") / "main",
84+
args=PIP_ARGS + ["importlib_metadata"],
85+
creator=VenvWrapper(),
86+
),
87+
}
88+
if not MOCK
89+
else Pip.factory(
90+
venv=Path(".venv") / "local",
91+
args=PIP_ARGS + ["importlib_metadata"],
92+
creator=VenvWrapper(),
93+
)
94+
)
95+
96+
BUILDER = (
97+
{
98+
None: SphinxBuilder(src / "source", args=[]),
99+
"v0.1.0": SphinxBuilder(src / "source", args=["-D", "plot_gallery=0"]),
100+
"main": SphinxBuilder(src / "source", args=[]),
101+
}
102+
if not MOCK
103+
else SphinxBuilder(src / "source", args=[])
104+
)
105+
106+
DefaultDriver(
107+
root,
108+
OUTPUT_DIR,
109+
vcs=Git(
110+
branch_regex=BRANCH_REGEX,
111+
tag_regex=TAG_REGEX,
112+
buffer_size=1 * 10**9, # 1 GB
113+
predicate=file_predicate([src]), # exclude refs without source dir
114+
),
115+
builder=BUILDER,
116+
env=ENVIRONMENT,
117+
# template_dir=root / src / "templates",
118+
static_dir=root / src / "source" / "_static",
119+
mock=MOCK_DATA,
120+
selector=partial(closest_tag, root),
121+
).run(MOCK)

docs/source/conf.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import sys
99

1010
import importlib_metadata
11+
from sphinx_polyversion import load
1112

13+
load(globals())
1214
# -- General configuration ----------------------------------------------------
1315

1416
# If your documentation needs a minimal Sphinx version, state it here.
@@ -33,7 +35,7 @@
3335
"sphinx.ext.viewcode",
3436
"sphinx_copybutton",
3537
"numpydoc",
36-
"sphinx_multiversion",
38+
"sphinx_polyversion",
3739
"sphinx_sitemap",
3840
"sphinx_gallery.gen_gallery",
3941
]
@@ -50,11 +52,6 @@
5052
# Add any paths that contain templates here, relative to this directory.
5153
# templates_path = ["_templates"]
5254

53-
# Disabling generation of docs on different branches to use tags only
54-
smv_tag_whitelist = r"^v\d+\.\d+\.\d+$"
55-
smv_branch_whitelist = r"^main$"
56-
smv_latest_version = r"^main$"
57-
5855
# The suffix of source filenames.
5956
source_suffix = ".rst"
6057

iohub/convert.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import logging
3+
from importlib.metadata import version
34
from pathlib import Path
45
from typing import Literal
56

@@ -9,7 +10,6 @@
910
from tqdm.contrib.itertools import product
1011
from tqdm.contrib.logging import logging_redirect_tqdm
1112

12-
from iohub._version import version as iohub_version
1313
from iohub.ngff.models import TransformationMeta
1414
from iohub.ngff.nodes import Position, open_ome_zarr
1515
from iohub.reader import MMStack, NDTiffDataset, read_images
@@ -140,7 +140,7 @@ def __init__(
140140
f"dimensions (P, T, C, Z, Y, X): {self.dim}"
141141
)
142142
self.metadata = dict()
143-
self.metadata["iohub_version"] = iohub_version
143+
self.metadata["iohub_version"] = version("iohub")
144144
self.metadata["Summary"] = self.summary_metadata
145145
if grid_layout:
146146
if hcs_plate:

iohub/ngff/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
from iohub.ngff.models import TransformationMeta
2-
from iohub.ngff.nodes import ImageArray, Plate, Position, open_ome_zarr
2+
from iohub.ngff.nodes import (
3+
ImageArray,
4+
NGFFNode,
5+
Plate,
6+
Position,
7+
TiledImageArray,
8+
TiledPosition,
9+
open_ome_zarr,
10+
)
311

412
__all__ = [
513
"ImageArray",
6-
"open_ome_zarr",
14+
"NGFFNode",
715
"Plate",
816
"Position",
17+
"TiledImageArray",
18+
"TiledPosition",
919
"TransformationMeta",
20+
"open_ome_zarr",
1021
]

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ doc =
6161
sphinx>=4.2.0
6262
pydata-sphinx-theme>=0.15.2
6363
sphinx-copybutton>=0.4.0
64-
sphinx-multiversion>=0.2.4
64+
sphinx-polyversion>=0.2.4
6565
sphinx-sitemap>=2.5.0
6666
sphinx-gallery>=0.13.0

0 commit comments

Comments
 (0)