FemtoCleaner.jl
FemtoCleaner.jl copied to clipboard
Add Jupyter cleanup
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.
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
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
... 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!