8000 MNT Replace PDF build by ZIP of the HTML (#17564) · scikit-learn/scikit-learn@e15d224 · GitHub
[go: up one dir, main page]

Skip to content

Commit e15d224

Browse files
alfaro96jeremiedbb
authored andcommitted
MNT Replace PDF build by ZIP of the HTML (#17564)
1 parent 690e0a5 commit e15d224

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

build_tools/circle/build_doc.sh

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ fi
116116

117117
if [[ "$CIRCLE_BRANCH" =~ ^master$|^[0-9]+\.[0-9]+\.X$ && -z "$CI_PULL_REQUEST" ]]
118118
then
119-
# PDF linked into HTML
120-
make_args="dist LATEXMKOPTS=-halt-on-error"
119+
# ZIP linked into HTML
120+
make_args=dist
121121
elif [[ "$build_type" =~ ^QUICK ]]
122122
then
123123
make_args=html-noplot
@@ -133,13 +133,10 @@ fi
133133
make_args="SPHINXOPTS=-T $make_args" # show full traceback on exception
134134

135135
# Installing required system packages to support the rendering of math
136-
# notation in the HTML documentation
136+
# notation in the HTML documentation and to optimize the image files
137137
sudo -E apt-get -yq update
138-
sudo -E apt-get -yq remove texlive-binaries --purge
139138
sudo -E apt-get -yq --no-install-suggests --no-install-recommends \
140-
install dvipng texlive-latex-base texlive-latex-extra \
141-
texlive-latex-recommended texlive-fonts-recommended \
142-
latexmk gsfonts ccache
139+
install dvipng gsfonts ccache zip optipng
143140

144141
# deactivate circleci virtualenv and setup a miniconda env instead
145142
if [[ `type -t deactivate` ]]; then

build_tools/circle/list_versions.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from distutils.version import LooseVersion
99
from urllib.request import urlopen
1010

11+
1112
def json_urlread(url):
1213
try:
1314
return json.loads(urlopen(url).read().decode('utf8'))
@@ -32,10 +33,23 @@ def human_readable_data_quantity(quantity, multiple=1024):
3233
quantity /= multiple
3334

3435

35-
def get_pdf_size(version):
36+
def get_file_extension(version):
37+
if version == 'dev':
38+
# The 'dev' branch should be explictly handled
39+
return 'zip'
40+
41+
current_version = LooseVersion(version)
42+
min_zip_version = LooseVersion('1.0.0')
43+
44+
return 'zip' if current_version >= min_zip_version else 'pdf'
45+
46+
47+
def get_file_size(version):
3648
api_url = ROOT_URL + '%s/_downloads' % version
3749
for path_details in json_urlread(api_url):
38-
if path_details['name'] == 'scikit-learn-docs.pdf':
50+
file_extension = get_file_extension(version)
51+
file_path = f'scikit-learn-docs.{file_extension}'
52+
if path_details['name'] == file_path:
3953
return human_readable_data_quantity(path_details['size'], 1000)
4054

4155

@@ -64,8 +78,8 @@ def get_pdf_size(version):
6478
if path_details['type'] == 'dir':
6579
html = urlopen(RAW_FMT % name).read().decode('utf8')
6680
version_num = VERSION_RE.search(html).group(1)
67-
pdf_size = get_pdf_size(name)
68-
dirs[name] = (version_num, pdf_size)
81+
file_size = get_file_size(name)
82+
dirs[name] = (version_num, file_size)
6983

7084
if path_details['type'] == 'symlink':
7185
symlinks[name] = json_urlread(path_details['_links']['self'])['target']
@@ -81,7 +95,7 @@ def get_pdf_size(version):
8195
for name in (NAMED_DIRS +
8296
sorted((k for k in dirs if k[:1].isdigit()),
8397
key=LooseVersion, reverse=True)):
84-
version_num, pdf_size = dirs[name]
98+
version_num, file_size = dirs[name]
8599
if version_num in seen:
86100
# symlink came first
87101
continue
@@ -91,7 +105,8 @@ def get_pdf_size(version):
91105
path = 'https://scikit-learn.org/%s/' % name
92106
out = ('* `Scikit-learn %s%s documentation <%s>`_'
93107
% (version_num, name_display, path))
94-
if pdf_size is not None:
95-
out += (' (`PDF %s <%s/_downloads/scikit-learn-docs.pdf>`_)'
96-
% (pdf_size, path))
108+
if file_size is not None:
109+
file_extension = get_file_extension(version_num)
110+
out += (f' (`{file_extension.upper()} {file_size} <{path}/'
111+
f'_downloads/scikit-learn-docs.{file_extension}>`_)')
97112
print(out)

doc/Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ ALLSPHINXOPTS = -T -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS)\
1717
$(EXAMPLES_PATTERN_OPTS) .
1818

1919

20-
.PHONY: help clean html dirhtml pickle json latex latexpdf changes linkcheck doctest optipng
20+
.PHONY: help clean html dirhtml ziphtml pickle json latex latexpdf changes linkcheck doctest optipng
2121

2222
all: html-noplot
2323

2424
help:
2525
@echo "Please use \`make <target>' where <target> is one of"
2626
@echo " html to make standalone HTML files"
2727
@echo " dirhtml to make HTML files named index.html in directories"
28+
@echo " ziphtml to make a ZIP of the HTML"
2829
@echo " pickle to make pickle files"
2930
@echo " json to make JSON files"
3031
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@@ -58,6 +59,19 @@ dirhtml:
5859
@echo
5960
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
6061

62+
ziphtml:
63+
@if [ ! -d "$(BUILDDIR)/html/stable/" ]; then \
64+
make html; \
65+
fi
66+
# Optimize the images to reduce the size of the ZIP
67+
optipng $(BUILDDIR)/html/stable/_images/*.png
68+
# Exclude the output directory to avoid infinity recursion
69+
cd $(BUILDDIR)/html/stable; \
70+
zip -q -x _downloads \
71+
-r _downloads/scikit-learn-docs.zip .
72+
@echo
73+
@echo "Build finished. The ZIP of the HTML is in $(BUILDDIR)/html/stable/_downloads."
74+
6175
pickle:
6276
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
6377
@echo
@@ -106,5 +120,4 @@ optipng:
106120
find _build auto_examples */generated -name '*.png' -print0 \
107121
| xargs -0 -n 1 -P 4 optipng -o10
108122

109-
dist: html latexpdf
110-
cp _build/latex/user_guide.pdf _build/html/stable/_downloads/scikit-learn-docs.pdf
123+
dist: html ziphtml

0 commit comments

Comments
 (0)
0