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

Sage support #727

Closed
frcl opened this issue Feb 2, 2021 · 7 comments · Fixed by #732
Closed

Sage support #727

frcl opened this issue Feb 2, 2021 · 7 comments · Fixed by #732
Milestone

Comments

@frcl
Copy link
Contributor

frcl commented Feb 2, 2021

I noticed that when I pair a notebook with a sagemath kernel with a markdown file, code blocks are not converted to code cells. Here is a minimal example:

---
jupyter:
  jupytext:
    formats: ipynb,md
    text_representation:
      extension: .md
      format_name: markdown
      format_version: '1.2'
      jupytext_version: 1.9.1
  kernelspec:
    display_name: SageMath 9.2
    language: sage
    name: sagemath
---

```sage
print("Hello world")
```

After converting with jupytext --to ipynb exmplae.md the code block ends up in a markdown cell. With a python kernel and a python code block the conversion works as expected, resulting in a code cell.

The documentation states that

Code snippets are turned into code cells in Jupyter as soon as they have an explicit language, when that language is supported in Jupyter.

But sage is supported by Jupyter. Maybe what is meant here is that the language must be supported by Jupytext? Since sage is not listed under supported languages. I would be grateful for a clarification.

@mwouts
Copy link
Owner

mwouts commented Feb 2, 2021

Hi @frcl , thank you reaching out! Well that part of the documentation could be improved, for sure.

What I meant is that you can have code cells in another language than the main notebook language (often Python) if there is an official magic command for that language (like %bash or %javascript, cf https://ipython.readthedocs.io/en/stable/interactive/magics.html).

In your case it seems that the main language for your notebook is Sage. You're right, Sage is not currently supported by Jupytext - but that should be a very easy pull request. You have provided already a sample notebook, that's great, could you please confirm what is the most common file extension for Sage files? Is that simply .SAGE? or .sage? Thanks

@mwouts
Copy link
Owner

mwouts commented Feb 2, 2021

Apparently the extension is .sage.

I've started a new branch with 5cb93ed, but the tests don't pass because there is no language_info metadata in the sample notebook that I recreated... @frcl would you mind replacing the notebook that I have added there with an actual (simple) Sage notebook?

@frcl
Copy link
Contributor Author

frcl commented Feb 3, 2021

Thanks of the help. I will provide a notebook with language_info.

@mwouts
Copy link
Owner

mwouts commented Feb 4, 2021

Thanks @frcl for the sample notebook. I am quite surprised to see Python rather than Sage in the language info of the sample notebook, could you please confirm that this is the case for all your Sage notebooks?

If so, we will have to make an adjustment on the way the script extension (should be .sage, not .py, right?) is determined to take this particularity into account.

@frcl
Copy link
Contributor Author

frcl commented Feb 4, 2021

Well, sage is just a thin wrapper around python with some snytaxtic sugar added with a preparser and lots of libraries. In general sage code will not execute when called directly with python, so the ambiguous extension .py may cause some confusion. It is relatively simple to convert the sage script to a python script, but converting back may be problematic.

The language_info is in fact equivalent in all my sage notebooks, except for version numbers.

@mwouts mwouts added this to the 1.10.1 milestone Feb 4, 2021
@mwouts
Copy link
Owner

mwouts commented Feb 4, 2021

Hi @frcl , thanks for the information! I have added a fix to take this specificity into account. Would you like to give a try to the development version? You can install it with

pip install git+https://github.com/mwouts/jupytext.git

(prefix that with BUILD_JUPYTERLAB_EXTENSION=1 if you want the extension for Jupyter Lab 3, but that will require nodejs).
Please let me know how it goes!

@frcl
Copy link
Contributor Author

frcl commented Feb 5, 2021

Works fine. Thank you very much! This is a huge improvement for me.

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 a pull request may close this issue.

2 participants