Skip to content

Commit 7667d86

Browse files
trivialfishcho3
andauthored
[backport][Doc] Fix deployment for JVM docs (dmlc#10385) (dmlc#10392)
Co-authored-by: Philip Hyunsu Cho <[email protected]>
1 parent eed3b3e commit 7667d86

File tree

3 files changed

+54
-39
lines changed

3 files changed

+54
-39
lines changed

doc/conf.py

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import warnings
2222
from urllib.error import HTTPError
2323

24-
from sh.contrib import git
25-
2624
CURR_PATH = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
2725
PROJECT_ROOT = os.path.normpath(os.path.join(CURR_PATH, os.path.pardir))
2826
TMP_DIR = os.path.join(CURR_PATH, "tmp")
@@ -61,6 +59,49 @@ def run_doxygen():
6159
os.chdir(curdir)
6260

6361

62+
def build_jvm_docs():
63+
"""Build docs for the JVM packages"""
64+
git_branch = os.getenv("READTHEDOCS_VERSION_NAME", default=None)
65+
print(f"READTHEDOCS_VERSION_NAME = {git_branch}")
66+
67+
if not git_branch:
68+
git_branch = "master"
69+
elif git_branch == "latest":
70+
git_branch = "master"
71+
elif git_branch == "stable":
72+
git_branch = f"release_{version}"
73+
print(f"git_branch = {git_branch}")
74+
75+
def try_fetch_jvm_doc(branch):
76+
"""
77+
Attempt to fetch JVM docs for a given branch.
78+
Returns True if successful
79+
"""
80+
try:
81+
url = f"https://s3-us-west-2.amazonaws.com/xgboost-docs/{branch}.tar.bz2"
82+
filename, _ = urllib.request.urlretrieve(url)
83+
if not os.path.exists(TMP_DIR):
84+
print(f"Create directory {TMP_DIR}")
85+
os.mkdir(TMP_DIR)
86+
jvm_doc_dir = os.path.join(TMP_DIR, "jvm_docs")
87+
if os.path.exists(jvm_doc_dir):
88+
print(f"Delete directory {jvm_doc_dir}")
89+
shutil.rmtree(jvm_doc_dir)
90+
print(f"Create directory {jvm_doc_dir}")
91+
os.mkdir(jvm_doc_dir)
92+
93+
with tarfile.open(filename, "r:bz2") as t:
94+
t.extractall(jvm_doc_dir)
95+
return True
96+
except HTTPError:
97+
print(f"JVM doc not found at {url}. Skipping...")
98+
return False
99+
100+
if not try_fetch_jvm_doc(git_branch):
101+
print(f"Falling back to the master branch...")
102+
try_fetch_jvm_doc("master")
103+
104+
64105
def is_readthedocs_build():
65106
if os.environ.get("READTHEDOCS", None) == "True":
66107
return True
@@ -75,40 +116,9 @@ def is_readthedocs_build():
75116

76117
if is_readthedocs_build():
77118
run_doxygen()
119+
build_jvm_docs()
78120

79121

80-
git_branch = os.getenv("SPHINX_GIT_BRANCH", default=None)
81-
if not git_branch:
82-
# If SPHINX_GIT_BRANCH environment variable is not given, run git
83-
# to determine branch name
84-
git_branch = [
85-
re.sub(r"origin/", "", x.lstrip(" "))
86-
for x in str(git.branch("-r", "--contains", "HEAD")).rstrip("\n").split("\n")
87-
]
88-
git_branch = [x for x in git_branch if "HEAD" not in x]
89-
else:
90-
git_branch = [git_branch]
91-
print("git_branch = {}".format(git_branch[0]))
92-
93-
try:
94-
filename, _ = urllib.request.urlretrieve(
95-
f"https://s3-us-west-2.amazonaws.com/xgboost-docs/{git_branch[0]}.tar.bz2"
96-
)
97-
if not os.path.exists(TMP_DIR):
98-
print(f"Create directory {TMP_DIR}")
99-
os.mkdir(TMP_DIR)
100-
jvm_doc_dir = os.path.join(TMP_DIR, "jvm")
101-
if os.path.exists(jvm_doc_dir):
102-
print(f"Delete directory {jvm_doc_dir}")
103-
shutil.rmtree(jvm_doc_dir)
104-
print(f"Create directory {jvm_doc_dir}")
105-
os.mkdir(jvm_doc_dir)
106-
107-
with tarfile.open(filename, "r:bz2") as t:
108-
t.extractall(jvm_doc_dir)
109-
except HTTPError:
110-
print("JVM doc not found. Skipping...")
111-
112122
# If extensions (or modules to document with autodoc) are in another directory,
113123
# add these directories to sys.path here. If the directory is relative to the
114124
# documentation root, use os.path.abspath to make it absolute, like shown here.
@@ -152,7 +162,7 @@ def is_readthedocs_build():
152162
"../demo/dask",
153163
"../demo/aft_survival",
154164
"../demo/gpu_acceleration",
155-
"../demo/rmm_plugin"
165+
"../demo/rmm_plugin",
156166
],
157167
# path to where to save gallery generated output
158168
"gallery_dirs": [

doc/jvm/api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#############################
2+
API Docs for the JVM packages
3+
#############################
4+
5+
* `XGBoost4J Java API <../jvm_docs/javadocs/index.html>`_
6+
* `XGBoost4J Scala API <../jvm_docs/scaladocs/xgboost4j/index.html>`_
7+
* `XGBoost4J-Spark Scala API <../jvm_docs/scaladocs/xgboost4j-spark/index.html>`_
8+
* `XGBoost4J-Flink Scala API <../jvm_docs/scaladocs/xgboost4j-flink/index.html>`_

doc/jvm/index.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ Contents
3737
XGBoost4J-Spark Tutorial <xgboost4j_spark_tutorial>
3838
XGBoost4J-Spark-GPU Tutorial <xgboost4j_spark_gpu_tutorial>
3939
Code Examples <https://github.com/dmlc/xgboost/tree/master/jvm-packages/xgboost4j-example>
40-
XGBoost4J Java API <javadocs/index>
41-
XGBoost4J Scala API <scaladocs/xgboost4j/index>
42-
XGBoost4J-Spark Scala API <scaladocs/xgboost4j-spark/index>
43-
XGBoost4J-Flink Scala API <scaladocs/xgboost4j-flink/index>
40+
API docs <api>
4441

4542
.. note::
4643

0 commit comments

Comments
 (0)