sphinx-examples-as-code 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/.github/workflows/ci.yml +1 -1
- sphinx_examples_as_code-0.3.0/LICENSE +21 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/PKG-INFO +42 -49
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/README.md +39 -48
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/pyproject.toml +2 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/sphinx_examples_as_code/__init__.py +131 -49
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/sphinx_examples_as_code/_version.py +3 -3
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/sphinx_examples_as_code.egg-info/PKG-INFO +42 -49
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/sphinx_examples_as_code.egg-info/SOURCES.txt +10 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/sphinx_examples_as_code.egg-info/scm_file_list.json +20 -10
- sphinx_examples_as_code-0.3.0/sphinx_examples_as_code.egg-info/scm_version.json +8 -0
- sphinx_examples_as_code-0.3.0/tests/heading_level_fixture/conf.py +23 -0
- sphinx_examples_as_code-0.3.0/tests/heading_level_fixture/examples/GALLERY_HEADER.rst +2 -0
- sphinx_examples_as_code-0.3.0/tests/heading_level_fixture/examples/plot_reused_level.py +19 -0
- sphinx_examples_as_code-0.3.0/tests/heading_level_fixture/index.rst +7 -0
- sphinx_examples_as_code-0.3.0/tests/single_function_fixture/conf.py +84 -0
- sphinx_examples_as_code-0.3.0/tests/single_function_fixture/index.rst +4 -0
- sphinx_examples_as_code-0.3.0/tests/single_function_fixture/mymodule.py +13 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/tests/test_gallery_downloads.py +16 -7
- sphinx_examples_as_code-0.3.0/tests/test_heading_level_reuse.py +41 -0
- sphinx_examples_as_code-0.3.0/tests/test_single_function_page.py +40 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/tests/test_sphinx_examples_as_code.py +343 -62
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/tests/test_tinypages.py +28 -21
- sphinx_examples_as_code-0.2.0/sphinx_examples_as_code.egg-info/scm_version.json +0 -8
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/.github/dependabot.yml +0 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/.github/release.yml +0 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/.gitignore +0 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/.pre-commit-config.yaml +0 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/setup.cfg +0 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/sphinx_examples_as_code.egg-info/dependency_links.txt +0 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/sphinx_examples_as_code.egg-info/requires.txt +0 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/sphinx_examples_as_code.egg-info/top_level.txt +0 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/tests/gallery_fixture/conf.py +0 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/tests/gallery_fixture/examples/GALLERY_HEADER.rst +0 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/tests/gallery_fixture/examples/plot_minimal.py +0 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/tests/gallery_fixture/index.rst +0 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/tests/tinypages/conf.py +0 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/tests/tinypages/docstring_cases.py +0 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/tests/tinypages/docstring_cases.rst +0 -0
- {sphinx_examples_as_code-0.2.0 → sphinx_examples_as_code-0.3.0}/tests/tinypages/index.rst +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The PyVista Developers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to
|
|
7
|
+
deal in the Software without restriction, including without limitation the
|
|
8
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
9
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
21
|
+
IN THE SOFTWARE.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sphinx-examples-as-code
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Sphinx extension for converting docstring examples into downloadable code.
|
|
5
5
|
Author-email: The PyVista Developers <info@pyvista.org>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -21,7 +21,9 @@ Classifier: Programming Language :: Python :: 3.14
|
|
|
21
21
|
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
22
22
|
Requires-Python: >=3.10
|
|
23
23
|
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
24
25
|
Requires-Dist: pyvista>=0.48
|
|
26
|
+
Dynamic: license-file
|
|
25
27
|
|
|
26
28
|
# sphinx-examples-as-code
|
|
27
29
|
|
|
@@ -55,12 +57,15 @@ the keys you want to change from their default:
|
|
|
55
57
|
sphinx_examples_as_code_conf = {
|
|
56
58
|
'link_position': 'top',
|
|
57
59
|
'formats': ['py', 'ipynb'],
|
|
58
|
-
'base_url': None,
|
|
59
60
|
'gallery_downloads': False,
|
|
60
61
|
'footer': (
|
|
61
62
|
'Generated by `sphinx-examples-as-code '
|
|
62
63
|
'<https://github.com/pyvista/sphinx-examples-as-code>`_'
|
|
63
64
|
),
|
|
65
|
+
'link_labels': {
|
|
66
|
+
'py': 'Download Python source code',
|
|
67
|
+
'ipynb': 'Download Jupyter notebook',
|
|
68
|
+
},
|
|
64
69
|
}
|
|
65
70
|
```
|
|
66
71
|
|
|
@@ -68,29 +73,26 @@ sphinx_examples_as_code_conf = {
|
|
|
68
73
|
(default) or `'bottom'`.
|
|
69
74
|
- `formats`: which downloads to generate. A list containing `'py'`, `'ipynb'`, or both
|
|
70
75
|
(default). Always offered in that order regardless of how the list is written.
|
|
71
|
-
- `
|
|
72
|
-
to
|
|
73
|
-
actually use. `None` (default) means no links are generated anywhere. A missing
|
|
74
|
-
trailing slash is added automatically; a value with no scheme or host raises a
|
|
75
|
-
configuration error at build start.
|
|
76
|
+
- `link_labels`: the text of the download link(s) themselves, per format. Set only the
|
|
77
|
+
format(s) you want to change; any left unset keep reading their own default shown above.
|
|
76
78
|
- `gallery_downloads`: opt-in takeover of
|
|
77
79
|
[sphinx-gallery](https://sphinx-gallery.github.io)'s own per-example downloads.
|
|
78
80
|
`False` (default) leaves sphinx-gallery pages untouched. See
|
|
79
81
|
[Sphinx-Gallery integration](#sphinx-gallery-integration) below.
|
|
80
82
|
- `footer`: a string appended to the end of every generated file. Defaults to a one-line
|
|
81
83
|
"generated file" credit linking back to this project; set to `None` to omit it
|
|
82
|
-
entirely. Preceded by a blank line and a `-`-only divider line,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
84
|
+
entirely. Preceded by a blank line and a `-`-only divider line, which also renders as a
|
|
85
|
+
real horizontal rule in `.ipynb`; the footer always gets its own dedicated cell there.
|
|
86
|
+
Parsed as RST: a hyperlink written as `` `text <url>`_ `` becomes a real clickable
|
|
87
|
+
Markdown link in `.ipynb`, and renders inline as `text url` in `.py`. Plain text with no
|
|
88
|
+
markup at all becomes one comment line per line of text, and blank-line-separated
|
|
89
|
+
paragraphs stay separated.
|
|
90
|
+
|
|
91
|
+
An unrecognized key raises a configuration error at build start.
|
|
92
|
+
|
|
93
|
+
Cross-references and hyperlinks resolve into absolute links using Sphinx's own
|
|
94
|
+
[`html_baseurl`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_baseurl).
|
|
95
|
+
Leave it unset and no links are generated anywhere.
|
|
94
96
|
|
|
95
97
|
Overriding a single key from the command line works via a dotted `-D` flag, e.g.
|
|
96
98
|
`-D sphinx_examples_as_code_conf.link_position=bottom` -- this only touches that one
|
|
@@ -103,16 +105,14 @@ What happens to the content of an Examples section:
|
|
|
103
105
|
- Doctest blocks (`>>> ...` / `... ...`) keep their input lines, prompts stripped, as
|
|
104
106
|
real Python source. Doctest *output* lines are dropped — only the input code matters.
|
|
105
107
|
- `.. code-block:: python` (or `py`) blocks are kept as-is; other languages become
|
|
106
|
-
comments, set off with blank lines on both sides like any other directive
|
|
107
|
-
preformatted block (e.g. an RST `::`-block illustrating a data format) still reads as
|
|
108
|
-
a distinct block rather than melting into the surrounding prose.
|
|
108
|
+
comments, set off with blank lines on both sides like any other directive.
|
|
109
109
|
- Admonitions (`.. note::`, `.. warning::`, `.. seealso::`, ...) become a `# LABEL:`
|
|
110
110
|
comment followed by their content as comments. "See Also" is recognized in any of its
|
|
111
111
|
three forms (`.. seealso::`, a bare `.. rubric:: See Also`, or a hand-written `See
|
|
112
112
|
Also` heading) and always renders the same way.
|
|
113
113
|
- Cross-references and inline code (`:class:`, `:meth:`, `:func:`, `:attr:`,
|
|
114
114
|
double-backtick literals, ...) keep their display text, wrapped in backticks (e.g.
|
|
115
|
-
``:class:`pyvista.Plotter` `` -> `` `pyvista.Plotter` ``). If `
|
|
115
|
+
``:class:`pyvista.Plotter` `` -> `` `pyvista.Plotter` ``). If `html_baseurl` is set and
|
|
116
116
|
the reference resolves: `.ipynb` turns it into a clickable link everywhere; `.py` only
|
|
117
117
|
writes the link inside a "See Also" part (as `name url` on its own line) — everywhere
|
|
118
118
|
else in `.py` the link is simply omitted.
|
|
@@ -121,15 +121,13 @@ What happens to the content of an Examples section:
|
|
|
121
121
|
- Everything else text-bearing (prose, captions, other non-Python code) becomes a plain
|
|
122
122
|
`#` comment.
|
|
123
123
|
- Figures/images, raw HTML, sphinx-design dropdowns/tab-sets, and sphinx-tags' `.. tags::`
|
|
124
|
-
line are dropped entirely
|
|
125
|
-
standalone file has any use for.
|
|
124
|
+
line are dropped entirely.
|
|
126
125
|
|
|
127
126
|
Generated `.py` files start with a `# Examples from <qualified name>` title header
|
|
128
|
-
(gallery mode uses the page's own title instead -- see below)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
blank
|
|
132
|
-
sides.
|
|
127
|
+
(gallery mode uses the page's own title instead -- see below), with a few whitespace
|
|
128
|
+
conventions: prose directly above a code block stays attached to it, a code block is
|
|
129
|
+
always followed by a blank line, and a directive (header, `# NOTE:`-style block) gets
|
|
130
|
+
blank lines on both sides.
|
|
133
131
|
|
|
134
132
|
Generated `.ipynb` notebooks use the same content, split into alternating code/markdown
|
|
135
133
|
cells instead.
|
|
@@ -146,35 +144,30 @@ full example code" note and the `.py`/`.ipynb`/`.zip` download footer are remove
|
|
|
146
144
|
the page, replaced with download link(s) built by this extension instead — same
|
|
147
145
|
conversion rules as above, applied to the whole page rather than one Examples section.
|
|
148
146
|
The generated file's header uses the page's own title (e.g. `# Create Circular Arcs`)
|
|
149
|
-
rather than the generic `# Examples from <docname
|
|
150
|
-
page, not an Examples section carved out of a larger docstring, so there's no "from"
|
|
151
|
-
framing to make.
|
|
147
|
+
rather than the generic `# Examples from <docname>`.
|
|
152
148
|
|
|
153
149
|
The "Total running time" line and the "Gallery generated by Sphinx-Gallery" credit line
|
|
154
150
|
stay on the rendered page untouched, but never make it into the generated download
|
|
155
|
-
itself
|
|
156
|
-
yourself would read like it's timing *your* run, not the build's, and a "Generated by
|
|
157
|
-
Sphinx-Gallery" credit is simply wrong inside a file this extension generated.
|
|
151
|
+
itself.
|
|
158
152
|
|
|
159
153
|
Detection is automatic and per-page — any page without a sphinx-gallery download footer
|
|
160
|
-
is left completely untouched
|
|
161
|
-
|
|
162
|
-
above.
|
|
154
|
+
is left completely untouched. Gallery pages and ordinary docstring/prose pages (using
|
|
155
|
+
the Examples-section behavior above) can coexist on the same site.
|
|
163
156
|
|
|
164
157
|
A `# %%` cell with its own RST heading gets the same title-plus-underline treatment as
|
|
165
|
-
the file's own header,
|
|
166
|
-
|
|
158
|
+
the file's own header, and renders as a real Markdown heading in `.ipynb` (`<h1>` for the
|
|
159
|
+
file's own header, `# Title` + `# ====`; `<h2>` for a cell heading, `# Title` + `# ----`).
|
|
160
|
+
A cell heading nested under the page's own title (the common case) is level 2; one that
|
|
161
|
+
reuses the page title's own underline character -- a real RST heading, one level up --
|
|
162
|
+
is level 1, matching the file's own header.
|
|
167
163
|
|
|
168
164
|
Two things worth knowing before turning this on:
|
|
169
165
|
|
|
170
|
-
- It's built against sphinx-gallery's own
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
`_downloads/` before this extension gets a chance to remove the links pointing to
|
|
176
|
-
them, so those files still end up in the build output even though nothing on the page
|
|
177
|
-
links to them anymore.
|
|
166
|
+
- It's built against sphinx-gallery's own RST/HTML output (the same `sphx-glr-*` CSS
|
|
167
|
+
classes its own theming depends on), not a documented extension API. A future
|
|
168
|
+
sphinx-gallery release could shift that structure without warning.
|
|
169
|
+
- sphinx-gallery's own `.py`/`.ipynb`/`.zip` downloads still end up copied into
|
|
170
|
+
`_downloads/`, even though nothing on the page links to them anymore.
|
|
178
171
|
|
|
179
172
|
## Development
|
|
180
173
|
|
|
@@ -30,12 +30,15 @@ the keys you want to change from their default:
|
|
|
30
30
|
sphinx_examples_as_code_conf = {
|
|
31
31
|
'link_position': 'top',
|
|
32
32
|
'formats': ['py', 'ipynb'],
|
|
33
|
-
'base_url': None,
|
|
34
33
|
'gallery_downloads': False,
|
|
35
34
|
'footer': (
|
|
36
35
|
'Generated by `sphinx-examples-as-code '
|
|
37
36
|
'<https://github.com/pyvista/sphinx-examples-as-code>`_'
|
|
38
37
|
),
|
|
38
|
+
'link_labels': {
|
|
39
|
+
'py': 'Download Python source code',
|
|
40
|
+
'ipynb': 'Download Jupyter notebook',
|
|
41
|
+
},
|
|
39
42
|
}
|
|
40
43
|
```
|
|
41
44
|
|
|
@@ -43,29 +46,26 @@ sphinx_examples_as_code_conf = {
|
|
|
43
46
|
(default) or `'bottom'`.
|
|
44
47
|
- `formats`: which downloads to generate. A list containing `'py'`, `'ipynb'`, or both
|
|
45
48
|
(default). Always offered in that order regardless of how the list is written.
|
|
46
|
-
- `
|
|
47
|
-
to
|
|
48
|
-
actually use. `None` (default) means no links are generated anywhere. A missing
|
|
49
|
-
trailing slash is added automatically; a value with no scheme or host raises a
|
|
50
|
-
configuration error at build start.
|
|
49
|
+
- `link_labels`: the text of the download link(s) themselves, per format. Set only the
|
|
50
|
+
format(s) you want to change; any left unset keep reading their own default shown above.
|
|
51
51
|
- `gallery_downloads`: opt-in takeover of
|
|
52
52
|
[sphinx-gallery](https://sphinx-gallery.github.io)'s own per-example downloads.
|
|
53
53
|
`False` (default) leaves sphinx-gallery pages untouched. See
|
|
54
54
|
[Sphinx-Gallery integration](#sphinx-gallery-integration) below.
|
|
55
55
|
- `footer`: a string appended to the end of every generated file. Defaults to a one-line
|
|
56
56
|
"generated file" credit linking back to this project; set to `None` to omit it
|
|
57
|
-
entirely. Preceded by a blank line and a `-`-only divider line,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
57
|
+
entirely. Preceded by a blank line and a `-`-only divider line, which also renders as a
|
|
58
|
+
real horizontal rule in `.ipynb`; the footer always gets its own dedicated cell there.
|
|
59
|
+
Parsed as RST: a hyperlink written as `` `text <url>`_ `` becomes a real clickable
|
|
60
|
+
Markdown link in `.ipynb`, and renders inline as `text url` in `.py`. Plain text with no
|
|
61
|
+
markup at all becomes one comment line per line of text, and blank-line-separated
|
|
62
|
+
paragraphs stay separated.
|
|
63
|
+
|
|
64
|
+
An unrecognized key raises a configuration error at build start.
|
|
65
|
+
|
|
66
|
+
Cross-references and hyperlinks resolve into absolute links using Sphinx's own
|
|
67
|
+
[`html_baseurl`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_baseurl).
|
|
68
|
+
Leave it unset and no links are generated anywhere.
|
|
69
69
|
|
|
70
70
|
Overriding a single key from the command line works via a dotted `-D` flag, e.g.
|
|
71
71
|
`-D sphinx_examples_as_code_conf.link_position=bottom` -- this only touches that one
|
|
@@ -78,16 +78,14 @@ What happens to the content of an Examples section:
|
|
|
78
78
|
- Doctest blocks (`>>> ...` / `... ...`) keep their input lines, prompts stripped, as
|
|
79
79
|
real Python source. Doctest *output* lines are dropped — only the input code matters.
|
|
80
80
|
- `.. code-block:: python` (or `py`) blocks are kept as-is; other languages become
|
|
81
|
-
comments, set off with blank lines on both sides like any other directive
|
|
82
|
-
preformatted block (e.g. an RST `::`-block illustrating a data format) still reads as
|
|
83
|
-
a distinct block rather than melting into the surrounding prose.
|
|
81
|
+
comments, set off with blank lines on both sides like any other directive.
|
|
84
82
|
- Admonitions (`.. note::`, `.. warning::`, `.. seealso::`, ...) become a `# LABEL:`
|
|
85
83
|
comment followed by their content as comments. "See Also" is recognized in any of its
|
|
86
84
|
three forms (`.. seealso::`, a bare `.. rubric:: See Also`, or a hand-written `See
|
|
87
85
|
Also` heading) and always renders the same way.
|
|
88
86
|
- Cross-references and inline code (`:class:`, `:meth:`, `:func:`, `:attr:`,
|
|
89
87
|
double-backtick literals, ...) keep their display text, wrapped in backticks (e.g.
|
|
90
|
-
``:class:`pyvista.Plotter` `` -> `` `pyvista.Plotter` ``). If `
|
|
88
|
+
``:class:`pyvista.Plotter` `` -> `` `pyvista.Plotter` ``). If `html_baseurl` is set and
|
|
91
89
|
the reference resolves: `.ipynb` turns it into a clickable link everywhere; `.py` only
|
|
92
90
|
writes the link inside a "See Also" part (as `name url` on its own line) — everywhere
|
|
93
91
|
else in `.py` the link is simply omitted.
|
|
@@ -96,15 +94,13 @@ What happens to the content of an Examples section:
|
|
|
96
94
|
- Everything else text-bearing (prose, captions, other non-Python code) becomes a plain
|
|
97
95
|
`#` comment.
|
|
98
96
|
- Figures/images, raw HTML, sphinx-design dropdowns/tab-sets, and sphinx-tags' `.. tags::`
|
|
99
|
-
line are dropped entirely
|
|
100
|
-
standalone file has any use for.
|
|
97
|
+
line are dropped entirely.
|
|
101
98
|
|
|
102
99
|
Generated `.py` files start with a `# Examples from <qualified name>` title header
|
|
103
|
-
(gallery mode uses the page's own title instead -- see below)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
blank
|
|
107
|
-
sides.
|
|
100
|
+
(gallery mode uses the page's own title instead -- see below), with a few whitespace
|
|
101
|
+
conventions: prose directly above a code block stays attached to it, a code block is
|
|
102
|
+
always followed by a blank line, and a directive (header, `# NOTE:`-style block) gets
|
|
103
|
+
blank lines on both sides.
|
|
108
104
|
|
|
109
105
|
Generated `.ipynb` notebooks use the same content, split into alternating code/markdown
|
|
110
106
|
cells instead.
|
|
@@ -121,35 +117,30 @@ full example code" note and the `.py`/`.ipynb`/`.zip` download footer are remove
|
|
|
121
117
|
the page, replaced with download link(s) built by this extension instead — same
|
|
122
118
|
conversion rules as above, applied to the whole page rather than one Examples section.
|
|
123
119
|
The generated file's header uses the page's own title (e.g. `# Create Circular Arcs`)
|
|
124
|
-
rather than the generic `# Examples from <docname
|
|
125
|
-
page, not an Examples section carved out of a larger docstring, so there's no "from"
|
|
126
|
-
framing to make.
|
|
120
|
+
rather than the generic `# Examples from <docname>`.
|
|
127
121
|
|
|
128
122
|
The "Total running time" line and the "Gallery generated by Sphinx-Gallery" credit line
|
|
129
123
|
stay on the rendered page untouched, but never make it into the generated download
|
|
130
|
-
itself
|
|
131
|
-
yourself would read like it's timing *your* run, not the build's, and a "Generated by
|
|
132
|
-
Sphinx-Gallery" credit is simply wrong inside a file this extension generated.
|
|
124
|
+
itself.
|
|
133
125
|
|
|
134
126
|
Detection is automatic and per-page — any page without a sphinx-gallery download footer
|
|
135
|
-
is left completely untouched
|
|
136
|
-
|
|
137
|
-
above.
|
|
127
|
+
is left completely untouched. Gallery pages and ordinary docstring/prose pages (using
|
|
128
|
+
the Examples-section behavior above) can coexist on the same site.
|
|
138
129
|
|
|
139
130
|
A `# %%` cell with its own RST heading gets the same title-plus-underline treatment as
|
|
140
|
-
the file's own header,
|
|
141
|
-
|
|
131
|
+
the file's own header, and renders as a real Markdown heading in `.ipynb` (`<h1>` for the
|
|
132
|
+
file's own header, `# Title` + `# ====`; `<h2>` for a cell heading, `# Title` + `# ----`).
|
|
133
|
+
A cell heading nested under the page's own title (the common case) is level 2; one that
|
|
134
|
+
reuses the page title's own underline character -- a real RST heading, one level up --
|
|
135
|
+
is level 1, matching the file's own header.
|
|
142
136
|
|
|
143
137
|
Two things worth knowing before turning this on:
|
|
144
138
|
|
|
145
|
-
- It's built against sphinx-gallery's own
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
`_downloads/` before this extension gets a chance to remove the links pointing to
|
|
151
|
-
them, so those files still end up in the build output even though nothing on the page
|
|
152
|
-
links to them anymore.
|
|
139
|
+
- It's built against sphinx-gallery's own RST/HTML output (the same `sphx-glr-*` CSS
|
|
140
|
+
classes its own theming depends on), not a documented extension API. A future
|
|
141
|
+
sphinx-gallery release could shift that structure without warning.
|
|
142
|
+
- sphinx-gallery's own `.py`/`.ipynb`/`.zip` downloads still end up copied into
|
|
143
|
+
`_downloads/`, even though nothing on the page links to them anymore.
|
|
153
144
|
|
|
154
145
|
## Development
|
|
155
146
|
|
|
@@ -96,6 +96,7 @@ ignore = ['D203', 'D211', 'D213']
|
|
|
96
96
|
# sphinx-gallery example scripts: the module docstring is an RST page title
|
|
97
97
|
# (title line + underline), not prose -- pydocstyle's summary-line rules don't apply.
|
|
98
98
|
'tests/gallery_fixture/examples/*' = ['D205', 'D400', 'D415', 'T201']
|
|
99
|
+
'tests/heading_level_fixture/examples/*' = ['D205', 'D400', 'D415', 'T201']
|
|
99
100
|
|
|
100
101
|
[tool.ruff.lint.isort]
|
|
101
102
|
combine-as-imports = true
|
|
@@ -104,6 +105,7 @@ force-sort-within-sections = true
|
|
|
104
105
|
required-imports = ['from __future__ import annotations']
|
|
105
106
|
|
|
106
107
|
[tool.setuptools]
|
|
108
|
+
license-files = ['LICENSE']
|
|
107
109
|
packages = ['sphinx_examples_as_code']
|
|
108
110
|
|
|
109
111
|
[tool.setuptools_scm]
|