Magic cell languages vs magic cell commands
See original GitHub issueFollowing #513 and #622, I’d like to think a bit about how magic cells are/should be handled.
Here are my expectations
- If a cell has a magic cell that is a language, say e.g.
R
, that differs from the main notebook language, say e.g.python
, then
- it is entirely commented out in the
.py
file - it appears as a
```R
code cell in the.md
file
- Cells with a magic cell that is not a language should appear verbatim in the
.md
file. The cell magic should always be commented out in the.py
file. For some cell magics like%%time
or%%capture
it may not be necessary to comment out the cell content in the.py
file. For some other cell magics like%%script
, commenting out the full cell is required.
I think (but would like to check) that we are actually doing that.
Currently the distinction between 1. and 2. is made based on jupytext.languages._JUPYTER_LANGUAGES
(script
is one of them), plus the configurable custom_cell_magics
. Do we cover all the use cases?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Built-in magic commands — IPython 8.7.0 documentation
Create a cell magic alias. -p PARAMS , --params PARAMS. Parameters passed to the magic function.
Read more >IPython - Magic Commands - Tutorialspoint
These magic commands are intended to solve common problems in data analysis using Python. In fact, they control the behaviour of IPython itself....
Read more >Magic commands in IPython.
There are two types of magic commands — line magic commands, and cell magic commands. Line magic commands work only with the line, ......
Read more >Enhance kernels with magic commands - Amazon EMR
Cell magics – These magic commands are denoted by a double %% prefix and operate on multiple lines of code. A full list...
Read more >List of Useful Magic Commands in Jupyter Notebook/Lab
Cell Magic Commands : It applies the command to the whole cell of the notebook and needs to be kept at the beginning...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @lc5415 , thanks for reporting the double magic case! I agree with you, the cell should be fully commented out in this case. I’ll try and see if I can fix this in the next release.
Hi @fm75 , thanks for asking.
As @chrisjsewell and @choldgraf mentioned in the other discussion, the outputs are never stored in the Jupytext files (and this is not related to magic or not magic commands).
You were probably expecting something closer to the output of
jupyter nbconvert
? Indeed this is an area wherejupytext
is very different fromnbconvert
- Jupytext focuses on the part of the notebook that the user wrote, not the part that was generated by the machine and which is often thousand times larger. Of course I understand that not having outputs can be troublesome, so depending you what you are trying to achieve, my recommendations arejupyter nbconvert
if you are looking for a one way conversion.ipynb
to.md
.ipynb
+.md
files) if you want to edit either the.ipynb
(with outputs) or the.md
file