Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[MRG] FIX import local modules in examples #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 14, 2018

Conversation

NelleV
Copy link
Contributor

@NelleV NelleV commented Oct 15, 2017

This patch allows to import a module placed in the same folder as the examples when executing the example by adding the current directory to the sys.path.

I used a deepcopy to restore the sys.path to the original state (before running the example).

This patch relates to a problem we are having on matplotlib/matplotlib#9402
I am honestly not entirely convince that sphinx-gallery should support this, as I think that good examples are self-contained examples.

@choldgraf
Copy link
Contributor

can anyone think of a way in which this could bite us in the long-run?

@larsoner
Copy link
Contributor

The way I have solved this previously is by doing sys.path.insert(0, os.getcwd()) in the few examples that require such functionality. I don't mind it because it's explicitly showing that an import needs to be made to some local file.

That being said, I don't mind adding this bit of code. My understanding is that SG running scripts is meant to mimic running them manually as much as possible. This seems like it will improve upon that. So +0.5 from me

@Titan-C
Copy link
Member

Titan-C commented Oct 16, 2017 via email

@lesteve
Copy link
Member

lesteve commented Oct 16, 2017

This would be nice to have a test for this, ideally as a unit test, but a separate example will do if the former is very inconvenient. Without test, this kind of micro-features tend to be broken very quickly.

@NelleV
Copy link
Contributor Author

NelleV commented Oct 16, 2017

Great! I'll write a test for this then (or add an example)

@NelleV NelleV changed the title FIX import local modules in examples [WIp] FIX import local modules in examples Oct 16, 2017
@NelleV NelleV changed the title [WIp] FIX import local modules in examples [WIP] FIX import local modules in examples Oct 16, 2017
@anntzer
Copy link
Contributor

anntzer commented Oct 17, 2017

Copying sys.path can be done with just sys.path[:] (or sys.path.copy() if you want to be super explicit) -- it's always a list of strings, nothing fancier.

@tacaswell
Copy link
Contributor

Somewhat related, where does the information for the new style namespace packages get stashed?

@lesteve lesteve force-pushed the master branch 3 times, most recently from 0c1f0d4 to 49d4f11 Compare June 13, 2018 18:18
@GaelVaroquaux
Copy link
Contributor

Is this still up to date? If so, @NelleV : can you fix the merge conflict, so that we merge this.

@tacaswell
Copy link
Contributor

Also maybe related to matplotlib/matplotlib#11838 (which breaks building on python3.7).

@codecov-io
Copy link

codecov-io commented Sep 2, 2018

Codecov Report

Merging #305 into master will decrease coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #305     +/-   ##
=========================================
- Coverage   95.48%   95.39%   -0.1%     
=========================================
  Files          29       29             
  Lines        2239     2191     -48     
=========================================
- Hits         2138     2090     -48     
  Misses        101      101
Impacted Files Coverage Δ
sphinx_gallery/gen_rst.py 97.27% <100%> (-0.28%) ⬇️
sphinx_gallery/gen_gallery.py 87.79% <0%> (-0.55%) ⬇️
sphinx_gallery/tests/test_full.py 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0879f21...fc75e3e. Read the comment docs.

@larsoner
Copy link
Contributor

larsoner commented Sep 2, 2018

It would also be good to add a test. @NelleV if you do not have time I'm happy to take over and add one

NelleV and others added 2 commits November 14, 2018 11:53
This patch allows to import a module placed in the same folder
as the examples when executing the example by adding the
current directory to the sys.path.
@larsoner
Copy link
Contributor

Rebased and tests added, I'll merge once it's green since folks were happy with it other than needing a test

@larsoner larsoner added this to the v0.3.0 milestone Nov 14, 2018
@larsoner larsoner changed the title [WIP] FIX import local modules in examples [MRG] FIX import local modules in examples Nov 14, 2018
@NelleV
Copy link
Contributor Author

NelleV commented Nov 14, 2018

Thank you :)

@larsoner larsoner merged commit 961d74d into sphinx-gallery:master Nov 14, 2018
@larsoner
Copy link
Contributor

Thanks @NelleV

@tacaswell
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants