Skip to content

Commit d603953

Browse files
trivialfisCopilot
andauthored
[doc] Reuse cached artifacts. (#11560)
--------- Co-authored-by: Copilot <[email protected]>
1 parent 16e3cb5 commit d603953

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

doc/conf.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,18 @@ def try_fetch_jvm_doc(branch: str) -> bool:
124124
"""
125125
try:
126126
local_jvm_docs = os.environ.get("XGBOOST_JVM_DOCS", None)
127+
url = f"{S3_BUCKET}/{branch}/{commit}/{branch}.tar.bz2"
127128
if local_jvm_docs is not None:
128-
filename = os.path.expanduser(local_jvm_docs)
129+
local_jvm_docs = os.path.expanduser(local_jvm_docs)
130+
131+
if local_jvm_docs is not None and os.path.exists(local_jvm_docs):
132+
# Reuse an existing tarball.
133+
filename = local_jvm_docs
134+
elif local_jvm_docs is not None:
135+
# Download to local_jvm_docs for future reuse.
136+
filename, _ = urllib.request.urlretrieve(url, filename=local_jvm_docs)
137+
print(f"Finished: {url} -> {filename}")
129138
else:
130-
url = f"{S3_BUCKET}/{branch}/{commit}/{branch}.tar.bz2"
131139
filename, _ = urllib.request.urlretrieve(url)
132140
print(f"Finished: {url} -> {filename}")
133141
if not os.path.exists(TMP_DIR):
@@ -161,10 +169,17 @@ def download_r_docs() -> None:
161169
def try_fetch_r_doc(branch: str) -> bool:
162170
try:
163171
local_r_docs = os.environ.get("XGBOOST_R_DOCS", None)
172+
url = f"{S3_BUCKET}/{branch}/{commit}/r-docs-{branch}.tar.bz2"
164173
if local_r_docs is not None:
165-
filename = os.path.expanduser(local_r_docs)
174+
local_r_docs = os.path.expanduser(local_r_docs)
175+
176+
if local_r_docs is not None and os.path.exists(local_r_docs):
177+
# Reuse an existing tarball.
178+
filename = local_r_docs
179+
elif local_r_docs is not None:
180+
filename, _ = urllib.request.urlretrieve(url, filename=local_r_docs)
181+
print(f"Finished: {url} -> {filename}")
166182
else:
167-
url = f"{S3_BUCKET}/{branch}/{commit}/r-docs-{branch}.tar.bz2"
168183
filename, _ = urllib.request.urlretrieve(url)
169184
print(f"Finished: {url} -> {filename}")
170185

doc/contrib/docs.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,12 @@ build directory. Following is a list of environment variables used by the fetche
107107

108108
- ``READTHEDOCS``: Read the docs flag. Build the full documentation site including R, JVM and
109109
C doc when set to ``True`` (case sensitive).
110-
- ``XGBOOST_R_DOCS``: Local path for pre-built R document, used for development.
111-
- ``XGBOOST_JVM_DOCS``: Local path for pre-built JVM document, used for development.
110+
- ``XGBOOST_R_DOCS``: Local path for pre-built R document, used for development. If it
111+
points to a file that doesn't exist, the configuration script will download the
112+
packaged document to that path for future reuse.
113+
- ``XGBOOST_JVM_DOCS``: Local path for pre-built JVM document, used for
114+
development. Similar to the R docs environment variable when it points to a non-existent
115+
file.
112116

113117
As of writing, RTD doesn't provide any facility to be embedded as a GitHub action but we
114118
need a way to specify the dependency between the CI pipelines and the document build in

0 commit comments

Comments
 (0)