Skip to content

Commit 10fea7f

Browse files
authored
Meson: add building of documentation as target
1 parent e0cf1e4 commit 10fea7f

File tree

9 files changed

+394
-399
lines changed

9 files changed

+394
-399
lines changed

.github/workflows/doc-build.yml

Lines changed: 51 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -16,110 +16,60 @@ on:
1616
- develop
1717
workflow_dispatch:
1818
# Allow to run manually
19-
inputs:
20-
platform:
21-
description: 'Platform'
22-
required: true
23-
default: 'ubuntu-noble-standard'
24-
docker_tag:
25-
description: 'Docker tag'
26-
required: true
27-
default: 'dev'
2819

2920
concurrency:
3021
# Cancel previous runs of this workflow for the same branch
3122
group: ${{ github.workflow }}-${{ github.ref }}
3223
cancel-in-progress: true
3324

3425
env:
35-
# Same as in build.yml
36-
TOX_ENV: "docker-${{ github.event.inputs.platform || 'ubuntu-noble-standard' }}-incremental"
37-
BUILD_IMAGE: "localhost:5000/${{ github.repository }}/sage-${{ github.event.inputs.platform || 'ubuntu-noble-standard' }}-with-targets:ci"
38-
FROM_DOCKER_REPOSITORY: "ghcr.io/sagemath/sage/"
39-
FROM_DOCKER_TARGET: "with-targets"
40-
FROM_DOCKER_TAG: ${{ github.event.inputs.docker_tag || 'dev'}}
41-
EXTRA_CONFIGURE_ARGS: --enable-fat-binary
26+
PYTHON_VERSION: 3.11
4227

4328
jobs:
4429
build-doc:
4530
runs-on: ubuntu-latest
46-
services:
47-
# https://docs.docker.com/build/ci/github-actions/local-registry/
48-
registry:
49-
image: registry:2
50-
ports:
51-
- 5000:5000
5231
steps:
53-
- name: Maximize build disk space
54-
uses: easimon/maximize-build-space@v10
55-
with:
56-
# need space in /var for Docker images
57-
root-reserve-mb: 30000
58-
remove-dotnet: true
59-
remove-android: true
60-
remove-haskell: true
61-
remove-codeql: true
62-
remove-docker-images: true
6332
- name: Checkout
6433
uses: actions/checkout@v4
65-
- name: Install test prerequisites
66-
# From docker.yml
67-
run: |
68-
sudo DEBIAN_FRONTEND=noninteractive apt-get update
69-
sudo DEBIAN_FRONTEND=noninteractive apt-get install tox
70-
sudo apt-get clean
71-
df -h
34+
7235
- name: Merge CI fixes from sagemath/sage
7336
run: |
74-
mkdir -p upstream
75-
.ci/merge-fixes.sh 2>&1 | tee upstream/ci_fixes.log
37+
.ci/merge-fixes.sh
7638
env:
7739
GH_TOKEN: ${{ github.token }}
78-
SAGE_CI_FIXES_FROM_REPOSITORIES: ${{ vars.SAGE_CI_FIXES_FROM_REPOSITORIES }}
79-
80-
# Building
81-
82-
- name: Generate Dockerfile
83-
# From docker.yml
84-
run: |
85-
tox -e ${{ env.TOX_ENV }}
86-
cp .tox/${{ env.TOX_ENV }}/Dockerfile .
87-
env:
88-
# Only generate the Dockerfile, do not run 'docker build' here
89-
DOCKER_TARGETS: ""
9040

