|
100 | 100 | import numpy as np
|
101 | 101 | from matplotlib import pyplot as plt
|
102 | 102 |
|
| 103 | + plot_dir_resolve_method |
| 104 | + The method to use for resolving file names that come after the |
| 105 | + ``plot::`` directive. Two options are available: ``relative`` and |
| 106 | + ``absolute``. Defaults to ``absolute`` but the default value will |
| 107 | + change to ``relative`` in future versions. The ``absolute`` method |
| 108 | + is deprecated and might be removed in future. See the ``plot_basedir`` |
| 109 | + for explanation of methods. |
| 110 | +
|
103 | 111 | plot_basedir
|
104 |
| - Base directory, to which ``plot::`` file names are relative |
105 |
| - to. Defaults to the source directory. Only absolute paths are treated |
106 |
| - relative to this option. Relative paths are found relative to the |
107 |
| - directory of the file containing the directive. |
| 112 | + Base directory, to which ``plot::`` file names are relative. |
| 113 | + Defaults to the source directory. |
| 114 | +
|
| 115 | + If ``plot_dir_resolve_method`` is ``relative``, relative file names are |
| 116 | + found relative to the directory of the file containing the directive. |
| 117 | + Absolute file names (paths starting with ``/``) are found relative to |
| 118 | + ``plot_basedir``. |
| 119 | +
|
| 120 | + If ``plot_dir_resolve_method`` is ``absolute``, all files are found |
| 121 | + relative to ``plot_basedir`` whether the paths start with ``/`` or not. |
| 122 | + This method is deprecated and may be removed in future. |
108 | 123 |
|
109 | 124 | plot_formats
|
110 | 125 | File formats to generate. List of tuples or strings::
|
@@ -652,13 +667,36 @@ def run(arguments, content, options, state_machine, state, lineno):
|
652 | 667 |
|
653 | 668 | if len(arguments):
|
654 | 669 |
|
655 |
| - if arguments[0].startswith('/'): |
656 |
| - arguments[0] = arguments[0][1:] |
657 |
| - src_dir = config.plot_basedir or setup.app.builder.srcdir |
| 670 | + # if the new method is selected for resolving paths |
| 671 | + if config.plot_dir_resolve_method.lower() == 'relative': |
| 672 | + |
| 673 | + if arguments[0].startswith('/'): |
| 674 | + arguments[0] = arguments[0][1:] |
| 675 | + src_dir = config.plot_basedir or setup.app.builder.srcdir |
| 676 | + else: |
| 677 | + src_dir = rst_dir |
| 678 | + |
| 679 | + source_file_name = os.path.join(src_dir, directives.uri(arguments[0])) |
| 680 | + |
658 | 681 | else:
|
659 |
| - src_dir = rst_dir |
660 | 682 |
|
661 |
| - source_file_name = os.path.join(src_dir, directives.uri(arguments[0])) |
| 683 | + cbook.warn_deprecated( |
| 684 | + '3.2', message='You are using an old method ' |
| 685 | + 'to resolve filenames of the ``.. ::plot`` directive. Please ' |
| 686 | + 'switch to the new method by specifying ' |
| 687 | + '``plot_dir_resolve_method=\'relative\'`` in your conf.py ' |
| 688 | + 'and fix the filenames accordingly. Please see ' |
| 689 | + 'matplotlib/doc/api/next_api_changes/2018-10-09-plot-directive.rst ' |
| 690 | + 'for more information. The old method will be removed in ' |
| 691 | + '%(removal)s.', removal='4.0') |
| 692 | + |
| 693 | + if not config.plot_basedir: |
| 694 | + source_file_name = os.path.join( |
| 695 | + setup.app.builder.srcdir, directives.uri(arguments[0])) |
| 696 | + |
| 697 | + else: |
| 698 | + source_file_name = os.path.join( |
| 699 | + setup.confdir, config.plot_basedir, directives.uri(arguments[0])) |
662 | 700 |
|
663 | 701 | # If there is content, it will be passed as a caption.
|
664 | 702 | caption = '\n'.join(content)
|
|
0 commit comments