Skip to content

Put savefig images back in source directory - #10186

Merged
takluyver merged 1 commit into
ipython:masterfrom
takluyver:sphinx-savefig-alt
Jan 20, 2017
Merged

takluyver merged 1 commit into
ipython:masterfrom
takluyver:sphinx-savefig-alt

Conversation

@takluyver

Copy link
Copy Markdown
Member

Simplifying the logic a bit.

I think there was an issue with the way we were finding the source directory: when it included a docstring from code, the source directory was that of the code. This always uses the main source directory of the docs.

Closes gh-8733

Simplifying the logic a bit.

I think there was an issue with the way we were finding the source
directory: when it included a docstring from code, the source directory
was that of the code. This always uses the main source directory of the
docs.

Closes ipythongh-8733
outfile = os.path.relpath(os.path.join(savefig_dir,filename),
source_dir)
# insert relative path to image file in source (as absolute path for Sphinx)
outfile = '/' + os.path.relpath(os.path.join(savefig_dir,filename),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ or os.path.sep ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe / is right, because it's effectively a URL rather than a platform path. We write all the paths in rst files with forward slashes. I suspect this means it shouldn't be doing os.path.join() either, but I didn't want to change more than I needed to at the moment.

@Carreau

Carreau commented Jan 20, 2017

Copy link
Copy Markdown
Member

+1

@minrk

minrk commented Jan 20, 2017

Copy link
Copy Markdown
Member

I think this should work.

@fmaussion

Copy link
Copy Markdown

Yes, this solved our problem on read the docs. Thanks!

@takluyver
takluyver merged commit 6ee1694 into ipython:master Jan 20, 2017
@takluyver
takluyver deleted the sphinx-savefig-alt branch January 20, 2017 12:54
@Carreau

Carreau commented Jan 27, 2017

Copy link
Copy Markdown
Member

@meeseeksdev backport to 5.x

lumberbot-app Bot pushed a commit that referenced this pull request Jan 27, 2017
Simplifying the logic a bit.

I think there was an issue with the way we were finding the source directory: when it included a docstring from code, the source directory was that of the code. This always uses the main source directory of the docs.

Closes gh-8733
Carreau added a commit that referenced this pull request Jan 27, 2017
@Carreau Carreau added the backported PR that have been backported by MrMeeseeks label Jan 29, 2017
@jcolonese

jcolonese commented Feb 15, 2019 •

Copy link
Copy Markdown

This fails on Windows. Not sure but seems like Sphinx removes the "\" from os.path.join and can't find files on savefig_dir when rendering html.

I have also set ipython_savefig_dir in conf.py and the images are saved in the right directory.

Using it right now for documenting a Windows app, so to make it work, I simply added

if os.name == 'nt':
     outfile = outfile.replace('\\', '/')

Not sure if it's the best way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backported PR that have been backported by MrMeeseeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants