Commit b57591b4f17a27f23855143fff91449a48edb35d
1 parent
df77fdc6
Bundle rawfiles Sphinx directive for docs build
Showing
2 changed files
with
42 additions
and
0 deletions
doc/source/conf.py
| ... | ... | @@ -34,6 +34,15 @@ except: |
| 34 | 34 | 'WARNING: https://pypi.python.org/pypi/sphinxcontrib-doxylink\n') |
| 35 | 35 | extensions = ['sphinx.ext.mathjax'] |
| 36 | 36 | |
| 37 | +# http://sphinx-doc.org/extensions.html#where-to-put-your-own-extensions | |
| 38 | +sys.path.append(os.path.abspath('exts')) | |
| 39 | + | |
| 40 | +# We bundled the `rawfiles` sphinx extension to copy over files on sphinx build | |
| 41 | +# https://pypi.python.org/pypi/sphinxcontrib-rawfiles | |
| 42 | +extensions += ['rawfiles'] | |
| 43 | + | |
| 44 | +rawfiles = ['fhelp/ctlike.html'] | |
| 45 | + | |
| 37 | 46 | # Add any paths that contain templates here, relative to this directory. |
| 38 | 47 | templates_path = ['_templates'] |
| 39 | 48 | ... | ... |
doc/source/exts/rawfiles.py
0 → 100644
| 1 | +# -*- coding: utf-8 -*- | |
| 2 | +# Copied from https://bitbucket.org/birkenfeld/sphinx-contrib/ | |
| 3 | +import os | |
| 4 | +import shutil | |
| 5 | + | |
| 6 | +def on_html_collect_pages(app): | |
| 7 | + for f in app.builder.config.rawfiles: | |
| 8 | + src = os.path.join(app.srcdir, f) | |
| 9 | + dst = os.path.join(app.builder.outdir, f) | |
| 10 | + # cleanup | |
| 11 | + if os.path.exists(dst): | |
| 12 | + if os.path.isdir(dst): | |
| 13 | + shutil.rmtree(dst) | |
| 14 | + elif os.path.isfile(dst): | |
| 15 | + os.remove(dst) | |
| 16 | + # copy file | |
| 17 | + if os.path.exists(src): | |
| 18 | + if os.path.isdir(src): | |
| 19 | + shutil.copytree(src, dst) | |
| 20 | + elif os.path.isfile(src): | |
| 21 | + shutil.copy(src, dst) | |
| 22 | + else: | |
| 23 | + msg = ('rawfiles target is not directory or file "%s".' % src) | |
| 24 | + app.builder.warn(msg) | |
| 25 | + else: | |
| 26 | + msg = ('rawfiles can not find "%s".' % src) | |
| 27 | + app.builder.warn(msg) | |
| 28 | + | |
| 29 | + return () | |
| 30 | + | |
| 31 | +def setup(app): | |
| 32 | + app.add_config_value('rawfiles', [], 'html') | |
| 33 | + app.connect("html-collect-pages", on_html_collect_pages) | |
| 0 | 34 | \ No newline at end of file | ... | ... |