-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
DOC: Doc build for a single doc made much faster, and clean up #24428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2571572
83c3b45
a5e7ad2
0fda07e
e851cae
fc9c359
8e1e9e4
ade46e6
648da45
c489aa6
2be1d61
55e47a2
4406988
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,23 +13,17 @@ | |
|
||
import sys | ||
import os | ||
import re | ||
import inspect | ||
import importlib | ||
import logging | ||
import warnings | ||
|
||
import jinja2 | ||
from sphinx.ext.autosummary import _import_by_name | ||
from numpydoc.docscrape import NumpyDocString | ||
from numpydoc.docscrape_sphinx import SphinxDocString | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can remove the raw_input yes? as we only build on py3 now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, and actually it wasn't used, so should still run in py2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, its actualy totally fine to have only py3 doc building now. |
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
try: | ||
raw_input # Python 2 | ||
except NameError: | ||
raw_input = input # Python 3 | ||
|
||
# https://github.com/sphinx-doc/sphinx/pull/2325/files | ||
# Workaround for sphinx-build recursion limit overflow: | ||
# pickle.dump(doctree, f, pickle.HIGHEST_PROTOCOL) | ||
|
@@ -77,18 +71,47 @@ | |
] | ||
|
||
exclude_patterns = ['**.ipynb_checkpoints'] | ||
|
||
with open("index.rst") as f: | ||
index_rst_lines = f.readlines() | ||
|
||
# only include the slow autosummary feature if we're building the API section | ||
# of the docs | ||
|
||
# JP: added from sphinxdocs | ||
autosummary_generate = False | ||
|
||
if any(re.match(r"\s*api\s*", l) for l in index_rst_lines): | ||
autosummary_generate = True | ||
try: | ||
import nbconvert | ||
except ImportError: | ||
logger.warn('nbconvert not installed. Skipping notebooks.') | ||
exclude_patterns.append('**/*.ipynb') | ||
else: | ||
try: | ||
nbconvert.utils.pandoc.get_pandoc_version() | ||
except nbconvert.utils.pandoc.PandocMissing: | ||
logger.warn('Pandoc not installed. Skipping notebooks.') | ||
exclude_patterns.append('**/*.ipynb') | ||
|
||
# sphinx_pattern can be '-api' to exclude the API pages, | ||
# the path to a file, or a Python object | ||
# (e.g. '10min.rst' or 'pandas.DataFrame.head') | ||
source_path = os.path.dirname(os.path.abspath(__file__)) | ||
pattern = os.environ.get('SPHINX_PATTERN') | ||
if pattern: | ||
for dirname, dirs, fnames in os.walk(source_path): | ||
for fname in fnames: | ||
if os.path.splitext(fname)[-1] in ('.rst', '.ipynb'): | ||
fname = os.path.relpath(os.path.join(dirname, fname), | ||
source_path) | ||
|
||
if (fname == 'index.rst' | ||
and os.path.abspath(dirname) == source_path): | ||
continue | ||
elif (pattern == '-api' | ||
and (fname == 'api.rst' or dirname == 'generated')): | ||
exclude_patterns.append(fname) | ||
elif fname != pattern: | ||
exclude_patterns.append(fname) | ||
|
||
with open(os.path.join(source_path, 'index.rst.template')) as f: | ||
t = jinja2.Template(f.read()) | ||
with open(os.path.join(source_path, 'index.rst'), 'w') as f: | ||
f.write(t.render(include_api=pattern is None, | ||
single_doc=(pattern | ||
if pattern is not None and pattern != '-api' | ||
else None))) | ||
autosummary_generate = True if pattern is None else ['index'] | ||
|
||
# matplotlib plot directive | ||
plot_include_source = True | ||
|
@@ -277,10 +300,11 @@ | |
"{new}.{method}".format(new=new, method=method)) | ||
) | ||
|
||
html_additional_pages = { | ||
'generated/' + page[0]: 'api_redirect.html' | ||
for page in moved_api_pages | ||
} | ||
if pattern is None: | ||
html_additional_pages = { | ||
'generated/' + page[0]: 'api_redirect.html' | ||
for page in moved_api_pages | ||
} | ||
|
||
|
||
header = """\ | ||
|
@@ -370,18 +394,17 @@ | |
# latex_use_modindex = True | ||
|
||
|
||
intersphinx_mapping = { | ||
'dateutil': ("https://dateutil.readthedocs.io/en/latest/", None), | ||
'matplotlib': ('https://matplotlib.org/', None), | ||
'numpy': ('https://docs.scipy.org/doc/numpy/', None), | ||
'pandas-gbq': ('https://pandas-gbq.readthedocs.io/en/latest/', None), | ||
'py': ('https://pylib.readthedocs.io/en/latest/', None), | ||
'python': ('https://docs.python.org/3/', None), | ||
'scipy': ('https://docs.scipy.org/doc/scipy/reference/', None), | ||
'statsmodels': ('http://www.statsmodels.org/devel/', None), | ||
} | ||
import glob | ||
autosummary_generate = glob.glob("*.rst") | ||
if pattern is None: | ||
intersphinx_mapping = { | ||
'dateutil': ("https://dateutil.readthedocs.io/en/latest/", None), | ||
'matplotlib': ('https://matplotlib.org/', None), | ||
'numpy': ('https://docs.scipy.org/doc/numpy/', None), | ||
'pandas-gbq': ('https://pandas-gbq.readthedocs.io/en/latest/', None), | ||
'py': ('https://pylib.readthedocs.io/en/latest/', None), | ||
'python': ('https://docs.python.org/3/', None), | ||
'scipy': ('https://docs.scipy.org/doc/scipy/reference/', None), | ||
'statsmodels': ('http://www.statsmodels.org/devel/', None), | ||
} | ||
|
||
# extlinks alias | ||
extlinks = {'issue': ('https://github.com/pandas-dev/pandas/issues/%s', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the DocBuilder init, the default is 1. Make them both the same?
What does a value of 0 do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. with
0
I don't pass a-j
value tosphinx-build
, while with1
, I pass-j 1
, which is actually the same (unless sphinx changes its default).It's a bit weird, because the
-j
parameter is supposed to makesphinx-build
run with multiple cores, but it actually doesn't work, and the process takes exactly the same with-j 1
and-j 4
. It could make sense to remove this option, but I guess at some point sphinx will be fixed at some point, so I guess it's worth leaving it.I'm happy setting our default to
0
(use sphinx default),1
, orauto
, just let me know if you have a preference.I address your other comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I think multiple cores speeds things up for me, at least for a full doc build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked it with
time
in Linux, 1 vs 4 cores, it took 17m30s in both cases (with a difference of less than 5 seconds between them). I tried it in the past with a different computer (also Linux) and was the same.