-
Notifications
You must be signed in to change notification settings - Fork 13
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
Integration with jupytext #32
Comments
A filter to convert to/from jupytext and Jupyter notebooks could be nice. I've thought about the possibility occasionally, but haven't actually attempted anything. I can't invest any significant time in this, given my other projects and commitments. I'm happy to answer questions about how Codebraid works to help in the creation of filters, and might have time to help with converting a basic subset of Codebraid features to/from jupytext/Jupyter. There are a few questions that would be useful to consider in thinking about this:
|
While I am aware of all the limitations of jupyter compared to codebraid, I think having an interactive environment where you can execute chunks and see the result would be very powerful (basically compilation vs. REPL). Right now I can only think of jupyter and its popularity. Leveraging it, even for a subset of codebraid, would add a lot of value. |
I'm also interested in codebraid+jupytext but I'm not sure I have quite the same use-case as @teucer My use-case is leveraging jupytexts command-line tools to convert scripts (.py, .R, .sh etc) to markdown. Previously I had used Pweave for this but It seems to be unmaintained (for now) and I like that codebraid can work without jupyter kernels. I have implemented one-way conversion *EDIT: the filter works on pandoc ast (of course) so it can convert from any format supported by pandoc including .ipynb. The filter is here It can be used like so:
@gpoore would you be interested in a PR to add something like this? |
Hello @gpoore , thank you for considering this. I'll give my view point on a few questions, hopefully that can help:
As you mention, there are two direct benefits:
If we work on this, an indirect benefit will be a good certification on the round trip between
I agree. We will have to determine how to represent these features in a notebook, even if they are not active there (until someone develops a Jupyter extension to activate them). Let me also note that we have had the same challenge for the R Markdown and for the Myst-Markdown formats. In practice, my target is that the same document should run, as much as possible, both in Jupyter and in the natural renderer (for instance, in R Markdown we have to comment out Jupyter magic commands because If you want to go further, I propose that someone with a good knowledge of |
@timothymillar Thanks for linking to your filter! I'm not sure at this point if I want to include filters within Codebraid itself. I've looked into Jupyter conversion some more, and it appears that filters can only handle a very limited set of cases. However, I think it could be worthwhile to start collecting Codebraid-related filters. I can create a Codebraid wiki page for filters and link to your filter from there for now. Then perhaps at some point it may be worth creating a separate repo for filters. |
I've done some research and experimentation, and have a proposal for how to proceed with this. There is a subset of Codebraid features that maps exactly to a Jupyter notebook, so I think it makes sense to start with support for that and then gradually add support for other things (in some form) from there. So to start with, implementation is simpler at the cost of some documents failing to convert. Since Pandoc already has ipynb support and Codebraid is based on manipulating the Pandoc abstract syntax tree (AST), I think the easiest way forward is to convert a Codebraid Pandoc Markdown document into Pandoc's Markdown representation of a Jupyter notebook. Then Pandoc can create the actual notebook from there. Converting from Jupyter notebook to Codebraid is just the reverse, again with Pandoc's Markdown notebook as an intermediary. I've done a few experiments, and this looks like a straightforward process for the subset of Codebraid features that maps exactly to a Jupyter notebook. I can add support for this as I have time, and then that will provide a starting point for working on the more difficult cases as they are needed. It's possible that many people who want to convert back and forth won't need the features that are especially difficult to translate. @mwouts I can plan on adding options to the |
Hi @gpoore , these are great news! I think I'd prefer to use To integrate I would also have use of the following:
|
Not having followed the entire discussion, I still would like to share my use-case: For multiple Python-related classes, I am using RISE to present, in an iteractive fashion, aspects of the language and libraries. RISE has the great advantage of allowing ad-hoc variations of code ("What would happen if we changed this to ....?"), which adds a lot of value to the audience, IMO. For preparation and reviewing, I provide lecture materials in multiple formats, namely
All this is being produced from a version-controlled, authoritative Markdown document per unit using a sophisticated Pandoc workflow with filters etc. Now, Jupytext does a pretty good job of creating and keeping in sync a Markdown and an But for lecture notes, you typically want to show the code snippets and their effects. Despite quite some research, I do not have an ideal solution; starting from the It is a lot easier starting from the Jupytext-provided Markdown document, except for a few quirks and the missing output cells.. IMO, a straightforward solution would be for Jupytext to add CodeBraid classes to PandocCode blocks, as follows: Jupytext Output:
With CodeBraid classes:
The same could be done for From an implementation point of view, this could be handled by
The actual execution of CodeBraid could be left to the workflow that processes the Markdown representation; IMO, there is no need to hard-wire the two components. As for interactivity: I would not spend too much effort on this, because CodeBraid and Jupyter cover very different parts of the spectrum - for a highly interactive class, changing and running code snippets as we go is much better in Jupyter Notebook than in any more advanced Markdown-Workflow (I would also not use Quarto in here.). Apologies if this is lengthy and a bit off topic; I really appreciate your efforts on the CodeBraid and Jupytext sides; they help tremendously in doing better in teaching and research! Hence, a huge thank you to @gpoore and @mwouts! |
It would beneficial to integrate with jupytext and hence jupyter notebooks. Jupyter can indeed become an interactive editor for codebraid.
To be able do so a seamless conversion from codebraid to ipynb is required. I believe a pandoc filter could achieve that.
@gpoore Would you be interested in such an approach?
The text was updated successfully, but these errors were encountered: