diff --git a/doc/conf.py b/doc/conf.py index 39198799c6ac..baf66d20fbf1 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -19,6 +19,7 @@ import tarfile import urllib.request import warnings +import tempfile from urllib.error import HTTPError CURR_PATH = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) @@ -111,37 +112,43 @@ def try_fetch_jvm_doc(branch): def build_r_docs() -> None: - """Build document for thte R package.""" + """Build sphinx document for the R package based on the existing files from + roxygen. + + """ curdir = os.path.normpath(os.path.abspath(os.path.curdir)) - try: - repo = "\"https://cran.us.r-project.org\"" - subprocess.check_call( - [ - "Rscript", - "-e", - f"install.packages(c(\"pkgdown\"), repos = {repo})" - ] - ) + with tempfile.TemporaryDirectory() as tmpdir: + try: + env = os.environ.copy() + env.update({"MAKEFLAGS": f"-j{os.cpu_count()}", "R_LIBS_USER": tmpdir}) + + repo = "https://cran.us.r-project.org" + subprocess.check_call( + [ + "Rscript", + "-e", + f"install.packages(c(\"pkgdown\"), repos = \"{repo}\")" + ], + env=env, + ) - os.chdir(os.path.join(PROJECT_ROOT, "R-package")) - env = os.environ.copy() - env.update({"MAKEFLAGS": f"-j{os.cpu_count()}"}) - subprocess.check_call(["Rscript", "-e", "pkgdown::build_site()"], env=env) - src = os.path.join(PROJECT_ROOT, "R-package", "docs") - dest = os.path.join(TMP_DIR, "r_docs") - if not os.path.exists(TMP_DIR): - os.mkdir(TMP_DIR) - if os.path.exists(dest): - shutil.rmtree(dest) - print(f"Copy directory {src} -> {dest}") - shutil.copytree(src, dest) + os.chdir(os.path.join(PROJECT_ROOT, "R-package")) + subprocess.check_call(["Rscript", "-e", "pkgdown::build_site()"], env=env) + src = os.path.join(PROJECT_ROOT, "R-package", "docs") + dest = os.path.join(TMP_DIR, "r_docs") + if not os.path.exists(TMP_DIR): + os.mkdir(TMP_DIR) + if os.path.exists(dest): + shutil.rmtree(dest) + print(f"Copy directory {src} -> {dest}") + shutil.copytree(src, dest) - os.chdir(os.path.join(PROJECT_ROOT, "doc", "R-package")) - subprocess.check_call(["make", "xgboostfromJSON.md"]) + os.chdir(os.path.join(PROJECT_ROOT, "doc", "R-package")) + subprocess.check_call(["make", "xgboostfromJSON.md"], env=env) - finally: - os.chdir(curdir) + finally: + os.chdir(curdir) def is_readthedocs_build(): @@ -158,7 +165,7 @@ def is_readthedocs_build(): if is_readthedocs_build(): run_doxygen() - build_jvm_docs() + # build_jvm_docs() build_r_docs()