Skip to content
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

[ci] [docs] use miniforge for readthedocs builds (fixes #4954) #4957

Merged
merged 23 commits into from Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bbfa3e5
[ci] [docs] use mamba for readthedocs builds (fixes #4954)
jameslamb Jan 17, 2022
4a451bb
update docs
jameslamb Jan 17, 2022
945a1ba
Merge branch 'master' into fix/rtd-configuration
jameslamb Jan 18, 2022
54b608d
simplify build script and add docs flag to gitignore
jameslamb Jan 18, 2022
5dd9c8e
exit with non-0 if build fails
jameslamb Jan 18, 2022
8df9337
update CI job
jameslamb Jan 18, 2022
57a0537
add doxygen
jameslamb Jan 18, 2022
d53e14e
remove outdated requirement_base.txt reference
jameslamb Jan 19, 2022
e9aa5a1
use conda create instead of conda env create
jameslamb Jan 19, 2022
343932f
fix conda create flags
jameslamb Jan 19, 2022
8b90bbf
add nodefaults to env.yml
jameslamb Jan 19, 2022
fef18e6
Update docs/README.rst
jameslamb Jan 20, 2022
0c312ee
try to fix check-docs CI job
jameslamb Jan 20, 2022
3efc619
additional changes
jameslamb Jan 20, 2022
c923dfb
Merge branch 'master' into fix/rtd-configuration
jameslamb Feb 13, 2022
e88ba38
switch from mamba to miniforge
jameslamb Feb 14, 2022
dfda92f
Merge branch 'master' into fix/rtd-configuration
jameslamb Feb 14, 2022
ac037b5
simplify docker command and fix issues in local build script
jameslamb Feb 16, 2022
164581a
Merge branch 'master' into fix/rtd-configuration
jameslamb Feb 17, 2022
8010f99
Apply suggestions from code review
jameslamb Feb 17, 2022
00b8e73
Merge branch 'fix/rtd-configuration' of github.com:microsoft/LightGBM…
jameslamb Feb 17, 2022
5faaa44
update docs and conda
jameslamb Feb 17, 2022
3e66b3f
Apply suggestions from code review
jameslamb Feb 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions .ci/test.sh
Expand Up @@ -29,15 +29,23 @@ if [[ "$TASK" == "cpp-tests" ]]; then
exit 0
fi

conda create -q -y -n $CONDA_ENV python=$PYTHON_VERSION
source activate $CONDA_ENV

cd $BUILD_DIRECTORY

if [[ $TASK == "check-docs" ]] || [[ $TASK == "check-links" ]]; then
cd $BUILD_DIRECTORY/docs
conda install -q -y -n $CONDA_ENV -c conda-forge doxygen rstcheck
pip install --user -r requirements.txt
conda env create \
-q \
-n docs-env \
-f ./env.yml
conda install \
-q \
-y \
-n docs-env \
-c conda-forge \
--override-channels \
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
doxygen \
rstcheck
source activate docs-env
# check reStructuredText formatting
cd $BUILD_DIRECTORY/python-package
rstcheck --report warning $(find . -type f -name "*.rst") || exit -1
Expand All @@ -60,6 +68,9 @@ if [[ $TASK == "check-docs" ]] || [[ $TASK == "check-links" ]]; then
exit 0
fi

conda create -q -y -n $CONDA_ENV python=$PYTHON_VERSION
source activate $CONDA_ENV

if [[ $TASK == "lint" ]]; then
conda install -q -y -n $CONDA_ENV \
pycodestyle \
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -346,6 +346,7 @@ instance/
# Sphinx documentation
docs/_build/
docs/pythonapi/
*.flag

# Doxygen documentation
docs/doxyoutput/
Expand Down
10 changes: 6 additions & 4 deletions .readthedocs.yaml
@@ -1,10 +1,12 @@
version: 2
build:
os: "ubuntu-20.04"
tools:
python: "mambaforge-4.10"
conda:
environment: docs/env.yml
formats:
- pdf
python:
version: 3
install:
- requirements: docs/requirements.txt
sphinx:
builder: html
configuration: docs/conf.py
Expand Down
37 changes: 36 additions & 1 deletion docs/README.rst
Expand Up @@ -13,11 +13,46 @@ After each commit on ``master``, documentation is updated and published to `Read
Build
-----

It is not necessary to re-build this documentation while modifying LightGBM's source code.
The HTML files generated using ``Sphinx`` are not checked into source control.
However, you may want to build them locally during development to test changes.

Docker
^^^^^^

The most reliable way to build the documentation locally is with Docker, using `the same images readthedocs uses <https://hub.docker.com/r/readthedocs/build>`_.
StrikerRUS marked this conversation as resolved.
Show resolved Hide resolved
jameslamb marked this conversation as resolved.
Show resolved Hide resolved

Run the following from the root of this repository to pull the relevant image and run a container locally.

.. code:: sh

docker run \
--rm \
--user=0 \
-v $(pwd):/opt/LightGBM \
--env C_API=true \
--env CONDA=/opt/conda \
--env PYTHONUNBUFFERED=1 \
--env READTHEDOCS=true \
--workdir=/opt/LightGBM/docs \
--entrypoint="" \
-it readthedocs/build:ubuntu-20.04-2021.09.23 \
/bin/bash build-docs.sh

When that code completes, open ``docs/html/index.html`` in your browser.
jameslamb marked this conversation as resolved.
Show resolved Hide resolved

.. note::

The navigation in locally-built docs does not link to the local copy of the R documentation. To view the local version of the R docs, open ``docs/_build/html/R/index.html`` in your browser.
StrikerRUS marked this conversation as resolved.
Show resolved Hide resolved

Locally
^^^^^^^

You can build the documentation locally. Just install Doxygen and run in ``docs`` folder

.. code:: sh

pip install -r requirements.txt
pip install breathe sphinx 'sphinx_rtd_theme>0.5'
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
make html

Unfortunately, documentation for R code is built only on our site, and commands above will not build it for you locally.
StrikerRUS marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
34 changes: 34 additions & 0 deletions docs/build-docs.sh
@@ -0,0 +1,34 @@
#!/bin/bash

rm -f ./_FIRST_RUN.flag

ARCH=$(uname -m)
export PATH="${CONDA}/bin:${PATH}"

curl \
-L \
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
-o ${HOME}/conda.sh \
"https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Linux-${ARCH}.sh"

/bin/bash ${HOME}/conda.sh -b -p ${CONDA}

conda config --set always_yes yes --set changeps1 no
jameslamb marked this conversation as resolved.
Show resolved Hide resolved

mamba env create \
--name docs-env \
--file env.yml || exit -1

source activate docs-env

${CONDA}/envs/docs-env/bin/python \
StrikerRUS marked this conversation as resolved.
Show resolved Hide resolved
-m sphinx \
-T \
-E \
-W \
--keep-going \
-b html \
-d _build/doctrees \
-D language=en \
. _build/html || exit -1
StrikerRUS marked this conversation as resolved.
Show resolved Hide resolved

echo "Done building docs. Open docs/_build/html/index.html in a web browser to view them."
17 changes: 2 additions & 15 deletions docs/conf.py
Expand Up @@ -259,21 +259,6 @@ def generate_r_docs(app: Sphinx) -> None:
The application object representing the Sphinx process.
"""
commands = f"""
/home/docs/.conda/bin/conda create \
-q \
-y \
-c conda-forge \
--override-channels \
-n r_env \
r-base=4.1.0=hb67fd72_2 \
r-data.table=1.14.0=r41hcfec24a_0 \
r-jsonlite=1.7.2=r41hcfec24a_0 \
r-knitr=1.35=r41hc72bb7e_0 \
r-matrix=1.3_4=r41he454529_0 \
r-pkgdown=1.6.1=r41hc72bb7e_0 \
r-rmarkdown=2.11=r41hc72bb7e_0 \
r-roxygen2=7.1.1=r41h03ef668_0
source /home/docs/.conda/bin/activate r_env
export TAR=/bin/tar
cd {CURR_PATH.parent}
export R_LIBS="$CONDA_PREFIX/lib/R/library"
Expand All @@ -298,6 +283,7 @@ def generate_r_docs(app: Sphinx) -> None:
cd {CURR_PATH.parent}
"""
try:
print("Building R-package documentation")
# Warning! The following code can cause buffer overflows on RTD.
# Consider suppressing output completely if RTD project silently fails.
# Refer to https://github.com/svenevs/exhale
Expand All @@ -311,6 +297,7 @@ def generate_r_docs(app: Sphinx) -> None:
raise RuntimeError(output)
else:
print(output)
print("Done building R-package documentation")
except BaseException as e:
raise Exception(f"An error has occurred while generating documentation for R-package\n{e}")

Expand Down
17 changes: 17 additions & 0 deletions docs/env.yml
@@ -0,0 +1,17 @@
name: docs-env
channels:
- conda-forge
dependencies:
- breathe
- python=3.9
- pip
- r-base=4.1.2
- r-data.table=1.14.2
- r-jsonlite=1.7.2
- r-knitr=1.37
- r-matrix=1.4_0
- r-pkgdown=1.6.1
- r-rmarkdown=2.11
- r-roxygen2=7.1.2
Comment on lines +8 to +15
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to pin R package versions anymore?.. #2176 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment you've linked refers to a commit, 014bee1, that changed the list of package from "not pinned at all" to "pin to aa specific BUILD of a specific VERSION".

This PR's changes are still pinning them to specific package VERSIONS, just not to individual BUILDS. Sometimes new builds of the same package version are pushed to conda channels, to fix issues like, for example, mistakes in metadata about declared dependencies. We should want to get such fixes automatically, as they make it more likely that the environment will solve correctly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment you've linked refers to a commit, 014bee1, that changed the list of package from "not pinned at all" to "pin to aa specific BUILD of a specific VERSION".

More relevant past discussion: #2725 (comment).

OK, let's not pin build numbers for now. But if RTD starts to fail, we know what to try first.

- sphinx
- "sphinx_rtd_theme>=0.5"
2 changes: 0 additions & 2 deletions docs/requirements.txt

This file was deleted.

2 changes: 0 additions & 2 deletions docs/requirements_base.txt

This file was deleted.