-
Notifications
You must be signed in to change notification settings - Fork 394
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
remove obsolete option --comment-magics #465
Conversation
--comment-magics is not available in version 1.4.1
Codecov Report
@@ Coverage Diff @@
## master #465 +/- ##
=======================================
Coverage 98.88% 98.89%
=======================================
Files 79 80 +1
Lines 7823 7861 +38
=======================================
+ Hits 7736 7774 +38
Misses 87 87
Continue to review full report at Codecov.
|
Thanks for pointing this out... We really should have a test that executes all these commands! What happened is that the
So maybe I'd prefer to keep the example with |
I agree with your suggestion. I think it is useful if this option is explicitly mentioned in the docs. The feature that magic commands are commented out by default confused me at the beginning. (I use VS Code and did not read the docs in a linear fashion but skipped directly to the command line usage) Thank you for providing such a great package! |
Thank you @FSpanhel . I have added a test on the documentation, we'll see how it goes... There's one more thing I'd be curious to know... are you able to run the magic commands in VS Code? |
Okay. Commands that are specific to IPython, such as shell or magic commands, are commented out by default. Instead of deactivating these commands I would convert them so that the script can be run with 'pure' Python. The conversions would be as follows: !dir -> IPython.get_ipython().system('dir') So you would also have to add 'import IPython' at the beginning of the script (or from IPython import get_ipython, which I would prefer). You could probably call this format the 'vs code' format? You can also see the 'pure' Python equivalent of the IPython commands using %hist -t. I would also propose to use IPython and not Jupyter in sentences like the second sentence in following paragraph (and related paragraphs): |
Hello @FSpanhel , well that's an interesting suggestion. I think translating the IPython code to plain Python would be difficult, so I'd prefer not to implement that in Jupytext. Anyway, if that can help, when I want the same document to be both a valid notebook and a valid script, I use the Also, did you notice the new 'Python interactive' mode in Code? It seems to be using IPython to execute the code. By the way, if you want to use that mode, you may want to use the |
To make a long story short: Have a look at https://github.com/FSpanhel/jupytext_run_shell_magic Excuse my late reply. I was busy and also wanted to take a deeper look at my suggestion.
Moreover, we have to differentiate between a) shell commands “!” and b) magic commands “%”. I think that 1) and 2) are easy to accomplish for shell commands. I think that 1) would work with some magic commands out-of-the box but not with all. Finding out what would work directly and where other solutions are required would definitely be some effort. I do not recommend following this route. However, 2) might be relatively easy to accomplish for all magic commands. So let’s assume I’ve created a notebook *.ipynb and I want to edit my code. I would convert the notebook to *.py script and then use my favorite IDE and the IPython shell to investigates my edits. I typically do not use magic commands, but I often invoke the shell using “!”. For example, see the notebooks mentioned below. Right now, these shell commands are commented out (or do not work) when the notebook is converted to a .py script using jupytext. Let’s have a look at my demonstration: https://github.com/FSpanhel/jupytext_run_shell_magic I’ve written a very simple program (activate_magic.py) that makes shell commands runnable from IPython (as a script or interactively) and that also makes (almost all) magic commands that do not require a kernel available for an interactive IPython session.
Note that I have not considered cell magics. That is because jupytext does not comment out all cell magics (e.g., %latex becomes # %% language="latex") and I have no time to consider this right now. All in all, I hope this demonstrates that it makes sense to consider shell commands for 1) and 2). Maybe one could also allow magic commands to be used for 2). However, I do not know whether this works for all magic commands. Probably it will work for all magics that are not specific to a kernel such as %connect_info. So it could be easy to allow magic commands for 2) or it could also take some time. Apart from that, allowing magic commands for 1) is very though. For instance, using %autocall 1 allows us to write “print 3” instead of “print(3)”. This works if only print 3 is send to the terminal. However, if you send “print 3\n print 2” to the terminal an error is thrown. This also happens if you execute “print 3\n print 2” in a Jupyter notebook cell. That is the reason why ipython magic_with_runnable_magic_cmds.py throws an error. I hope my comments are interesting and useful for you. PS: I’ve found that magic and shell commands are not always commented out., e.g., my_host = !hostname in shell.ipynb is not commented out when using jupytext (maybe because you only check for % as first non-whitespace character?). |
About the 'Python interactive' mode in Code. But doesn't vs code use the percent format? I haven't taken a look into the hydrogen format. Will do. |
So py:hydrogen seems to be the same as py:percent --opt comment_magics=false? |
--comment-magics is not available in version 1.4.1