91-
- name: Set up Docker Buildx
92-
uses: docker/setup-buildx-action@v3
41+
- name: Cache conda packages
42+
uses: actions/cache@v4
9343
with:
94-
driver-opts: network=host
95-
96-
- name: Build Docker image
97-
id: image
98-
uses: docker/build-push-action@v6
44+
path: ~/conda_pkgs_dir
45+
key:
46+
${{ runner.os }}-conda-${{ hashFiles('environment-${{ env.PYTHON_VERSION }}-linux.yml') }}
47+
48+
- name: Compiler cache
49+
uses: hendrikmuhs/[email protected]
9950
with:
100-
# push and load may not be set together at the moment
101-
push: true
102-
load: false
103-
context: .
104-
tags: ${{ env.BUILD_IMAGE }}
105-
target: with-targets
106-
cache-from: type=gha
107-
cache-to: type=gha,mode=max
108-
build-args: |
109-
NUMPROC=6
110-
USE_MAKEFLAGS=-k V=0 SAGE_NUM_THREADS=4 --output-sync=recurse
111-
TARGETS_PRE=build/make/Makefile
112-
TARGETS=ci-build-with-fallback
51+
key: ${{ runner.os }}-meson-${{ env.PYTHON_VERSION }}
11352

114-
- name: Start container
115-
id: container
116-
# Try to continue when "exporting to GitHub Actions Cache" failed with timeout
53+
- name: Setup Conda environment
54+
uses: conda-incubator/setup-miniconda@v3
55+
with:
56+
python-version: ${{ env.PYTHON_VERSION }}
57+
# Disabled for now due to
58+
# https://github.com/conda-incubator/setup-miniconda/issues/379
59+
# miniforge-version: latest
60+
use-mamba: true
61+
channels: conda-forge
62+
channel-priority: true
63+
activate-environment: sage-dev
64+
environment-file: environment-${{ env.PYTHON_VERSION }}-linux.yml
65+
66+
- name: Build Sage
67+
shell: bash -l {0}
11768
run: |
118-
docker run --name BUILD -dit \
119-
--mount type=bind,src=$(pwd),dst=$(pwd) \
120-
--workdir $(pwd) \
121-
${{ env.BUILD_IMAGE }} /bin/sh
122-
69+
export LIB="$LIB;$CONDA_PREFIX\\Library\\lib"
70+
export INCLUDE="$INCLUDE;$CONDA_PREFIX\\Library\\include"
71+
pip install --no-build-isolation --config-settings=builddir=builddir . -v
72+
12373
#
12474
# On pull request and push to develop events
12575
#
@@ -164,8 +114,8 @@ jobs:
164114
# mathjax path in old doc (regex)
165115
mathjax_path_from="[-./A-Za-z_]*/tex-chtml[.]js?v=[0-9a-f]*"
166116
# mathjax path in new doc
167-
mathjax_path_to=$(docker exec -e SAGE_USE_CDNS=yes BUILD /sage/sage -python -c "from sage_docbuild.conf import mathjax_path; print(mathjax_path)")
168-
new_version=$(docker exec BUILD cat src/VERSION.txt)
117+
mathjax_path_to=$(SAGE_USE_CDNS=yes python -c "from sage_docbuild.conf import mathjax_path; print(mathjax_path)")
118+
new_version=$(cat src/VERSION.txt)
169119
# Wipe out chronic diffs between old doc and new doc
170120
(cd doc && \
171121
find . -name "*.html" | xargs sed -i -e '/class="sidebar-brand-text"/ s/Sage [0-9a-z.]* /Sage '"$new_version"' /' \
@@ -185,20 +135,15 @@ jobs:
185135
git add -A && git commit --quiet -m 'old')
186136
fi
187137
188-
- name: Build doc
138+
- name: Build documentation
189139
id: docbuild
190-
if: steps.container.outcome == 'success' && !startsWith(github.ref, 'refs/tags/')
191-
# Always non-incremental because of the concern that
192-
# incremental docbuild may introduce broken links (inter-file references) though build succeeds
140+
if: steps.worktree.outcome == 'success'
141+
shell: bash -l {0}
193142
run: |
194-
export GITHUB_REF=${{ github.ref }}
195-
export PR_SHA=${{ github.event.pull_request.head.sha }}
196-
export MAKE="make -j5 --output-sync=recurse" SAGE_NUM_THREADS=5
197-
make doc-clean doc-uninstall
198-
export SAGE_USE_CDNS=yes
199-
export SAGE_DOCBUILD_OPTS="--include-tests-blocks"
200-
./config.status && make sagemath_doc_html-no-deps
201-
shell: sh .ci/docker-exec-script.sh BUILD /sage {0}
143+
meson compile -C builddir doc-html
144+
env:
145+
SAGE_USE_CDNS: yes
146+
SAGE_DOCBUILD_OPTS: "--include-tests-blocks"
202147

