-
Notifications
You must be signed in to change notification settings - Fork 206
Fix for when sys.argv is used in examples #252
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
Conversation
ping @Titan-C @choldgraf. |
CHANGES.rst
Outdated
@@ -4,6 +4,7 @@ Change Log | |||
git master | |||
---------- | |||
|
|||
<<<<<<< 5eb83a7c61a79656f24e61f5c90c631082265359 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left over from rebase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
@@ -0,0 +1,14 @@ | |||
""" | |||
Using ``sys.argv`` in examples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be an RST heading
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
sphinx_gallery/gen_rst.py
Outdated
|
||
argv_orig = sys.argv[:] | ||
if block_vars['execute_script']: | ||
print('Executing file %s' % src_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently use the Sphinx logger not the print statement. The execution of the file is stated in generate_dir_rst
and not here anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the print
statement. I think that is what you were aiming at.
sphinx_gallery/gen_rst.py
Outdated
argv_orig = sys.argv[:] | ||
if block_vars['execute_script']: | ||
print('Executing file %s' % src_file) | ||
sys.argv[0] = src_file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? sys.argv[0]
corresponds to the executing binary, most probably it would be python
as example scripts are not executable on their own (there is no shebang). I wouldn't like to have this hint to the src_file
, because people might start abusing it. We already don't provide the __file__
variable because of incompatibility with the Jupyter notebooks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise sys.argv[0]
is sphinx-build
leading to a very confusing error message like the one shown in #251 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some issues pending. Maybe the try block is not necessary, changing the sys.argv value can be enough.
Thanks, merging |
You are right, basically what happens is the equivalent of
It is consistent with this example,
|
Ah I see, thank you for explaining. You mentioned:
And I noticed that there are scikit-learn examples that do use |
I think that the example you mention is not run by sphinx-gallery. AFAIK scikit-learn sphinx-gallery config only use the |
Ah okay - that makes sense - thanks for clarifying. |
Fix #251.
The fix is not the nicest one (maybe changing
sys.argv
inside atry
clause and changing it back inexcept
would make it a bit better) but it works ...