(arguments, content, options, state_machine, state, lineno)
| 782 | |
| 783 | |
| 784 | def run(arguments, content, options, state_machine, state, lineno): |
| 785 | document = state_machine.document |
| 786 | env = document.settings.env |
| 787 | config = env.config |
| 788 | nofigs = 'nofigs' in options |
| 789 | |
| 790 | if config.plot_srcset and setup.app.builder.name == 'singlehtml': |
| 791 | raise ExtensionError( |
| 792 | 'plot_srcset option not compatible with single HTML writer') |
| 793 | |
| 794 | formats = get_plot_formats(config) |
| 795 | default_fmt = formats[0][0] |
| 796 | |
| 797 | options.setdefault('include-source', config.plot_include_source) |
| 798 | options.setdefault('show-source-link', config.plot_html_show_source_link) |
| 799 | options.setdefault('filename-prefix', None) |
| 800 | |
| 801 | if 'class' in options: |
| 802 | # classes are parsed into a list of string, and output by simply |
| 803 | # printing the list, abusing the fact that RST guarantees to strip |
| 804 | # non-conforming characters |
| 805 | options['class'] = ['plot-directive'] + options['class'] |
| 806 | else: |
| 807 | options.setdefault('class', ['plot-directive']) |
| 808 | keep_context = 'context' in options |
| 809 | context_opt = None if not keep_context else options['context'] |
| 810 | |
| 811 | rst_file = document.attributes['source'] |
| 812 | rst_dir = os.path.dirname(rst_file) |
| 813 | |
| 814 | if len(arguments): |
| 815 | if not config.plot_basedir: |
| 816 | source_file_name = os.path.join(setup.app.builder.srcdir, |
| 817 | directives.uri(arguments[0])) |
| 818 | else: |
| 819 | source_file_name = os.path.join(setup.confdir, config.plot_basedir, |
| 820 | directives.uri(arguments[0])) |
| 821 | # If there is content, it will be passed as a caption. |
| 822 | caption = '\n'.join(content) |
| 823 | |
| 824 | # Enforce unambiguous use of captions. |
| 825 | if "caption" in options: |
| 826 | if caption: |
| 827 | raise ValueError( |
| 828 | 'Caption specified in both content and options.' |
| 829 | ' Please remove ambiguity.' |
| 830 | ) |
| 831 | # Use caption option |
| 832 | caption = options["caption"] |
| 833 | |
| 834 | # If the optional function name is provided, use it |
| 835 | if len(arguments) == 2: |
| 836 | function_name = arguments[1] |
| 837 | else: |
| 838 | function_name = None |
| 839 | |
| 840 | code = Path(source_file_name).read_text(encoding='utf-8') |
| 841 | if options['filename-prefix']: |
no test coverage detected