Skip to content

Commit cca4901

Browse files
authored
DOC/CI: Fix building docs with --no-api (#38858)
1 parent 9159513 commit cca4901

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

doc/make.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(
4646
warnings_are_errors=False,
4747
):
4848
self.num_jobs = num_jobs
49+
self.include_api = include_api
4950
self.verbosity = verbosity
5051
self.warnings_are_errors = warnings_are_errors
5152

@@ -188,7 +189,14 @@ def _add_redirects(self):
188189
if not row or row[0].strip().startswith("#"):
189190
continue
190191

191-
path = os.path.join(BUILD_PATH, "html", *row[0].split("/")) + ".html"
192+
html_path = os.path.join(BUILD_PATH, "html")
193+
path = os.path.join(html_path, *row[0].split("/")) + ".html"
194+
195+
if not self.include_api and (
196+
os.path.join(html_path, "reference") in path
197+
or os.path.join(html_path, "generated") in path
198+
):
199+
continue
192200

193201
try:
194202
title = self._get_page_title(row[1])
@@ -198,11 +206,6 @@ def _add_redirects(self):
198206
# sphinx specific stuff
199207
title = "this page"
200208

201-
if os.path.exists(path):
202-
raise RuntimeError(
203-
f"Redirection would overwrite an existing file: {path}"
204-
)
205-
206209
with open(path, "w") as moved_page_fd:
207210
html = f"""\
208211
<html>

doc/source/conf.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -77,29 +77,32 @@
7777
try:
7878
import nbconvert
7979
except ImportError:
80-
logger.warn("nbconvert not installed. Skipping notebooks.")
80+
logger.warning("nbconvert not installed. Skipping notebooks.")
8181
exclude_patterns.append("**/*.ipynb")
8282
else:
8383
try:
8484
nbconvert.utils.pandoc.get_pandoc_version()
8585
except nbconvert.utils.pandoc.PandocMissing:
86-
logger.warn("Pandoc not installed. Skipping notebooks.")
86+
logger.warning("Pandoc not installed. Skipping notebooks.")
8787
exclude_patterns.append("**/*.ipynb")
8888

8989
# sphinx_pattern can be '-api' to exclude the API pages,
9090
# the path to a file, or a Python object
9191
# (e.g. '10min.rst' or 'pandas.DataFrame.head')
9292
source_path = os.path.dirname(os.path.abspath(__file__))
9393
pattern = os.environ.get("SPHINX_PATTERN")
94+
single_doc = pattern is not None and pattern != "-api"
95+
include_api = pattern != "-api"
9496
if pattern:
9597
for dirname, dirs, fnames in os.walk(source_path):
98+
reldir = os.path.relpath(dirname, source_path)
9699
for fname in fnames:
97100
if os.path.splitext(fname)[-1] in (".rst", ".ipynb"):
98101
fname = os.path.relpath(os.path.join(dirname, fname), source_path)
99102

100103
if fname == "index.rst" and os.path.abspath(dirname) == source_path:
101104
continue
102-
elif pattern == "-api" and dirname == "reference":
105+
elif pattern == "-api" and reldir.startswith("reference"):
103106
exclude_patterns.append(fname)
104107
elif pattern != "-api" and fname != pattern:
105108
exclude_patterns.append(fname)
@@ -109,11 +112,11 @@
109112
with open(os.path.join(source_path, "index.rst"), "w") as f:
110113
f.write(
111114
t.render(
112-
include_api=pattern is None,
113-
single_doc=(pattern if pattern is not None and pattern != "-api" else None),
115+
include_api=include_api,
116+
single_doc=(pattern if single_doc else None),
114117
)
115118
)
116-
autosummary_generate = True if pattern is None else ["index"]
119+
autosummary_generate = True if include_api else ["index"]
117120
autodoc_typehints = "none"
118121

119122
# numpydoc
@@ -315,7 +318,7 @@
315318
# ... and each of its public methods
316319
moved_api_pages.append((f"{old}.{method}", f"{new}.{method}"))
317320

318-
if pattern is None:
321+
if include_api:
319322
html_additional_pages = {
320323
"generated/" + page[0]: "api_redirect.html" for page in moved_api_pages
321324
}
@@ -411,7 +414,7 @@
411414
# latex_use_modindex = True
412415

413416

414-
if pattern is None:
417+
if include_api:
415418
intersphinx_mapping = {
416419
"dateutil": ("https://dateutil.readthedocs.io/en/latest/", None),
417420
"matplotlib": ("https://matplotlib.org/", None),

0 commit comments

Comments
 (0)