mwouts / jupytext

Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
https://jupytext.readthedocs.io
MIT License
6.6k stars 386 forks source link

Automatically add shebang #1149

Open txoof opened 11 months ago

txoof commented 11 months ago

Is there a way to add the shebang to projects that start from within Jupyter? I can't find a way other than running:

!jupytext Untitled.ipynb --update-metadata '{"jupytext":{"executable":"/usr/bin/python"}}' --to py from within the notebook to do this.

This works, but is rather convoluted and requires some non-intuitive commands; this seems rather contrary to the ease of the rest of jupytext. The method above also causes the Reload/Cancel/Overwrite dialogue to pop up.

Related comment from @mwouts in https://github.com/mwouts/jupytext/issues/914#issuecomment-1032934480_

mwouts commented 10 months ago

Hi @txoof , well I don't think there is any other programmatic way to do this, but if you prefer you could directly edit the notebook metadata, like in this screenshot: image

txoof commented 10 months ago

@mwouts

Thanks for the suggestion. That definitely works. It just feels hacky for such an otherwise comprehensive tool that does everything else almost magically.

I guess I'll migrate this to a feature request.

mwouts commented 10 months ago

Thanks 😊

I will think about this.

Maybe we could let users configure a default shebang or, more generally, a default metadata through the Jupytex configuration file.

These weeks, we are finishing Jupytext 1.16, which will improve the user experience in JLab 4, I will come back to this afterwards.

txoof commented 10 months ago

@mwouts Thanks! Jupytext has revolutionized my workflow. I really love this tool!

mwouts commented 10 months ago

Glad you like it! Thank you for your kind works.