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

[Doc] Fix deployment for JVM docs #10385

Merged
merged 5 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
80 changes: 45 additions & 35 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import warnings
from urllib.error import HTTPError

from sh.contrib import git

CURR_PATH = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
PROJECT_ROOT = os.path.normpath(os.path.join(CURR_PATH, os.path.pardir))
TMP_DIR = os.path.join(CURR_PATH, "tmp")
Expand Down Expand Up @@ -61,6 +59,49 @@ def run_doxygen():
os.chdir(curdir)


def build_jvm_docs():
"""Build docs for the JVM packages"""
git_branch = os.getenv("READTHEDOCS_VERSION_NAME", default=None)
print(f"READTHEDOCS_VERSION_NAME = {git_branch}")

if not git_branch:
git_branch = "master"
elif git_branch == "latest":
git_branch = "master"
elif git_branch == "stable":
git_branch = f"release_{version}"
print(f"git_branch = {git_branch}")

hcho3 marked this conversation as resolved.
Show resolved Hide resolved
def try_fetch_jvm_doc(branch):
"""
Attempt to fetch JVM docs for a given branch.
Returns True if successful
"""
try:
url = f"https://s3-us-west-2.amazonaws.com/xgboost-docs/{branch}.tar.bz2"
filename, _ = urllib.request.urlretrieve(url)
if not os.path.exists(TMP_DIR):
print(f"Create directory {TMP_DIR}")
os.mkdir(TMP_DIR)
jvm_doc_dir = os.path.join(TMP_DIR, "jvm_docs")
if os.path.exists(jvm_doc_dir):
print(f"Delete directory {jvm_doc_dir}")
shutil.rmtree(jvm_doc_dir)
print(f"Create directory {jvm_doc_dir}")
os.mkdir(jvm_doc_dir)

with tarfile.open(filename, "r:bz2") as t:
t.extractall(jvm_doc_dir)
return True
except HTTPError:
print(f"JVM doc not found at {url}. Skipping...")
return False

if not try_fetch_jvm_doc(git_branch):
print(f"Falling back to the master branch...")
try_fetch_jvm_doc("master")


def is_readthedocs_build():
if os.environ.get("READTHEDOCS", None) == "True":
return True
Expand All @@ -75,40 +116,9 @@ def is_readthedocs_build():

if is_readthedocs_build():
run_doxygen()
build_jvm_docs()


git_branch = os.getenv("SPHINX_GIT_BRANCH", default=None)
if not git_branch:
# If SPHINX_GIT_BRANCH environment variable is not given, run git
# to determine branch name
git_branch = [
re.sub(r"origin/", "", x.lstrip(" "))
for x in str(git.branch("-r", "--contains", "HEAD")).rstrip("\n").split("\n")
]
git_branch = [x for x in git_branch if "HEAD" not in x]
else:
git_branch = [git_branch]
print("git_branch = {}".format(git_branch[0]))

try:
filename, _ = urllib.request.urlretrieve(
f"https://s3-us-west-2.amazonaws.com/xgboost-docs/{git_branch[0]}.tar.bz2"
)
if not os.path.exists(TMP_DIR):
print(f"Create directory {TMP_DIR}")
os.mkdir(TMP_DIR)
jvm_doc_dir = os.path.join(TMP_DIR, "jvm")
if os.path.exists(jvm_doc_dir):
print(f"Delete directory {jvm_doc_dir}")
shutil.rmtree(jvm_doc_dir)
print(f"Create directory {jvm_doc_dir}")
os.mkdir(jvm_doc_dir)

with tarfile.open(filename, "r:bz2") as t:
t.extractall(jvm_doc_dir)
except HTTPError:
print("JVM doc not found. Skipping...")

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
Expand Down Expand Up @@ -152,7 +162,7 @@ def is_readthedocs_build():
"../demo/dask",
"../demo/aft_survival",
"../demo/gpu_acceleration",
"../demo/rmm_plugin"
"../demo/rmm_plugin",
],
# path to where to save gallery generated output
"gallery_dirs": [
Expand Down
8 changes: 8 additions & 0 deletions doc/jvm/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#############################
API Docs for the JVM packages
#############################

* `XGBoost4J Java API <../jvm_docs/javadocs/index.html>`_
* `XGBoost4J Scala API <../jvm_docs/scaladocs/xgboost4j/index.html>`_
* `XGBoost4J-Spark Scala API <../jvm_docs/scaladocs/xgboost4j-spark/index.html>`_
* `XGBoost4J-Flink Scala API <../jvm_docs/scaladocs/xgboost4j-flink/index.html>`_
5 changes: 1 addition & 4 deletions doc/jvm/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ Contents
XGBoost4J-Spark Tutorial <xgboost4j_spark_tutorial>
XGBoost4J-Spark-GPU Tutorial <xgboost4j_spark_gpu_tutorial>
Code Examples <https://github.com/dmlc/xgboost/tree/master/jvm-packages/xgboost4j-example>
XGBoost4J Java API <javadocs/index>
XGBoost4J Scala API <scaladocs/xgboost4j/index>
XGBoost4J-Spark Scala API <scaladocs/xgboost4j-spark/index>
XGBoost4J-Flink Scala API <scaladocs/xgboost4j-flink/index>
API docs <api>

.. note::

Expand Down
Loading