-
Notifications
You must be signed in to change notification settings - Fork 386
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
feature request: support gonb #1244
Comments
Hi @HaveF , thanks for reaching out! Yep sure it would be a great addition. For that I would need at least a short example notebook, or ideally a full pull request. The process for adding a new language is documented here: https://jupytext.readthedocs.io/en/latest/contributing.html#add-support-for-another-language. Thanks! |
@mwouts Thanks for the reference! |
I believe I can't fix it by myself. @mwouts added _SCRIPT_EXTENSIONS in jupytext/languages.py: ".go": {"language": "go", "comment": "//"}, simple some error:
the sample notebook is copied from gonb/examples/tutorial.ipynb at main · janpfeifer/gonb.
|
Hi @HaveF , can you tell me a bit more about the |
Hi, @mwouts , Thanks for helping me out. I believe your PR is fine. I can help to test.
like %%
fmt.Printf("Hello World!") It will converted to this behind the scenes func main() {
fmt.Printf("Hello World!")
} It can appears at any part of a cell, not just beginning of a cell, like: var startValue = float32(1)
%%
startValue = incr(startValue)
fmt.Printf("current startValue=%f\n", startValue) Do you see the error I mentioned before? Or, you can help to change in #1250, then I test it |
Other special notation in GoNB:
|
Thank you @HaveF - that's very helpful! Well, I'm afraid this is going to be a little tricky... Can I ask you one more question? How do you think that this notebook cell should be represented in the
Do you think that this might work for you? (is this a valid go file?)
|
@mwouts Thanks for your help.
Although this is not a valid go file, I think if someone uses GoNB, he should understand the meaning of
Hi, @janpfeifer (author of GoNB), jupytext's author(Marc Wouts) is help us to support GoNB in jupytext. We are now facing a problem with the correspondence between jupyter notebook and jupytext. Can you help us see if the above syntax correspondence is the most ideal? Or you have other ideas? Thanks! |
Thanks for following up on this, Jupytext looks awesome. I was reading through Jupytext readthedocs page and I'm not sure I got all the details right -- for the A few meta comments, from what I understood (I may be wrong):
Any thoughts? Example of what a Jupytext+Gonb code would look like: // %% [markdown]
// # Defining a $x^2$ function
// It returns x*x.
// %%
func Square(x float64) float64 {
return x * x
}
// %% [markdown]
// # Examples
//
// ## Example A: $x = 3$
// %%
var x = flag.Float64("x", 0.0, "Value of x")
//gonb:%% -x=3
fmt.Printf("Square(%g)=%g\n", *x, Square(*x))
// %% [markdown]
// ## Example B: $x = 4$
// %%
//gonb::%% -x=4
fmt.Printf("Square(%g)=%g\n", *x, Square(*x)) This seems unambiguous, trivial to parse ... but not very pretty on the eyes 😄 (too many I would suggest an alias for the Btw, if (1) becomes a serious usability issue (IDE complaining of various // %% [markdown]
// ## Example C: $x=5$:
// %%
func exampleC() {
fmt.Printf("Square(%g)=%g\n", *x, Square(*x))
}
//gonb:%main exampleC -x=5 |
I just went for a hike and was thinking more about it: one of the benefits of the Jupytext file were named So I like even more the idea of having a The above example could look like a file package square
// %% [markdown]
// # Defining a $x^2$ function
// It returns x*x.
// %%
func Square(x float64) float64 {
return x * x
}
// %% [markdown]
// # Examples
//
// ## Example A: $x = 3$
// %%
var x = flag.Float64("x", 0.0, "Value of x")
func example() {
fmt.Printf("Square(%g)=%g\n", *x, Square(*x))
}
//gonb:%main example -x=3
// %% [markdown]
// ## Example B: $x = 4$
// %%
//gonb:%main example -x=4 This way this compiles in Go, and we can even create on the side a file Any thoughts ? |
@janpfeifer ❤️ Thanks for your constructive comments.
|
Hi @HaveF , @janpfeifer , thank you for your useful inputs! That's very interesting. And thank you for your kind comments too! To follow-up on the above,
I'll ping you when I get a development version that you can try to see how it works on real notebooks. |
I might have something that works with the percent and markdown formats (not yet with the "light" format):
(remove Let me know how it works for you. Thanks! |
Wow! @mwouts Your speed is really fast! I tried it and it seems to be OK. The corresponding go files can't really be go files(just forget about the IDE complaining 😄 ). I think it's pretty good (and simple) for now. I love it! What do you think? @janpfeifer If you haven't used jupytext before, I suggest you try it, it's really useful! |
Very neat 😃 ! It's working here, see image below. A couple of things:
I also updated
I'm definitely using For my testing: File // %% [markdown]
// # Square Function
//
// Defines a function $f(x) = x^2$
// %%
func Square(x float64) float64 {
return x*x
}
// %% [markdown]
// # Examples
//
// ## Example A: $x = 3$
// %%
var x = flag.Float64("x", 0.0, "value of x to feed f(x)")
//gonb:%% -x=3
fmt.Printf("Square(%g)=%g\n", *x, Square(*x))
// %% [markdown]
// ## Example A: $x = 4$
// %%
//gonb:%% -x=4
fmt.Printf("Square(%g)=%g\n", *x, Square(*x)) Yields the following notebook: |
hi @janpfeifer
|
Oh, thanks @HaveF ! I hadn't realize you start from the Now about the space in between If you both agree, @mwouts would that work for you, have In the |
Hi both, thank you for your feedback! Quick comments
Sure I can do
I would have expected the contents manager to set a kernel in a matching language if you open a
Thanks! As pointed out in the documentation, for writing documentation you might want to use one of the Markdown-oriented formats (the most advanced one is the MyST Markdown format, which works well with Jupyter Book), but of course the choice is entirely up to you. An example is included in the PR, see https://github.com/mwouts/jupytext/blob/support_gonb/tests/data/notebooks/outputs/ipynb_to_myst/hello_world_gonb.md |
+100 from my side: we get the best of both worlds, space for the cell makers ( Thanks for the pointers on the |
Great! I've updated the PR by the way, if you want to test the latest development version (I will follow-up on the default kernel later on, possibly in another issue). |
I just re-installed and tried it -- but I'm not sure if I'm getting the latest version -- but in one case the The
When converted back to the notebook with But maybe I didn't get the latest version ? ps.: I'm doing a Mandelbrot fractal drawing example, I'll publish it as soon as I'm done. |
So I just wrote the following (typical for me) notebook: I notice that the special commands that start with a single
Converted
An issue is that when converting this back to But maybe I got the wrong version ... |
Hi @janpfeifer, thanks for the example! Very nice notebook! A few comments I see that you are using the Re the round trip support, that matters a lot to me, so thanks for sharing that example! I'll get that fixed soon. Before that, I think it's worth chatting a bit more about the usual magic commands. The most standard magic commands in Jupyter are the Some languages have other magic commands. In Python for instance, Magic commands are commented out when a notebook is exported to either a Now, if we go back to the I know you mentioned replacing it with Would it be a constraint for you to require that the command is always at the top of a cell? That's not a big deal for me, but I think the support for magic commands at the top of a cell is better tested. My plan is to categorize the |
Thanks for the explanation. So in my installation is a Ubuntu 24.04, python 3.12.3, using So I was trying to use jupytext from the command line, and I'm assuming I'm missing a lot 😃 I did follow the installation instructions and did The command I did browse through the JupyterLab logs it prints out during execution, and the only reference to Jupytext I see is a line like:
Any ideas why it doesn't show up as installed ? |
Ok, after searching around, I found a stackoverflow question that suggests one should use instead So I did:
And now during the execution of JupyterLab I get the following in the logs:
I hadn't realized that there are 2 extensions: |
Hi Jan, no you don't miss that much - the lab extension is just the "Jupytext menu". You can use a config file as an alternative. To get the extension, can you uninstall both Jupytext and the extension that you installed manually, and reinstall them using the full compilation command, e.g. HATCH_BUILD_HOOKS_ENABLE=true pip install git+https://github.com/mwouts/jupytext.git@support_gonb You will need nodejs for this. Note that I didn't change anything since the second dev release, so there's a bit more work needed on the magic commands. |
hi @mwouts thank you so much! I had forgotten that I installed it without the hooks. After installing nodejs and reinstalled The pairing is very convenient to be done automatically when editing the notebook or the text file! |
Hey, here it seems all working well. Any concerns @HaveF , @mwouts ? I was thinking of creating a new release of GoNB with support for Do you have plans for any releases @mwouts ? Or should I mention installing from the branch ('@support_gonb`) for those wanting to try it for now and leave it like that for a while longer ? cheers |
@janpfeifer I believe it is great. @mwouts Thanks your great work! |
Hi @janpfeifer , yes sorry I'd need a little more time - I'd like to support the Also, what were the remaining cases of unremoved After that I'd be very happy to publish a new release. I should be able to do so at worse on next Tuesday evening. |
No worries, no hurry. In GoNB I don't require them to be at the top of the notebook. But they are executed before the cell Go code is executed, irrespective of where they are in the cell. But the common use case is not to mix shell ( |
Hi @HaveF , @janpfeifer , I've added a few commits to the PR. It should have support for the |
Thank you @mwouts, it is great! I just tried it, and all the special commands I tried ( This time i tried to install the extension ( |
Great! What is the compilation error exactly? You might need to upgrade nodejs (see https://jupytext.readthedocs.io/en/latest/developing.html) |
Jupytext v1.16.3 is now available on pypi! Thanks for your feedback on this topic, and for the patience re the release (the publish CI failed a few times due to another change...) |
Thanks @mwouts ! Very appreciated. I'm already advertising it in gonb's home 😄 |
Thanks for this repo!
could it possible support gonb?
for now, error:
jupytext.formats.JupytextFormatError: Extension '.go' is not a notebook extension. Please use one of '.ipynb', '.md', '.markdown', '.Rmd', '.py', '.coco', '.R', '.r', '.jl', '.cpp', '.ss', '.clj', '.scm', '.sh', '.ps1', '.q', '.m', '.wolfram', '.pro', '.js', '.ts', '.scala', '.rs', '.robot', '.resource', '.cs', '.fsx', '.fs', '.sos', '.java', '.groovy', '.sage', '.ml', '.hs', '.tcl', '.mac', '.gp', '.do', '.sas', '.xsh', '.qmd', '.myst', '.mystnb', '.mnb', '.auto'.
The text was updated successfully, but these errors were encountered: