question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Magic cell languages vs magic cell commands

See original GitHub issue

Following #513 and #622, I’d like to think a bit about how magic cells are/should be handled.

Here are my expectations

  1. 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
  1. 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:open
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mwoutscommented, Nov 4, 2020

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.

0reactions
mwoutscommented, Nov 24, 2020

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 where jupytext is very different from nbconvert - 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 are

  • use jupyter nbconvert if you are looking for a one way conversion .ipynb to .md
  • use Jupytext’s paired notebooks (synchronized .ipynb + .md files) if you want to edit either the .ipynb (with outputs) or the .md file
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found