fonsp / PlutoUtils.jl

Nifty scripts to go with Pluto.jl
The Unlicense
22 stars 11 forks source link

Export to a clean .jl file #11

Open Samyak2 opened 4 years ago

Samyak2 commented 4 years ago

Pluto notebooks are already .jl files, but they have comments that may seem foreign to those who haven't used Pluto.jl.

A script to export Pluto notebooks to clean .jl files would be useful in sharing these with other people or platforms (outside of VCS).

(I had the need for a clean jl file while doing the Julia exercises at Exercism)

Samyak2 commented 4 years ago

I want to work on this issue, but I have no idea how to start xD.

Do I wait for the notebook conversion scripts to be added before working on this?

shashankp commented 4 years ago

Great that you're willing to share your learnings 👍

Comments & guids are placeholders needed by Pluto to keep track of code. If by "clean" .jl files means removing comments it would be basically be square one for loading back into Pluto if thats needed later, losing the benefits it provides.

Since you brought it up, notebook conversion is a more common usecase, which might interest you.

shashankp commented 4 years ago

Also, no need to wait for anything, just share the pull request

fonsp commented 4 years ago

@shashankp You mixed up the two repositories

shashankp commented 4 years ago

fixed it 😅

Samyak2 commented 4 years ago

@shashankp you're right, it would lose all benefits of Pluto and the only usecase I have for now is Exercism (which I linked in the original comment).

I wasn't sure how to structure the code since there's no script in the repo yet (the jupyter conversion script is in TODO) to get ideas from/base it on.

shashankp commented 4 years ago

Since .ipynb is essentially json, you could create a new script, include JSON.jl parse .ipynb to extract code snippets and write it to a .jl file.

fonsp commented 4 years ago

@Samyak2 you're right, if you wait a little for the other scripts, you will have a better sense of what the code should look like.

filchristou commented 1 year ago

I don't think it's as easy as it seems because of cell order. Pluto will intelligently evaluate cells according to the dependency tree, but julia scripts will just serially evaluate the code. E.g. if a function is defined later than used, Pluto will have no problem, but the julia script will fail. In the notebook's *.jl file there is a cell order list, but I think that's just for the browser UI. I see two choices :

  1. either the notebook *.jl file must continuously be reconfigured in the background to be a functional julia script
  2. or provide a function (or button) to update the Pluto *.jl notebook file to be also a functionally correct julia script.

Obviously I would prefer the 1. approach, but probably 2. would be more realistic for now.

I am sure you already have ideas on how to get a functionally correct order of the cell's evaluation. Could you please share ?

So, in my understanding, just stripping the comments needed by Pluto comes as a second priority here.