Skip to content
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

Add Cython to list of language magics #622

Merged
merged 1 commit into from
Oct 1, 2020
Merged

Conversation

mje-nz
Copy link
Contributor

@mje-nz mje-nz commented Sep 12, 2020

Add Cython to the list of language magics, so that Cython cells get commented out in non-notebook formats.

FWIW I don't think it would make sense to open Cython files as notebooks; each Cython cell in a notebook is compiled separately, so a file with any dependencies between cells would fail as a notebook.

@mwouts
Copy link
Owner

mwouts commented Sep 13, 2020

Hi @mje-nz, thanks for reporting this. I think I have seen that the %%cython cell magic comes with the cythonmagic extension. Is this correct?

If so, maybe I'd had a preference for letting the user use the new custom_cell_magics option that was developed for #513. I mean, what would you think of adding

custom_cell_magics = "cython"

to your jupytext.toml file?

@mje-nz
Copy link
Contributor Author

mje-nz commented Sep 13, 2020

The extension is called Cython not cythonmagic and it's bundled into the main Cython package now, but basically yes.

Oh I missed custom_cell_magics! That would solve it, but I can't see a scenario where a user would want Cython to not be treated as a language. You already have much less common languages in the list of language magics, why draw the line here?

@mwouts
Copy link
Owner

mwouts commented Sep 15, 2020

You already have much less common languages in the list of language magics, why draw the line here?

That is correct! Well the current line is more or less which magic cells are supported by default in Jupytext. Still I agree with you, cython should be added there, because we do want cython cells to be represented as

```{cython}
(...)
```

in Markdown. But then the question is... should we distinguish between cell magics that represent languages, and those that do do, like %%time or %%configure ? Do we need to comment out the corresponding cells in scripts? Let me think about that...

@mje-nz
Copy link
Contributor Author

mje-nz commented Sep 15, 2020

Well basically every cell magic is not equivalent to just executing the cell contents in the current kernel, so shouldn't the default be to comment out the cell? Even magics like %%python and %%timeit which take Python code are semantically different to executing the cell contents.

I guess it depends on whether the user wants a script that does the same thing as running the notebook (as much as possible), or just a plain-text version of the notebook that's convenient for version control. Maybe custom_cell_magics should be custom_language_magics and there should be an option for whether to comment out cells with unknown magics?

@mwouts mwouts added this to the 1.6.1 milestone Sep 19, 2020
@mwouts
Copy link
Owner

mwouts commented Oct 1, 2020

Hi @mje-nz , I'll take this PR, and we can continue thinking about magic cells at #643 😄 Thank you!

@mwouts mwouts merged commit e61a244 into mwouts:master Oct 1, 2020
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.

2 participants