Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 03a3b8e

Browse files
committed
Fix multiprocessing of gallery. Change how gallery.html is generated to prevent a full rebuild.
svn path=/trunk/matplotlib/; revision=7765
1 parent e46a427 commit 03a3b8e

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

doc/sphinxext/gen_gallery.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
multiimage = re.compile('(.*)_\d\d')
2020

21+
def make_thumbnail(args):
22+
image.thumbnail(args[0], args[1], 0.3)
23+
2124
def out_of_date(original, derived):
2225
return (not os.path.exists(derived) or
2326
os.stat(derived).st_mtime < os.stat(original).st_mtime)
@@ -87,16 +90,23 @@ def gen_gallery(app, doctree):
8790
link = 'examples/%s/%s.html'%(subdir, basename)
8891
rows.append(link_template%(link, thumbfile, basename))
8992

90-
fh = file(os.path.join(app.builder.srcdir, '_templates', 'gallery.html'),
91-
'w')
92-
fh.write(template%'\n'.join(rows))
93-
fh.close()
93+
# Only write out the file if the contents have actually changed.
94+
# Otherwise, this triggers a full rebuild of the docs
95+
content = template%'\n'.join(rows)
96+
gallery_path = os.path.join(app.builder.srcdir, '_templates', 'gallery.html')
97+
if os.path.exists(gallery_path):
98+
fh = file(gallery_path, 'r')
99+
regenerate = fh.read() != content
100+
fh.close()
101+
else:
102+
regenerate = True
103+
if regenerate:
104+
fh = file(gallery_path, 'w')
105+
fh.write(content)
106+
fh.close()
94107

95108
try:
96109
import multiprocessing
97-
def make_thumbnail(args):
98-
image.thumbnail(args[0], args[1], 0.3)
99-
100110
app.builder.info("generating thumbnails... ", nonl=True)
101111
pool = multiprocessing.Pool()
102112
pool.map(make_thumbnail, thumbnails.iteritems())

0 commit comments

Comments
 (0)