diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index d52a7983d..d2c41890d 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -44,6 +44,10 @@ class Builder(object): versioning_method = 'none' # allow parallel write_doc() calls allow_parallel = False + # basename of images directory + imagedir = "" + # relative path to image directory from current docname (used at writing docs) + imgpath = "" def __init__(self, app): self.env = app.env diff --git a/sphinx/builders/epub.py b/sphinx/builders/epub.py index 5f9f66431..848dfaa43 100644 --- a/sphinx/builders/epub.py +++ b/sphinx/builders/epub.py @@ -404,7 +404,7 @@ class EpubBuilder(StandaloneHTMLBuilder): The method tries to read and write the files with the PIL, converting the format and resizing the image if necessary/possible. """ - ensuredir(path.join(self.outdir, '_images')) + ensuredir(path.join(self.outdir, self.imagedir)) for src in self.app.status_iterator(self.images, 'copying images... ', brown, len(self.images)): dest = self.images[src] @@ -416,7 +416,7 @@ class EpubBuilder(StandaloneHTMLBuilder): (path.join(self.srcdir, src), )) try: copyfile(path.join(self.srcdir, src), - path.join(self.outdir, '_images', dest)) + path.join(self.outdir, self.imagedir, dest)) except (IOError, OSError) as err: self.warn('cannot copy image file %r: %s' % (path.join(self.srcdir, src), err)) @@ -432,7 +432,7 @@ class EpubBuilder(StandaloneHTMLBuilder): nh = (height * nw) / width img = img.resize((nw, nh), Image.BICUBIC) try: - img.save(path.join(self.outdir, '_images', dest)) + img.save(path.join(self.outdir, self.imagedir, dest)) except (IOError, OSError) as err: self.warn('cannot write image file %r: %s' % (path.join(self.srcdir, src), err)) diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index c2c308937..4c7155fd7 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -73,6 +73,7 @@ class StandaloneHTMLBuilder(Builder): link_suffix = '.html' # defaults to matching out_suffix indexer_format = js_index indexer_dumps_unicode = True + imagedir = '_images' supported_image_types = ['image/svg+xml', 'image/png', 'image/gif', 'image/jpeg'] searchindex_filename = 'searchindex.js' @@ -424,7 +425,7 @@ class StandaloneHTMLBuilder(Builder): doctree.settings = self.docsettings self.secnumbers = self.env.toc_secnumbers.get(docname, {}) - self.imgpath = relative_uri(self.get_target_uri(docname), '_images') + self.imgpath = relative_uri(self.get_target_uri(docname), self.imagedir) self.dlpath = relative_uri(self.get_target_uri(docname), '_downloads') self.current_docname = docname self.docwriter.write(doctree, destination) @@ -436,7 +437,7 @@ class StandaloneHTMLBuilder(Builder): self.handle_page(docname, ctx, event_arg=doctree) def write_doc_serialized(self, docname, doctree): - self.imgpath = relative_uri(self.get_target_uri(docname), '_images') + self.imgpath = relative_uri(self.get_target_uri(docname), self.imagedir) self.post_process_images(doctree) title = self.env.longtitles.get(docname) title = title and self.render_partial(title)['title'] or '' @@ -534,13 +535,13 @@ class StandaloneHTMLBuilder(Builder): def copy_image_files(self): # copy image files if self.images: - ensuredir(path.join(self.outdir, '_images')) + ensuredir(path.join(self.outdir, self.imagedir)) for src in self.app.status_iterator(self.images, 'copying images... ', brown, len(self.images)): dest = self.images[src] try: copyfile(path.join(self.srcdir, src), - path.join(self.outdir, '_images', dest)) + path.join(self.outdir, self.imagedir, dest)) except Exception as err: self.warn('cannot copy image file %r: %s' % (path.join(self.srcdir, src), err)) diff --git a/sphinx/builders/qthelp.py b/sphinx/builders/qthelp.py index c0fff2a6a..8e2558e72 100644 --- a/sphinx/builders/qthelp.py +++ b/sphinx/builders/qthelp.py @@ -157,7 +157,7 @@ class QtHelpBuilder(StandaloneHTMLBuilder): olen = len(outdir) projectfiles = [] staticdir = path.join(outdir, '_static') - imagesdir = path.join(outdir, '_images') + imagesdir = path.join(outdir, self.imagedir) for root, dirs, files in os.walk(outdir): resourcedir = root.startswith(staticdir) or \ root.startswith(imagesdir) diff --git a/sphinx/builders/websupport.py b/sphinx/builders/websupport.py index 7b0e6f724..0a99b5021 100644 --- a/sphinx/builders/websupport.py +++ b/sphinx/builders/websupport.py @@ -58,7 +58,8 @@ class WebSupportBuilder(PickleHTMLBuilder): doctree.settings = self.docsettings self.secnumbers = self.env.toc_secnumbers.get(docname, {}) - self.imgpath = '/' + posixpath.join(self.virtual_staticdir, '_images') + self.imgpath = '/' + posixpath.join(self.virtual_staticdir, self.imagedir) + print self.imgpath self.dlpath = '/' + posixpath.join(self.virtual_staticdir, '_downloads') self.current_docname = docname self.docwriter.write(doctree, destination) @@ -70,7 +71,8 @@ class WebSupportBuilder(PickleHTMLBuilder): self.handle_page(docname, ctx, event_arg=doctree) def write_doc_serialized(self, docname, doctree): - self.imgpath = '/' + posixpath.join(self.virtual_staticdir, '_images') + self.imgpath = '/' + posixpath.join(self.virtual_staticdir, self.imagedir) + print self.imgpath self.post_process_images(doctree) title = self.env.longtitles.get(docname) title = title and self.render_partial(title)['title'] or '' @@ -148,7 +150,8 @@ class WebSupportBuilder(PickleHTMLBuilder): PickleHTMLBuilder.handle_finish(self) # move static stuff over to separate directory - directories = ['_images', '_static'] + directories = [self.imagedir, '_static'] + print directories for directory in directories: src = path.join(self.outdir, directory) dst = path.join(self.staticdir, directory) diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py index 56831c648..71e7ba651 100644 --- a/sphinx/ext/graphviz.py +++ b/sphinx/ext/graphviz.py @@ -146,14 +146,8 @@ def render_dot(self, code, options, format, prefix='graphviz'): ).encode('utf-8') fname = '%s-%s.%s' % (prefix, sha1(hashkey).hexdigest(), format) - if hasattr(self.builder, 'imgpath'): - # HTML - relfn = posixpath.join(self.builder.imgpath, fname) - outfn = path.join(self.builder.outdir, '_images', fname) - else: - # LaTeX - relfn = fname - outfn = path.join(self.builder.outdir, fname) + relfn = posixpath.join(self.builder.imgpath, fname) + outfn = path.join(self.builder.outdir, self.builder.imagedir, fname) if path.isfile(outfn): return relfn, outfn diff --git a/sphinx/ext/pngmath.py b/sphinx/ext/pngmath.py index 27d7978fe..81a6f9d57 100644 --- a/sphinx/ext/pngmath.py +++ b/sphinx/ext/pngmath.py @@ -86,7 +86,7 @@ def render_math(self, math): shasum = "%s.png" % sha1(latex.encode('utf-8')).hexdigest() relfn = posixpath.join(self.builder.imgpath, 'math', shasum) - outfn = path.join(self.builder.outdir, '_images', 'math', shasum) + outfn = path.join(self.builder.outdir, self.builder.imagedir, 'math', shasum) if path.isfile(outfn): depth = read_png_depth(outfn) return relfn, depth