Description
Bug report
Bug summary
According to the documentation when plot_basedir is empty or None. The source-code files are found relative to the document that contains them:
plot_basedir
Base directory, to which plot:: file names are relative to. (If None or empty, file names are relative to the directory where the file containing the directive is.)
but this is not true in the source code and filenames are found relative to conf.py
instead:
matplotlib/lib/matplotlib/sphinxext/plot_directive.py
Lines 684 to 693 in 44a9036
On line 689, I believe rst_dir
must be used instead of setup.app.builder.srcdir
(which points to the folder of conf.py
).
Code for reproduction
The minimal example to reproduce this is here:
minimal.zip
Here is how the folder structure looks like:
minimal
└── source
├── conf.py
├── index.rst
├── plots
│ ├── plot.py
│ └── plot.rst
where the conf.py
contains (besides what is in template):
extensions = ['matplotlib.sphinxext.plot_directive']
and plot.rst
contains:
.. plot:: plot.py
and index.rst
contains:
.. toctree::
:maxdepth: 2
:caption: Contents:
plots/plot.rst
Running make html
on this minimal example fails with:
Running Sphinx v1.6.6
making output directory...
loading pickled environment... not yet created
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 2 source files that are out of date
updating environment: 2 added, 0 changed, 0 removed
/tmp/minimal/source/index.rst:9: WARNING: Error in "toctree" directive:
invalid option block.
.. toctree::
:maxdepth: 2
:caption: Contents:
plots/plot.rst
Exception occurred:
File "/usr/lib/python3.6/site-packages/matplotlib/sphinxext/plot_directive.py", line 708, in run
with io.open(source_file_name, 'r', encoding='utf-8') as fd:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/minimal/source/plot.py'
The full traceback has been saved in /tmp/sphinx-err-36njex0o.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
Expected outcome
I expect the resolved paths to the Python file to be relative to the .rst file per documentation.
('/tmp/minimal/source/plots/plot.py'
in the example above).
Matplotlib version
- Operating system: Arch Linux
- Matplotlib version: 2.1.2
- Matplotlib backend (
print(matplotlib.get_backend())
): Qt5Agg - Python version: 3.6
- Other libraries: Sphinx v1.6.6