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 22 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@ 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 update \
-n $CONDA_ENV \
--file ./env.yml || exit -1
conda install \
-q \
-y \
-n $CONDA_ENV \
doxygen \
rstcheck || exit -1
# check reStructuredText formatting
cd $BUILD_DIRECTORY/python-package
rstcheck --report warning $(find . -type f -name "*.rst") || exit -1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
version: 2
build:
os: "ubuntu-20.04"
tools:
python: "miniconda3-4.7"
conda:
environment: docs/env.yml
formats:
- pdf
python:
version: 3
install:
- requirements: docs/requirements.txt
sphinx:
builder: html
configuration: docs/conf.py
Expand Down
43 changes: 39 additions & 4 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,55 @@ After each commit on ``master``, documentation is updated and published to `Read
Build
-----

You can build the documentation locally. Just install Doxygen and run in ``docs`` folder
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 Read the Docs uses <https://hub.docker.com/r/readthedocs/build>`_.

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/miniforge \
--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 these 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.

Without Docker
^^^^^^^^^^^^^^

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

.. code:: sh

pip install -r requirements.txt
pip install breathe sphinx 'sphinx_rtd_theme>=0.5'
make html

Unfortunately, documentation for R code is built only on our site, and commands above will not build it for you locally.
Note that this will not build the R documentation.
To build the R docuumentation locally, use the Docker-based approach described above.
Consider using common R utilities for documentation generation, if you need it.
jameslamb marked this conversation as resolved.
Show resolved Hide resolved

If you faced any problems with Doxygen installation or you simply do not need documentation for C code, it is possible to build the documentation without it:

.. code:: sh

pip install -r requirements_base.txt
pip install sphinx 'sphinx_rtd_theme>=0.5'
export C_API=NO || set C_API=NO
make html
24 changes: 24 additions & 0 deletions docs/build-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

rm -f ./_FIRST_RUN.flag

export PATH="${CONDA}/bin:${PATH}"

curl \
-sL \
-o ${HOME}/miniforge.sh \
https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh

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

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

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

source activate docs-env
make clean html || exit -1

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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: docs-env
channels:
- nodefaults
- conda-forge
dependencies:
- breathe
- python=3.9
- 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.