Skip to content
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

Add Jupyter cleanup #86

Open
miguelraz opened this issue Jun 12, 2018 · 3 comments
Open

Add Jupyter cleanup #86

miguelraz opened this issue Jun 12, 2018 · 3 comments

Comments

@miguelraz
Copy link

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.

@fredrikekre
Copy link

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

@KristofferC
Copy link
Contributor

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

while Deprecations.edit_file(fpath, deps, endswith(fpath, ".jl") ? edit_text : edit_markdown;
analysis = file_analysis)
if iteration_counter > max_iterations
warn("Iterations did not converge for file $file")
problematic_file = true
break
end
iteration_counter += 1
changed_any = true
end

@miguelraz
Copy link
Author

... 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants