Skip to content

Commit

Permalink
install dir.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Jan 14, 2025
1 parent 7eb40e5 commit 0e0ade4
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)))
Expand Down Expand Up @@ -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():
Expand All @@ -158,7 +165,7 @@ def is_readthedocs_build():

if is_readthedocs_build():
run_doxygen()
build_jvm_docs()
# build_jvm_docs()
build_r_docs()


Expand Down

0 comments on commit 0e0ade4

Please sign in to comment.