1
- # -*- coding: utf-8 -*-
2
- #
3
- # documentation build configuration file, created by
4
- # sphinx-quickstart on Thu Jul 23 19:40:08 2015.
5
- #
6
- # This file is execfile()d with the current directory set to its
7
- # containing dir.
8
- #
9
- # Note that not all possible configuration values are present in this
10
- # autogenerated file.
11
- #
12
- # All configuration values have a default; values that are commented out
13
- # serve to show the default.
1
+ """Sphinx configuration.
2
+
3
+ See `doc/contrib/docs.rst <https://xgboost.readthedocs.io/en/stable/contrib/docs.html>`__
4
+ for more info.
5
+ """
6
+
14
7
import os
15
- import re
16
8
import shutil
17
9
import subprocess
18
10
import sys
26
18
TMP_DIR = os .path .join (CURR_PATH , "tmp" )
27
19
DOX_DIR = "doxygen"
28
20
21
+ # Directly load the source module.
22
+ sys .path .append (os .path .join (PROJECT_ROOT , "python-package" ))
23
+ # Tell xgboost to not load the libxgboost.so
29
24
os .environ ["XGBOOST_BUILD_DOC" ] = "1"
30
25
31
26
# Version information.
35
30
release = xgboost .__version__
36
31
37
32
38
- def run_doxygen ():
33
+ # Document is uploaded to here by the CI builder.
34
+ S3_BUCKET = "https://xgboost-docs.s3.us-west-2.amazonaws.com"
35
+
36
+
37
+ def run_doxygen () -> None :
39
38
"""Run the doxygen make command in the designated folder."""
40
39
curdir = os .path .normpath (os .path .abspath (os .path .curdir ))
41
40
if os .path .exists (TMP_DIR ):
@@ -67,33 +66,74 @@ def run_doxygen():
67
66
os .chdir (curdir )
68
67
69
68
70
- def build_jvm_docs ():
71
- """Build docs for the JVM packages"""
72
- git_branch = os .getenv ("READTHEDOCS_VERSION_NAME" , default = None )
73
- print (f"READTHEDOCS_VERSION_NAME = { git_branch } " )
69
+ def get_branch () -> str :
70
+ """Guess the git branch."""
71
+ branch = os .getenv ("READTHEDOCS_VERSION_NAME" , default = None )
72
+ print (f"READTHEDOCS_VERSION_NAME = { branch } " )
73
+
74
+ def is_id ():
75
+ try :
76
+ return str (int (branch )) == branch
77
+ except ValueError :
78
+ return False
79
+
80
+ if not branch : # Not in RTD
81
+ branch = "master" # use the master branch as the default.
82
+ elif branch == "latest" :
83
+ branch = "master"
84
+ elif branch .startswith ("release_" ):
85
+ pass # release branch, like: release_2.1.0
86
+ elif branch == "stable" :
87
+ branch = f"release_{ xgboost .__version__ } "
88
+ elif is_id ():
89
+ # Likely PR branch
90
+ branch = f"PR-{ branch } "
91
+ else : # other dmlc branches.
92
+ pass
93
+ print (f"branch = { branch } " )
94
+ return branch
95
+
96
+
97
+ def get_sha (branch : str ) -> str | None :
98
+ sha = os .getenv ("READTHEDOCS_GIT_COMMIT_HASH" , default = None )
99
+ if sha is not None :
100
+ return sha
101
+
102
+ if branch == "master" :
103
+ res = subprocess .run (["git" , "rev-parse" , "master" ], stdout = subprocess .PIPE )
104
+ else :
105
+ res = subprocess .run (["git" , "rev-parse" , "HEAD" ], stdout = subprocess .PIPE )
106
+ if res .returncode != 0 :
107
+ return None
108
+ return res .stdout .decode ("utf-8" ).strip ()
109
+
74
110
75
- if not git_branch :
76
- git_branch = "master "
77
- elif git_branch == "latest" :
78
- git_branch = "master"
79
- elif git_branch == "stable" :
80
- git_branch = f"release_ { xgboost . __version__ } "
81
- print ( f"git_branch = { git_branch } " )
111
+ def build_jvm_docs () -> None :
112
+ """Fetch docs for the JVM packages"" "
113
+ branch = get_branch ()
114
+ commit = get_sha ( branch )
115
+ if commit is None :
116
+ print ( "Couldn't find commit to build jvm docs." )
117
+ return
82
118
83
- def try_fetch_jvm_doc (branch ) :
119
+ def try_fetch_jvm_doc (branch : str ) -> bool :
84
120
"""
85
121
Attempt to fetch JVM docs for a given branch.
86
122
Returns True if successful
87
123
"""
88
124
try :
89
- url = f"https://s3-us-west-2.amazonaws.com/xgboost-docs/{ branch } .tar.bz2"
90
- filename , _ = urllib .request .urlretrieve (url )
125
+ local_jvm_docs = os .environ .get ("XGBOOST_JVM_DOCS" , None )
126
+ if local_jvm_docs is not None :
127
+ filename = os .path .expanduser (local_jvm_docs )
128
+ else :
129
+ url = f"{ S3_BUCKET } /{ branch } /{ commit } /{ branch } .tar.bz2"
130
+ filename , _ = urllib .request .urlretrieve (url )
131
+ print (f"Finished: { url } -> { filename } " )
91
132
if not os .path .exists (TMP_DIR ):
92
133
print (f"Create directory { TMP_DIR } " )
93
134
os .mkdir (TMP_DIR )
94
135
jvm_doc_dir = os .path .join (TMP_DIR , "jvm_docs" )
95
136
if os .path .exists (jvm_doc_dir ):
96
- print (f"Delete directory { jvm_doc_dir } " )
97
137
shutil .rmtree (jvm_doc_dir )
98
138
print (f"Create directory { jvm_doc_dir } " )
99
139
os .mkdir (jvm_doc_dir )
@@ -105,8 +145,8 @@ def try_fetch_jvm_doc(branch):
105
145
print (f"JVM doc not found at { url } . Skipping..." )
106
146
return False
107
147
108
- if not try_fetch_jvm_doc (git_branch ):
109
- print (f "Falling back to the master branch.. ." )
148
+ if not try_fetch_jvm_doc (branch ):
149
+ print ("Falling back to the master branch." )
110
150
try_fetch_jvm_doc ("master" )
111
151
112
152
0 commit comments