203148
- name: Copy doc
204149
id: copy
@@ -209,12 +154,7 @@ jobs:
209154
if [ -d "doc/html" ]; then
210155
rm -rf doc/html
211156
fi
212-
# Simpler "docker cp --follow-link ... doc" does not work
213-
mkdir -p doc
214-
mkdir -p temp
215-
docker cp --follow-link BUILD:/sage/local/share/doc/sage/html temp
216-
docker cp --follow-link BUILD:/sage/local/share/doc/sage/index.html temp
217-
cp -r -L temp/* doc/
157+
cp -r builddir/src/doc doc/
218158
# Check if we are on pull request event
219159
PR_NUMBER=""
220160
if [[ -n "$GITHUB_REF" ]]; then
@@ -275,30 +215,24 @@ jobs:
275215
- name: Build live doc
276216
id: buildlivedoc
277217
if: startsWith(github.ref, 'refs/tags/')
218+
shell: bash -l {0}
278219
run: |
279-
# Avoid running out of disk space
280-
rm -rf upstream
281-
export MAKE="make -j5 --output-sync=recurse" SAGE_NUM_THREADS=5
282-
export PATH="build/bin:$PATH"
283-
eval $(sage-print-system-package-command auto update)
284-
eval $(sage-print-system-package-command auto --yes --no-install-recommends install zip)
285-
eval $(sage-print-system-package-command auto --spkg --yes --no-install-recommends install git texlive texlive_luatex free_fonts xindy)
286-
export SAGE_USE_CDNS=yes
287-
export SAGE_LIVE_DOC=yes
288-
export SAGE_JUPYTER_SERVER=binder:sagemath/sage-binder-env/dev
289-
make doc-clean doc-uninstall
290-
./config.status && make sagemath_doc_html-no-deps sagemath_doc_pdf-no-deps
291-
shell: sh .ci/docker-exec-script.sh BUILD /sage {0}
220+
meson compile -C builddir doc-html
221+
env:
222+
SAGE_USE_CDNS: yes
223+
SAGE_LIVE_DOC: yes
224+
SAGE_JUPYTER_SERVER: binder:sagemath/sage-binder-env/dev
225+
SAGE_DOCBUILD_OPTS: "--include-tests-blocks"
292226

293227
- name: Copy live doc
294228
id: copylivedoc
295229
if: steps.buildlivedoc.outcome == 'success'
296230
run: |
297231
mkdir -p ./livedoc
298232
# We copy everything to a local folder
299-
docker cp --follow-link BUILD:/sage/local/share/doc/sage/html livedoc
300-
docker cp --follow-link BUILD:/sage/local/share/doc/sage/pdf livedoc
301-
docker cp --follow-link BUILD:/sage/local/share/doc/sage/index.html livedoc
233+
cp -r builddir/src/doc/html livedoc/
234+
cp -r builddir/src/doc/pdf livedoc/
235+
cp builddir/src/doc/index.html livedoc/
302236
zip -r livedoc.zip livedoc
303237
304238
- name: Upload live doc

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ test = [
169169
]
170170
docs = [
171171
"sphinx",
172-
"sphinx-inline-tabs",
172+
"sphinx-copybutton",
173+
"sphinx-inline-tabs",
173174
"furo",
174175
]
175176
lint = [

src/build-docs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from sage_docbuild.__main__ import main
2+
3+
if __name__ == "__main__":
4+
main()

src/doc/en/reference/conf_sub.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
# serve to show the default.
1212

1313
import os
14-
from sage.env import SAGE_DOC_SRC, SAGE_DOC
15-
from sage_docbuild.conf import release, exclude_patterns
16-
from sage_docbuild.conf import *
1714

15+
from sage.env import SAGE_DOC, SAGE_DOC_SRC
16+
from sage_docbuild.conf import *
17+
from sage_docbuild.conf import exclude_patterns
1818

1919
for tag in feature_tags():
2020
tags.add(tag)
@@ -31,7 +31,7 @@
3131
ref_out = os.path.join(SAGE_DOC, 'html', 'en', 'reference')
3232

3333
# We use the main document's title, if we can find it.
34-
rst_file = open('index.rst', 'r')
34+
rst_file = open('index.rst', 'r', encoding='utf-8')
3535
rst_lines = rst_file.read().splitlines()
3636
rst_file.close()
3737

src/doc/meson.build

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Clean target
2+
# clean = custom_target(
3+
# 'clean',
4+
# output: [],
5+
# command: [
6+
# 'sh', '-c',
7+
# '''
8+
# rm -rf en/reference/*/sage
9+
# rm -rf en/reference/documentation/sage_docbuild
10+
# rm -rf en/reference/sage
11+
# rm -f common/*.pyc
12+
# '''
13+
# ]
14+
# )
15+
16+
# Generate sources at build time
17+
# doc_src = custom_target(
18+
# 'doc-src',
19+
# output: ['en/reference/repl/options.txt'],
20+
# command: [
21+
# 'sh', '-c',
22+
# '''
23+
# mkdir -p en/reference/repl
24+
# sage -advanced > en/reference/repl/options.txt
25+
# '''
26+
# ]
27+
# )
28+
29+
30+
31+
references = run_command(
32+
py,
33+
[
34+
src / 'build-docs.py',
35+
'--all-documents',
36+
'reference',
37+
'--source', meson.current_source_dir()
38+
],
39+
check: true,
40+
).stdout().strip()
41+
42+
reference_inventory = []
43+
reference_html = []
44+
reference_pdf = []
45+
bibliography = []
46+
foreach type : ['inventory', 'html', 'pdf']
47+
foreach ref : references.splitlines()
48+
short_ref = ref.split('/')[1]
49+
deps = []
50+
if type == 'html' or type == 'pdf'
51+
deps += reference_inventory
52+
endif
53+
if short_ref != 'references'
54+
deps += bibliography
55+
endif
56+
target = custom_target(
57+
'doc-' + type + '-reference-' + short_ref,
58+
output: [type + short_ref],
59+
command: [
60+
py,
61+
src / 'build-docs.py',
62+
'--no-pdf-links',
63+
ref,
64+
type,
65+
'-o', '@OUTDIR@',
66+
'--source', meson.current_source_dir()
67+
],
68+
depends: deps,
69+
)
70+
if short_ref == 'references'
71+
bibliography += target
72+
endif
73+
if type == 'inventory'
74+
reference_inventory += target
75+
elif type == 'html'
76+
reference_html += target
77+
elif type == 'pdf'
78+
reference_pdf += target
79+
endif
80+
endforeach
81+
endforeach
82+
83+
other_documents = run_command(
84+
py,
85+
[
86+
src / 'build-docs.py',
87+
'--all-documents',
88+
'all',
89+
'--source', meson.current_source_dir()
90+
],
91+
check: true,
92+
).stdout().strip()
93+
other_documents_html = []
94+
other_documents_pdf = []
95+
foreach type : ['html', 'pdf']
96+
foreach doc : other_documents.splitlines()
97+
short_doc = doc.replace('/', '-')
98+
target = custom_target(
99+
'doc-' + type + '-other-' + short_doc,
100+
output: [type + short_doc],
101+
command: [
102+
py,
103+
src / 'build-docs.py',
104+
'--no-pdf-links',
105+
doc,
106+
type,
107+
'-o', '@OUTDIR@',
108+
'--source', meson.current_source_dir()
109+
],
110+
depends: reference_inventory,
111+
)
112+
if type == 'html'
113+
other_documents_html += target
114+
elif type == 'pdf'
115+
other_documents_pdf += target
116+
endif
117+
endforeach
118+
endforeach
119+
120+
# Custom target for building the complete documentation
121+
alias_target('doc-html', [reference_html, other_documents_html])
122+
alias_target('doc-pdf', [reference_pdf, other_documents_pdf])

0 commit comments

Comments
 (0)