8000 add show_code_download conf.py option by LuisBL · Pull Request #1070 · sphinx-gallery/sphinx-gallery · GitHub
[go: up one dir, main page]

Skip to content

add show_code_download conf.py option #1070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
8000 Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ file:
- ``capture_repr`` and ``ignore_repr_types`` (:ref:`capture_repr`)
- ``nested_sections`` (:ref:`nested_sections`)
- ``api_usage_ignore`` (:ref:`api_usage_ignore`)
- ``show_code_download`` (:ref:`show_code_download`)
- ``show_api_usage`` (:ref:`show_api_usage`)

Some options can also be set or overridden on a file-by-file basis:
Expand Down Expand Up @@ -368,6 +369,23 @@ In addition, multiple convenience classes are provided for use with
- :class:`sphinx_gallery.sorting.FileNameSortKey` to sort by file name.
- :class:`sphinx_gallery.sorting.ExampleTitleSortKey` to sort by example title.

.. _show_code_download:

Download Python/Jupyter source code
====================================
To not have the two download buttons::

Download Python source code: <Python_file.py>

Download Jupyter notebook: <Jupyter_file.ipynb>

You can use the configuration key ``show_code_download``::

sphinx_gallery_conf = {
...
'show_code_download' : False,
}


.. _link_to_documentation:

Expand Down
1 change: 1 addition & 0 deletions sphinx_gallery/gen_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __call__(self, gallery_conf, script_vars):


DEFAULT_GALLERY_CONF = {
'show_code_download': True,
'filename_pattern': re.escape(os.sep) + 'plot',
'ignore_pattern': r'__init__\.py',
'examples_dirs': os.path.join('..', 'examples'),
Expand Down
9 changes: 5 additions & 4 deletions sphinx_gallery/gen_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,10 +1246,11 @@ def save_rst_example(example_rst, example_file, time_elapsed,
binder_badge_rst = indent(binder_badge_rst, ' ') # need an extra two

fname = os.path.basename(example_file)
example_rst += CODE_DOWNLOAD.format(fname,
replace_py_ipynb(fname),
binder_badge_rst,
ref_fname)
if gallery_conf['show_code_download']:
example_rst += CODE_DOWNLOAD.format(fname,
replace_py_ipynb(fname),
binder_badge_ 4A57 rst,
ref_fname)
if gallery_conf['show_signature']:
example_rst += SPHX_GLR_SIG

Expand Down
0