Skip to content

Commit c8eba90

Browse files
committed
Rename image-basename to filename-prefix
1 parent bab3aaf commit c8eba90

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
4848
The ``.. plot::`` directive supports the following options:
4949
50-
``:image-basename:`` : str
51-
The base name (without the extension) of the outputted image files. The
52-
default is to use the same name as the input script, or the name of
53-
the RST document if no script is provided. The image-basename for each
54-
plot directive must be unique.
50+
``:filename-prefix:`` : str
51+
The base name (without the extension) of the outputted image and script
52+
files. The default is to use the same name as the input script, or the
53+
name of the RST document if no script is provided. The filename-prefix for
54+
each plot directive must be unique.
5555
5656
``:format:`` : {'python', 'doctest'}
5757
The format of the input. If unset, the format is auto-detected.
@@ -169,6 +169,7 @@
169169
be customized by changing the *plot_template*. See the source of
170170
:doc:`/api/sphinxext_plot_directive_api` for the templates defined in *TEMPLATE*
171171
and *TEMPLATE_SRCSET*.
172+
172173
"""
173174

174175
from collections import defaultdict
@@ -273,7 +274,7 @@ class PlotDirective(Directive):
273274
'scale': directives.nonnegative_int,
274275
'align': Image.align,
275276
'class': directives.class_option,
276-
'image-basename': directives.unchanged,
277+
'filename-prefix': directives.unchanged,
277278
'include-source': _option_boolean,
278279
'show-source-link': _option_boolean,
279280
'format': _option_format,
@@ -640,15 +641,15 @@ def check_output_base_name(env, output_base):
640641

641642
if '.' in output_base or '/' in output_base or '\\' in output_base:
642643
raise PlotError(
643-
f"The image-basename '{output_base}' is invalid. "
644+
f"The filename-prefix '{output_base}' is invalid. "
644645
f"It must not contain dots or slashes.")
645646

646647
for d in env.mpl_plot_image_basenames:
647648
if output_base in env.mpl_plot_image_basenames[d]:
648649
if d == docname:
649650
raise PlotError(
650-
f"The image-basename {output_base!r} is used multiple times.")
651-
raise PlotError(f"The image-basename {output_base!r} is used multiple"
651+
f"The filename-prefix {output_base!r} is used multiple times.")
652+
raise PlotError(f"The filename-prefix {output_base!r} is used multiple"
652653
f"times (it is also used in {env.doc2path(d)}).")
653654

654655
env.mpl_plot_image_basenames[docname].add(output_base)
@@ -789,7 +790,7 @@ def run(arguments, content, options, state_machine, state, lineno):
789790

790791
options.setdefault('include-source', config.plot_include_source)
791792
options.setdefault('show-source-link', config.plot_html_show_source_link)
792-
options.setdefault('image-basename', None)
793+
options.setdefault('filename-prefix', None)
793794

794795
if 'class' in options:
795796
# classes are parsed into a list of string, and output by simply
@@ -831,16 +832,16 @@ def run(arguments, content, options, state_machine, state, lineno):
831832
function_name = None
832833

833834
code = Path(source_file_name).read_text(encoding='utf-8')
834-
if options['image-basename']:
835-
output_base = options['image-basename']
835+
if options['filename-prefix']:
836+
output_base = options['filename-prefix']
836837
check_output_base_name(env, output_base)
837838
else:
838839
output_base = os.path.basename(source_file_name)
839840
else:
840841
source_file_name = rst_file
841842
code = textwrap.dedent("\n".join(map(str, content)))
842-
if options['image-basename']:
843-
output_base = options['image-basename']
843+
if options['filename-prefix']:
844+
output_base = options['filename-prefix']
844845
check_output_base_name(env, output_base)
845846
else:
846847
base, ext = os.path.splitext(os.path.basename(source_file_name))

lib/matplotlib/tests/data/tinypages/some_plots.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,18 @@ Plot 22 uses a different specific function in a file with plot commands:
180180

181181
.. plot:: range6.py range10
182182

183-
Plots 23--25 use image-basename.
183+
Plots 23--25 use filename-prefix.
184184

185185
.. plot::
186-
:image-basename: custom-basename-6
186+
:filename-prefix: custom-basename-6
187187

188188
plt.plot(range(6))
189189

190190
.. plot:: range4.py
191-
:image-basename: custom-basename-4
191+
:filename-prefix: custom-basename-4
192192

193193
.. plot::
194-
:image-basename: custom-basename-4-6
194+
:filename-prefix: custom-basename-4-6
195195

196196
plt.figure()
197197
plt.plot(range(4))

lib/matplotlib/tests/test_sphinxext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def test_plot_html_show_source_link_custom_basename(tmp_path):
190190
doctree_dir = tmp_path / 'doctrees'
191191
(tmp_path / 'index.rst').write_text("""
192192
.. plot::
193-
:image-basename: custom-name
193+
:filename-prefix: custom-name
194194
195195
plt.plot(range(2))
196196
""")

0 commit comments

Comments
 (0)