Skip to content

MNT Replace PDF build by ZIP of the HTML #17564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jan 12, 2021
11 changes: 4 additions & 7 deletions build_tools/circle/build_doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ fi

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

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

# deactivate circleci virtualenv and setup a miniconda env instead
if [[ `type -t deactivate` ]]; then
Expand Down
31 changes: 23 additions & 8 deletions build_tools/circle/list_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from distutils.version import LooseVersion
from urllib.request import urlopen


def json_urlread(url):
try:
return json.loads(urlopen(url).read().decode('utf8'))
Expand All @@ -32,10 +33,23 @@ def human_readable_data_quantity(quantity, multiple=1024):
quantity /= multiple


def get_pdf_size(version):
def get_file_extension(version):
if version == 'dev':
# The 'dev' branch should be explictly handled
return 'zip'

current_version = LooseVersion(version)
min_zip_version = LooseVersion('1.0.0')

return 'zip' if current_version >= min_zip_version else 'pdf'


def get_file_size(version):
api_url = ROOT_URL + '%s/_downloads' % version
for path_details in json_urlread(api_url):
if path_details['name'] == 'scikit-learn-docs.pdf':
file_extension = get_file_extension(version)
file_path = f'scikit-learn-docs.{file_extension}'
if path_details['name'] == file_path:
return human_readable_data_quantity(path_details['size'], 1000)


Expand Down Expand Up @@ -64,8 +78,8 @@ def get_pdf_size(version):
if path_details['type'] == 'dir':
html = urlopen(RAW_FMT % name).read().decode('utf8')
version_num = VERSION_RE.search(html).group(1)
pdf_size = get_pdf_size(name)
dirs[name] = (version_num, pdf_size)
file_size = get_file_size(name)
dirs[name] = (version_num, file_size)

if path_details['type'] == 'symlink':
symlinks[name] = json_urlread(path_details['_links']['self'])['target']
Expand All @@ -81,7 +95,7 @@ def get_pdf_size(version):
for name in (NAMED_DIRS +
sorted((k for k in dirs if k[:1].isdigit()),
key=LooseVersion, reverse=True)):
version_num, pdf_size = dirs[name]
version_num, file_size = dirs[name]
if version_num in seen:
# symlink came first
continue
Expand All @@ -91,7 +105,8 @@ def get_pdf_size(version):
path = 'https://scikit-learn.org/%s/' % name
out = ('* `Scikit-learn %s%s documentation <%s>`_'
% (version_num, name_display, path))
if pdf_size is not None:
out += (' (`PDF %s <%s/_downloads/scikit-learn-docs.pdf>`_)'
% (pdf_size, path))
if file_size is not None:
file_extension = get_file_extension(version_num)
out += (f' (`{file_extension.upper()} {file_size} <{path}/'
f'_downloads/scikit-learn-docs.{file_extension}>`_)')
print(out)
19 changes: 16 additions & 3 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ ALLSPHINXOPTS = -T -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS)\
$(EXAMPLES_PATTERN_OPTS) .


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

all: html-noplot

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

ziphtml:
@if [ ! -d "$(BUILDDIR)/html/stable/" ]; then \
make html; \
fi
# Optimize the images to reduce the size of the ZIP
optipng $(BUILDDIR)/html/stable/_images/*.png
# Exclude the output directory to avoid infinity recursion
cd $(BUILDDIR)/html/stable; \
zip -q -x _downloads \
-r _downloads/scikit-learn-docs.zip .
@echo
@echo "Build finished. The ZIP of the HTML is in $(BUILDDIR)/html/stable/_downloads."

pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
Expand Down Expand Up @@ -106,5 +120,4 @@ optipng:
find _build auto_examples */generated -name '*.png' -print0 \
| xargs -0 -n 1 -P 4 optipng -o10

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