Skip to content

Commit 60d0166

Browse files
committed
test versioning
1 parent cd01cdc commit 60d0166

File tree

7 files changed

+150
-18
lines changed

7 files changed

+150
-18
lines changed

.github/workflows/build-docs.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- dev
7+
- multiversion
78
pull_request:
89
branches:
910
- dev
@@ -46,7 +47,7 @@ jobs:
4647
4748
- name: build documentation
4849
run: |
49-
make docs
50+
make multi-version
5051
5152
- name: save branch name without slashes
5253
env:

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ test-docs: docs
3838
serve-docs: docs
3939
$(poetry) python -m http.server -d docs/build/html 8333
4040

41+
.PHONY: multi-version
42+
multi-version:
43+
$(poetry) python -m sphinx-multiversion docs/source docs/build/html
44+
4145
.PHONY: clean-docs
4246
clean-docs:
4347
rm -rf docs/build

docs/_static/versions.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
{
3+
"name": "v0.0.1 (stable)",
4+
"version": "0.0.1",
5+
"url": "/0.0.1/"
6+
},
7+
{
8+
"version": "dev (dev)",
9+
"url": "/dev/"
10+
}
11+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% if versions %}
2+
<h3>{{ _('Versions') }}</h3>
3+
<ul>
4+
{%- for item in versions %}
5+
<li><a href="{{ item.url }}">{{ item.name }}</a></li>
6+
{%- endfor %}
7+
</ul>
8+
{% endif %}

docs/source/conf.py

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# For the full list of built-in configuration values, see the documentation:
44
# https://www.sphinx-doc.org/en/master/usage/configuration.html
5-
5+
import json
66
# -- Project information -----------------------------------------------------
77
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
88

@@ -16,6 +16,7 @@
1616

1717
from docs_utils.skip_members import skip_member # noqa: E402
1818
from docs_utils.tutorials import generate_tutorial_links_for_notebook_creation # noqa: E402
19+
from docs_utils.versions_generator import generate_versions_json, get_sorted_versions # noqa: E402
1920

2021
project = "AutoIntent"
2122
copyright = "2024, DeepPavlov"
@@ -44,6 +45,7 @@
4445
"sphinx_copybutton",
4546
"nbsphinx",
4647
"sphinx.ext.intersphinx",
48+
"sphinx_multiversion",
4749
]
4850

4951
templates_path = ["_templates"]
@@ -131,23 +133,46 @@
131133
"user_guides/*": "_static/square-white.svg",
132134
}
133135

136+
html_sidebars = {
137+
'**': [
138+
'versioning.html',
139+
],
140+
}
141+
134142
mathjax_path = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"
135143

144+
# sphinx-multiversion
145+
# Whitelist for tags matching v1.0, v2.1 format
146+
smv_tag_whitelist = r'^v\d+\.\d+\.\d+$'
147+
148+
# Whitelist for the dev branch
149+
smv_branch_whitelist = r'^dev$'
150+
151+
# Output format (keeping your current format)
152+
smv_outputdir_format = 'versions/{config.version}/{ref.name}'
153+
154+
# Include both tags and dev branch as released
155+
smv_released_pattern = r'^(refs/tags/.*|refs/heads/dev)$'
136156

