Coder Social home page Coder Social logo

oxinabox / ipynb2literatejulia Goto Github PK

View Code? Open in Web Editor NEW
24.0 4.0 3.0 503 KB

NBConverter stuff to convert Jupyter Notebooks in to Julia Literate.jl files (This is the opposite of Literate.jl)

License: MIT License

Smarty 11.54% Python 40.89% Shell 8.05% Julia 39.53%
nbconvert julialang jupyter

ipynb2literatejulia's Introduction

ipynb2LiterateJulia

NBConverter stuff to convert Jupyter Notebooks in to Literate.jl files (This is the opposite of Literate.jl)

Demo

  1. We start with this notebook: ODEIntroduction.ipynb
  2. we run bash literate_run_nbconvert.sh demo/ODEIntroduction.ipynb to generate this Literate julia file: ODEIntroduction.jl
  3. we run the Literate.jl script to generate the markdown, notebook and script files in literate_output/:
julia> Literate.markdown("demo/ODEIntroduction.jl", "demo/literate_output/")
[ Info: generating markdown page from `~/.julia/environments/WeaveAwayNotebooks/demo/ODEIntroduction.jl`
[ Info: not running on Travis, skipping links will not be correct.
[ Info: writing result to `~/.julia/environments/WeaveAwayNotebooks/demo/literate_output/ODEIntroduction.md`
"/home/wheel/oxinabox/.julia/environments/WeaveAwayNotebooks/demo/literate_output/ODEIntroduction.md"

julia> Literate.notebook("demo/ODEIntroduction.jl", "demo/literate_output/"; execute=false) # executing require packages to be installed
[ Info: generating notebook from `~/.julia/environments/WeaveAwayNotebooks/demo/ODEIntroduction.jl`
[ Info: not running on Travis, skipping links will not be correct.
[ Info: writing result to `~/.julia/environments/WeaveAwayNotebooks/demo/literate_output/ODEIntroduction.ipynb`
"/home/wheel/oxinabox/.julia/environments/WeaveAwayNotebooks/demo/literate_output/ODEIntroduction.ipynb"

julia> Literate.script("demo/ODEIntroduction.jl", "demo/literate_output/"; execute=false)
[ Info: generating plain script file from `~/.julia/environments/WeaveAwayNotebooks/demo/ODEIntroduction.jl`
[ Info: not running on Travis, skipping links will not be correct.
[ Info: writing result to `~/.julia/environments/WeaveAwayNotebooks/demo/literate_output/ODEIntroduction.jl`
"/home/wheel/oxinabox/.julia/environments/WeaveAwayNotebooks/demo/literate_output/ODEIntroduction.jl"

julia script

We also provide a short and simple Julia script for running the process. It is in the file [literate_run_nbconvert.jl]. Step 2 above can be replaced with:

julia> include("literate_run_nbconvert.jl")
literate_run_nbconvert

julia> literate_run_nbconvert("demo/")

ipynb2literatejulia's People

Contributors

juliatagbot avatar oxinabox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

musm cpfiffer hdrake

ipynb2literatejulia's Issues

directory for output as last argument

(This is a great little utility BTW, so thanks for it!)

I think it would be nice to be able to do something like

bash literate_run_nbconvert.sh demo/ODEIntroduction.ipynb another_output_folder

to specify another_output_folder ๐Ÿ™‚

new nbconvert, template

This seems to fail on nbconvert 6.0.7:

jupyter nbconvert  --to script "$1" --config literate_config.py --template=literate.tpl 

(Same with --template-file=literate.tpl )

Skipping the --template=literate.tpl makes it run, but the markdown cells are dropped.

The changelog mentions changes to the template system

suggested Julia function to simplify workflow

""
    literate_run_nbconvert(;OutputDir="",ConfigDir="")

Convert all Julia ipynb notebooks to jl files, using nbconvert

# Input
- `OutputDir::String`:  path to output folder
- `ConfigDir::String`:  path to where literate_config.py and literate.tpl are

"""
function literate_run_nbconvert(;OutputDir="",ConfigDir="")

    Files = filter(x->endswith(lowercase(x),".ipynb"), readdir())

    ConfigFile = joinpath(ConfigDir,"literate_config.py")
    TemplFile  = joinpath(ConfigDir,"literate.tpl")

    for i = 1:length(Files)
        printstyled("\n\n-------------Converting $(Files[i])-------------\n",color=:blue)
        run(`jupyter nbconvert  --to script $(Files[i]) --output-dir $OutputDir --config $ConfigFile --template $TemplFile --Application.log_level='DEBUG'`)
    end

end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.