Skip to content

Commit 43e3eb7

Browse files
authored
Merge pull request #1043 from pytorch/pr/reduce-recomp
Reduce amount of unnecessary recompilation done by sphinx
2 parents b511d95 + 740c3a6 commit 43e3eb7

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ docs:
108108
touch docs/.nojekyll
109109

110110
html-noplot:
111-
make clean
112111
$(SPHINXBUILD) -D plot_gallery=0 -b html $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)/html"
113112
# bash .jenkins/remove_invisible_code_block_batch.sh "$(BUILDDIR)/html"
114113
@echo

conf.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import glob
3636
import shutil
3737
from custom_directives import IncludeDirective, GalleryItemDirective, CustomGalleryItemDirective, CustomCalloutItemDirective, CustomCardItemDirective
38+
import distutils.file_util
39+
import re
3840

3941

4042
try:
@@ -63,10 +65,19 @@
6365
'examples_dirs': ['beginner_source', 'intermediate_source',
6466
'advanced_source', 'recipes_source'],
6567
'gallery_dirs': ['beginner', 'intermediate', 'advanced', 'recipes'],
66-
'filename_pattern': os.environ.get('GALLERY_PATTERN', r'tutorial.py'),
6768
'backreferences_dir': False
6869
}
6970

71+
if os.getenv('GALLERY_PATTERN'):
72+
# GALLERY_PATTERN is to be used when you want to work on a single
73+
# tutorial. Previously this was fed into filename_pattern, but
74+
# if you do that, you still end up parsing all of the other Python
75+
# files which takes a few seconds. This strategy is better, as
76+
# ignore_pattern also skips parsing.
77+
# See https://github.com/sphinx-gallery/sphinx-gallery/issues/721
78+
# for a more detailed description of the issue.
79+
sphinx_gallery_conf['ignore_pattern'] = r'/(?!' + re.escape(os.getenv('GALLERY_PATTERN')) + r')[^/]+$'
80+
7081
for i in range(len(sphinx_gallery_conf['examples_dirs'])):
7182
gallery_dir = sphinx_gallery_conf['gallery_dirs'][i]
7283
source_dir = sphinx_gallery_conf['examples_dirs'][i]
@@ -78,7 +89,7 @@
7889

7990
# Copy rst files from source dir to gallery dir
8091
for f in glob.glob(os.path.join(source_dir, '*.rst')):
81-
shutil.copy(f, gallery_dir)
92+
distutils.file_util.copy_file(f, gallery_dir, update=True)
8293

8394

8495
# Add any paths that contain templates here, relative to this directory.

0 commit comments

Comments
 (0)