|
| 1 | +import os |
| 2 | +from fnmatch import fnmatch |
| 3 | +from sphinx_gallery import binder |
| 4 | + |
| 5 | +# Blacklist contains patterns for which no binder/pyodite links |
| 6 | +# should be created |
| 7 | +blacklist = ["*_sgskip.py", |
| 8 | + "*pipong.py", |
| 9 | + "*pgf*.py", |
| 10 | + "*svg_filter*.py", |
| 11 | + "*font_indexing.py", |
| 12 | + "*ftface_props.py", |
| 13 | + "*multipage_pdf.py", |
| 14 | + "*pick_event_demo2.py"] |
| 15 | + |
| 16 | + |
| 17 | +# Rewrite "download" section |
| 18 | +# {0} is .py link, {1} is ipynb link, |
| 19 | +# {2} is additional rst text (used here for additional links) |
| 20 | +# {3} is ref_fname |
| 21 | +dlcode = """ |
| 22 | +.. _sphx_glr_download_{3}: |
| 23 | +\n.. only :: html |
| 24 | +
|
| 25 | + .. container:: sphx-glr-footer |
| 26 | + :class: sphx-glr-footer-example |
| 27 | +
|
| 28 | + .. container:: sphx-glr-download |
| 29 | + |
| 30 | + :download:`Download Python source code: {0} <{0}>`\n |
| 31 | + .. container:: sphx-glr-download |
| 32 | + |
| 33 | + :download:`Download Jupyter notebook: {1} <{1}>`\n |
| 34 | + {2} |
| 35 | + """ |
| 36 | + |
| 37 | +def gen_pyodite_url(fname): |
| 38 | + base = "https://iodide.io/pyodide-demo/matplotlib-sideload.html?sideload=" |
| 39 | + head, tail = os.path.split(fname) |
| 40 | + return base + "https://matplotlib.org/_downloads/" + tail |
| 41 | + |
| 42 | +def gen_links(fname, binder_conf, gallery_conf): |
| 43 | + """Generate the RST + links for the additional links. |
| 44 | + This is a replaced version of the original gen_binder_rst. |
| 45 | +
|
| 46 | + Parameters |
| 47 | + ---------- |
| 48 | + fname: str |
| 49 | + The path to the `.py` file for which a Binder badge will be generated. |
| 50 | + binder_conf: dict | None |
| 51 | + If a dictionary it must have the following keys: |
| 52 | + 'url': The URL of the BinderHub instance that's running a Binder |
| 53 | + service. |
| 54 | + 'org': The GitHub organization to which the documentation will be |
| 55 | + pushed. |
| 56 | + 'repo': The GitHub repository to which the documentation will be |
| 57 | + pushed. |
| 58 | + 'branch': The Git branch on which the documentation exists (e.g., |
| 59 | + gh-pages). |
| 60 | + 'dependencies': A list of paths to dependency files that match the |
| 61 | + Binderspec. |
| 62 | + Returns |
| 63 | + ------- |
| 64 | + rst : str |
| 65 | + The reStructuredText for the Binder badge and pyodite link. |
| 66 | + """ |
| 67 | + binder_conf = binder.check_binder_conf(binder_conf) |
| 68 | + binder_url = binder.gen_binder_url(fname, binder_conf, gallery_conf) |
| 69 | + pyodite_url = gen_pyodite_url(fname) |
| 70 | + |
| 71 | + for pattern in blacklist: |
| 72 | + if fnmatch(fname, pattern): |
| 73 | + return "\n" |
| 74 | + |
| 75 | + rst_binder = ( |
| 76 | + "\n" |
| 77 | + " .. container:: sphx-glr-download\n\n" |
| 78 | + " `Open with binder (experimental) <{}>`_\n" |
| 79 | + ).format(binder_url) |
| 80 | + rst_pyodite = ( |
| 81 | + "\n" |
| 82 | + " .. container:: sphx-glr-download\n\n" |
| 83 | + " `Open with pyodite (experimental) <{}>`_\n" |
| 84 | + ).format(pyodite_url) |
| 85 | + |
| 86 | + # leave binder out for now , because configuration is unclear |
| 87 | + return rst_pyodite # + rst_binder |
| 88 | + |
0 commit comments