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

Need Developer Docs for adding a new language/kernel #61

Closed
dsblank opened this issue Sep 8, 2018 · 12 comments
Closed

Need Developer Docs for adding a new language/kernel #61

dsblank opened this issue Sep 8, 2018 · 12 comments

Comments

@dsblank
Copy link
Contributor

dsblank commented Sep 8, 2018

Great tool! Would be great for me and future generations to document the steps needed to add a new language.

Consider Scheme. There is a link to a live kernel here:

Binder

Details:

Anything else one needs?

@mwouts
Copy link
Owner

mwouts commented Sep 9, 2018

Thanks @dsblank , that's a very nice suggestion.

Well, I'm not sure the current organisation of the code is prepared for being documented... It has improved a lot with v0.6.0, but adding a new format still requires modifying the code at lots of places (latest example was Julia #56).

So I think that we should first refactor the code a bit further. There are already three more formats in the pipe, and the refactored code should allow an easier inclusion of those:

@dsblank
Copy link
Contributor Author

dsblank commented Sep 9, 2018

Org mode looks very interesting, and perhaps a nice way to combine jupyter notebooks and jupytext ideas in a scalable fashion.

Some other links regarding org mode and jupyter:

@mwouts
Copy link
Owner

mwouts commented Sep 18, 2018

Hello @dsblank , I have been working on refactoring, and was able to add a new format (the double percent scripts #59). It now requires

  • Adding a new class derived from BaseCellReader for reading cells from text
  • A class that derives from BaseCellExporter for exporting cells to text
  • appending the definition of the format to formats.py

The corresponding commit (that also includes a bit of noise, sorry) is 3f3a12b

Do you think that structure is sustainable? Would you recommend another organization? I feel recommendations on this could be very useful! Thanks.

@dsblank
Copy link
Contributor Author

dsblank commented Sep 19, 2018

I don't really have a feel for what this code is doing. Why does jupytext even need to be parsing the cell data? It seems that code cell data should be either sent directly to the kernel, or saved as-is in a section marked as "code cell".

@mwouts
Copy link
Owner

mwouts commented Sep 24, 2018

@dsblank , I have just implemented the double percent format for Python/Julia/R (#59). That format is interesting as it is almost language agnostic. Would you like an adaptation of that format for scheme (that's easy, I just need to replace the comment char # with the ;;...) ?

Two quick questions:

  • Could you contribute a sample scheme notebook to the tests/notebooks directory ? (or, may I copy the Mandelbrot one?)
  • Should jupytext comment the Jupyter magic commands in the resulting scheme script?

@dsblank
Copy link
Contributor Author

dsblank commented Sep 25, 2018

The line comment per language seems like it would be something that the kernels should be able to identify. (I recommended this to jupyter core 4 years ago, but it wasn't adopted at that point).

The magics in Scheme are language agnostic: they come from Metakernel. (We could have metakernel identify the line comment character(s)).

https://github.com/Calysto/metakernel/blob/master/metakernel/magics/README.md

The current rules for Metakernel magics:

  1. they start with %, %%, or %%%.
  2. they have to appear at the beginning of the cell
  3. they can have flags and arguments, like the command-line

The Metakernel magics also provide the shell interaction.

The Mandelbot one is one of the most complicated, as it uses the full power of Metakernel. Feel free to use any of the notebooks from our repos. Perhaps a better representative notebook would be:

https://github.com/Calysto/calysto_scheme/blob/master/notebooks/Reference%20Guide%20for%20Calysto%20Scheme.ipynb

FYI, perhaps the most popular Metakernel languages are octave and matlab:

@mwouts
Copy link
Owner

mwouts commented Sep 27, 2018

Hello @dsblank , the branch v0.7.2 has support for scheme! The resulting scripts are here (percent format, which you can open with Hydrogen) and here (light format, which has fewer explicit cell markers).

Would you like to test this and provide feedback? Currently I have implemented the support for just one comment character per script extension - for scheme I have choosen ;;. Do you think that is good enough? Would you prefer just ; ?

By the way - extending the light and percent formats for more file extensions is easier than ever before:

  • add one line to _SCRIPT_EXTENSIONS in languages.py
  • contribute a sample notebook in tests\notebooks\ipynb_[language]
  • add two tests in test_mirror.py: one for the light format, one for the percent format...

... Which file extension do you want to do next ? 😄

@dsblank
Copy link
Contributor Author

dsblank commented Sep 28, 2018

Very cool! I will test this out!

mwouts added a commit that referenced this issue Oct 3, 2018
Documented how to extend light and percent format #61
Scheme and C++ mentioned
Transition to jupytext section #91
Added a word on format_version
@mwouts
Copy link
Owner

mwouts commented Oct 9, 2018

@dsblank , I will soon review the treatment of magics in Jupytext (and possibly make it simpler, cf. #94). May I ask you two questions?

  1. Do you think I can consider any command that starts with one or two percent sign as a 'magic'? Are there legitimate Python commands that start with one percent sign?
  2. Above you mention that metakernel magics may start with up to three percent signs. I have never seen one of those, may I ask you to confirm?
    Thanks,

@dsblank
Copy link
Contributor Author

dsblank commented Oct 9, 2018

  1. I believe that is correct that there are no regular python code that can start with a percent.
  2. Other languages can start with percents, but we decided for metakernel, we would put those at very top of cell. Metakernel can have 1, 2, or three percents (3 means sticky magic, and continues to apply)
  3. Note that ipython's magics can appear anywhere, even on right of an equal sign.
  4. We are considering allowing some metakernel magics in middle of code, but still at left of line (like %include)

This was referenced Oct 9, 2018
mwouts added a commit that referenced this issue Oct 10, 2018
Documented how to extend light and percent format #61
Scheme and C++ mentioned
Transition to jupytext section #91
Added a word on format_version
@mwouts
Copy link
Owner

mwouts commented Oct 10, 2018

A brief documentation on how to extend the light and percent format is available in the readme in version 0.8.0. Scheme and C++ are supported already!

@mwouts mwouts closed this as completed Oct 10, 2018
@mwouts mwouts mentioned this issue Oct 10, 2018
@mwouts
Copy link
Owner

mwouts commented Oct 11, 2018

Well, I just noticed with #97 that the 'mirror' test was not covering properly the round trip conversion. This has been fixed in v0.8.1 which is thus the first version with proper support for C++ and Scheme.

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

No branches or pull requests

2 participants