Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

The sphinx plot directive does not find files relative to the document that contains them. #10350

Copy link
Copy link
Open
@183amir

Description

@183amir
Issue body actions

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:

rst_file = document.attributes['source']
rst_dir = os.path.dirname(rst_file)
if len(arguments):
if not config.plot_basedir:
source_file_name = os.path.join(setup.app.builder.srcdir,
directives.uri(arguments[0]))
else:
source_file_name = os.path.join(setup.confdir, config.plot_basedir,
directives.uri(arguments[0]))

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    keepItems to be ignored by the “Stale” Github ActionItems to be ignored by the “Stale” Github Actionstatus: inactiveMarked by the “Stale” Github ActionMarked by the “Stale” Github Actiontopic: sphinx extension

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.