FemtoCleaner.jl icon indicating copy to clipboard operation
FemtoCleaner.jl copied to clipboard

Add Jupyter cleanup

Open miguelraz opened this issue 7 years ago • 3 comments

It would probably not be too hard for FemtoCleaner to update Jupyter notebooks. I think educators would love the autoupgrading of their lectures.

If someone can outline a basic guideline of how to do this, I can take it on.

miguelraz avatar Jun 12 '18 19:06 miguelraz

import JSON, Deprecations

function update_notebook(infile, outfile = infile)
    nb = open(JSON.parse, infile)
    for cell in nb["cells"]
        if cell["cell_type"] == "code"
            old_source = join(cell["source"])
            _, new_source = Deprecations.edit_text(old_source)
            new_source = split(new_source, '\n')
            @views map!(x -> x * "\n", new_source[1:end-1], new_source[1:end-1])
            cell["source"] = new_source
        end
    end
    open(io -> JSON.print(io, nb, 1), outfile, "w")
end

fredrikekre avatar Jun 12 '18 22:06 fredrikekre

Need a while loop over edit_text so that it will run until convergence, see:

https://github.com/JuliaComputing/FemtoCleaner.jl/blob/f3f6a1f53ab8c74960696fdef71a94f9be9b2900/src/FemtoCleaner.jl#L80-L89

KristofferC avatar Jun 13 '18 08:06 KristofferC

... this is the sort of Swedish efficiency that scares me for the world cup. I'll try to whip this into a PR by day's end. Thank you both for the ~intimidating~ input!

miguelraz avatar Jun 14 '18 16:06 miguelraz