Skip to content

Commit

Permalink
pull over readthedocs config from master
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb committed Oct 9, 2022
1 parent 097a14e commit 6b396e8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
10 changes: 6 additions & 4 deletions .readthedocs.yaml
@@ -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
40 changes: 19 additions & 21 deletions docs/conf.py
Expand Up @@ -25,7 +25,6 @@
from shutil import copytree
from subprocess import PIPE, Popen
from typing import Any, List
from unittest.mock import Mock

import sphinx
from docutils.nodes import reference
Expand All @@ -40,12 +39,6 @@

INTERNAL_REF_REGEX = compile(r"(?P<url>\.\/.+)(?P<extension>\.rst)(?P<anchor>$|#)")

# -- mock out modules
MOCK_MODULES = ['numpy', 'scipy', 'scipy.sparse',
'sklearn', 'matplotlib', 'pandas', 'graphviz', 'dask', 'dask.distributed']
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = Mock()


class InternalRefTransform(Transform):
"""Replaces '.rst' with '.html' in all internal links like './[Something].rst[#anchor]'."""
Expand Down Expand Up @@ -99,7 +92,22 @@ def run(self) -> List:
"inherited-members": True,
"show-inheritance": True,
}

# mock out modules
autodoc_mock_imports = [
'dask',
'dask.distributed',
'datatable',
'graphviz',
'matplotlib',
'numpy',
'pandas',
'scipy',
'scipy.sparse',
]
try:
import sklearn
except ImportError:
autodoc_mock_imports.append('sklearn')
# hide type hints in API docs
autodoc_typehints = "none"

Expand Down Expand Up @@ -142,7 +150,7 @@ def run(self) -> List:
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = 'en'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down Expand Up @@ -254,18 +262,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 \
-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-matrix=1.3_4=r41he454529_0 \
r-pkgdown=1.6.1=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 @@ -290,6 +286,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 @@ -303,6 +300,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
18 changes: 18 additions & 0 deletions docs/env.yml
@@ -0,0 +1,18 @@
name: docs-env
channels:
- nodefaults
- conda-forge
dependencies:
- breathe
- python=3.9
- r-base=4.1.3
- 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.2.1
- scikit-learn
- sphinx
- "sphinx_rtd_theme>=0.5"

0 comments on commit 6b396e8

Please sign in to comment.