|
47 | 47 |
|
48 | 48 | The ``.. plot::`` directive supports the following options: |
49 | 49 |
|
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. |
55 | 55 |
|
56 | 56 | ``:format:`` : {'python', 'doctest'} |
57 | 57 | The format of the input. If unset, the format is auto-detected. |
|
169 | 169 | be customized by changing the *plot_template*. See the source of |
170 | 170 | :doc:`/api/sphinxext_plot_directive_api` for the templates defined in *TEMPLATE* |
171 | 171 | and *TEMPLATE_SRCSET*. |
| 172 | +
|
172 | 173 | """ |
173 | 174 |
|
174 | 175 | from collections import defaultdict |
@@ -273,7 +274,7 @@ class PlotDirective(Directive): |
273 | 274 | 'scale': directives.nonnegative_int, |
274 | 275 | 'align': Image.align, |
275 | 276 | 'class': directives.class_option, |
276 | | - 'image-basename': directives.unchanged, |
| 277 | + 'filename-prefix': directives.unchanged, |
277 | 278 | 'include-source': _option_boolean, |
278 | 279 | 'show-source-link': _option_boolean, |
279 | 280 | 'format': _option_format, |
@@ -640,15 +641,15 @@ def check_output_base_name(env, output_base): |
640 | 641 |
|
641 | 642 | if '.' in output_base or '/' in output_base or '\\' in output_base: |
642 | 643 | raise PlotError( |
643 | | - f"The image-basename '{output_base}' is invalid. " |
| 644 | + f"The filename-prefix '{output_base}' is invalid. " |
644 | 645 | f"It must not contain dots or slashes.") |
645 | 646 |
|
646 | 647 | for d in env.mpl_plot_image_basenames: |
647 | 648 | if output_base in env.mpl_plot_image_basenames[d]: |
648 | 649 | if d == docname: |
649 | 650 | 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" |
652 | 653 | f"times (it is also used in {env.doc2path(d)}).") |
653 | 654 |
|
654 | 655 | env.mpl_plot_image_basenames[docname].add(output_base) |
@@ -789,7 +790,7 @@ def run(arguments, content, options, state_machine, state, lineno): |
789 | 790 |
|
790 | 791 | options.setdefault('include-source', config.plot_include_source) |
791 | 792 | options.setdefault('show-source-link', config.plot_html_show_source_link) |
792 | | - options.setdefault('image-basename', None) |
| 793 | + options.setdefault('filename-prefix', None) |
793 | 794 |
|
794 | 795 | if 'class' in options: |
795 | 796 | # 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): |
831 | 832 | function_name = None |
832 | 833 |
|
833 | 834 | 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'] |
836 | 837 | check_output_base_name(env, output_base) |
837 | 838 | else: |
838 | 839 | output_base = os.path.basename(source_file_name) |
839 | 840 | else: |
840 | 841 | source_file_name = rst_file |
841 | 842 | 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'] |
844 | 845 | check_output_base_name(env, output_base) |
845 | 846 | else: |
846 | 847 | base, ext = os.path.splitext(os.path.basename(source_file_name)) |
|
0 commit comments