157+
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', "..")) # if conf.py is in docs/
137158
def setup(app) -> None: # noqa: ANN001
138-
generate_tutorial_links_for_notebook_creation(
139-
include=[
140-
(
141-
"user_guides.basic_usage",
142-
"Basic Usage",
143-
),
144-
(
145-
"user_guides.advanced",
146-
"Advanced Usage",
147-
),
148-
("user_guides.cli", "CLI Usage"),
149-
],
150-
source="user_guides",
151-
destination="docs/source/user_guides",
152-
)
153-
app.connect("autoapi-skip-member", skip_member)
159+
generate_versions_json(app, repo_root)
160+
# versions = get_sorted_versions()
161+
# with open('docs/source/_static/versions.json', 'w') as f:
162+
# json.dump(versions, f, indent=4)
163+
# generate_tutorial_links_for_notebook_creation(
164+
# include=[
165+
# (
166+
# "user_guides.basic_usage",
167+
# "Basic Usage",
168+
# ),
169+
# (
170+
# "user_guides.advanced",
171+
# "Advanced Usage",
172+
# ),
173+
# ("user_guides.cli", "CLI Usage"),
174+
# ],
175+
# source="user_guides",
176+
# destination="docs/source/user_guides",
177+
# )
178+
# app.connect("autoapi-skip-member", skip_member)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import os
2+
import json
3+
import subprocess
4+
from typing import List, Dict
5+
6+
import re
7+
import os
8+
import json
9+
import subprocess
10+
11+
12+
def get_sorted_versions(repo_root):
13+
# Get the git repository root
14+
tags_output = subprocess.check_output(['git', '-C', repo_root, 'tag'], text=True).strip().split('\n')
15+
# Change to the repository root
16+
original_cwd = os.getcwd()
17+
os.chdir(repo_root)
18+
# Fetch tags and branches
19+
tags_output = subprocess.check_output(['git', 'tag'], text=True).strip().split('\n')
20+
tag_regex = re.compile(r"^v\d+\.\d+\.\d+$") # Matches tags like v0.0.1
21+
tags = [tag for tag in tags_output if tag_regex.match(tag)]
22+
23+
# Sort tags
24+
def version_key(tag):
25+
version = tag.lstrip('v')
26+
return [int(x) for x in version.split('.')]
27+
28+
sorted_tags = sorted(tags, key=version_key, reverse=True)
29+
30+
# Prepare versions list (similar to previous implementation)
31+
versions = []
32+
33+
if sorted_tags:
34+
versions.append({
35+
"name": f"{sorted_tags[0]} (stable)",
36+
"version": sorted_tags[0].lstrip('v'),
37+
"url": f"/{sorted_tags[0].lstrip('v')}/"
38+
})
39+
40+
for tag in sorted_tags[1:]:
41+
versions.append({
42+
"version": tag.lstrip('v'),
43+
"url": f"/{tag.lstrip('v')}/"
44+
})
45+
46+
# Get branches
47+
branches_output = subprocess.check_output(['git', 'branch', '-r'], text=True).strip().split('\n')
48+
dev_branches = [
49+
branch.strip().split('/')[-1]
50+
for branch in branches_output
51+
if 'origin/dev' in branch and "HEAD" not in branch
52+
]
53+
print(dev_branches, branches_output)
54+
55+
for branch in dev_branches:
56+
versions.append({
57+
"version": f"{branch} (dev)",
58+
"url": f"/{branch}/"
59+
})
60+
61+
return versions
62+
63+
64+
def generate_versions_json(app, repo_root):
65+
"""
66+
Sphinx extension to generate versions.json during documentation build.
67+
"""
68+
# Only generate if no exception occurred
69+
# Ensure _static directory exists
70+
print(app.srcdir)
71+
static_dir = os.path.join(repo_root, "docs", '_static')
72+
os.makedirs(static_dir, exist_ok=True)
73+
74+
# Generate and write versions JSON
75+
versions = get_sorted_versions(repo_root)
76+
versions_path = os.path.join(static_dir, 'versions.json')
77+
78+
# Always generate a JSON, even if empty
79+
with open(versions_path, 'w') as f:
80+
json.dump(versions, f, indent=4)
81+
82+
print(f"Generated versions.json with {len(versions)} versions")

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ sphinx-autodoc-typehints = "^2.5.0"
9595
sphinx-copybutton = "^0.5.2"
9696
sphinx-autoapi = "^3.3.3"
9797
ipykernel = "^6.29.5"
98+
sphinx-multiversion = "^0.2.4"
9899

99100
[tool.poetry.scripts]
100101
"autointent" = "autointent._pipeline._cli_endpoint:optimize"

0 commit comments

Comments
 (0)