21
21
import warnings
22
22
from urllib .error import HTTPError
23
23
24
- from sh .contrib import git
25
-
26
24
CURR_PATH = os .path .dirname (os .path .abspath (os .path .expanduser (__file__ )))
27
25
PROJECT_ROOT = os .path .normpath (os .path .join (CURR_PATH , os .path .pardir ))
28
26
TMP_DIR = os .path .join (CURR_PATH , "tmp" )
@@ -61,6 +59,49 @@ def run_doxygen():
61
59
os .chdir (curdir )
62
60
63
61
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
+
64
105
def is_readthedocs_build ():
65
106
if os .environ .get ("READTHEDOCS" , None ) == "True" :
66
107
return True
@@ -75,40 +116,9 @@ def is_readthedocs_build():
75
116
76
117
if is_readthedocs_build ():
77
118
run_doxygen ()
119
+ build_jvm_docs ()
78
120
79
121
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
-
112
122
# If extensions (or modules to document with autodoc) are in another directory,
113
123
# add these directories to sys.path here. If the directory is relative to the
114
124
# documentation root, use os.path.abspath to make it absolute, like shown here.
@@ -152,7 +162,7 @@ def is_readthedocs_build():
152
162
"../demo/dask" ,
153
163
"../demo/aft_survival" ,
154
164
"../demo/gpu_acceleration" ,
155
- "../demo/rmm_plugin"
165
+ "../demo/rmm_plugin" ,
156
166
],
157
167
# path to where to save gallery generated output
158
168
"gallery_dirs" : [
0 commit comments