-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
Export to .ml with a jupyter-nbconvert command ? #58
Comments
Note that if a |
Thank you for often telling me bugs. I reproduced the problem you said. In order to register the $ jupyter nbconvert --to ocaml notebooks/introduction.ipynb
Traceback (most recent call last):
File "/home/aabe/.local/bin/jupyter-nbconvert", line 11, in <module>
sys.exit(main())
File "/home/aabe/.local/lib/python3.5/site-packages/jupyter_core/application.py", line 267, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/home/aabe/.local/lib/python3.5/site-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/home/aabe/.local/lib/python3.5/site-packages/nbconvert/nbconvertapp.py", line 313, in start
self.convert_notebooks()
File "/home/aabe/.local/lib/python3.5/site-packages/nbconvert/nbconvertapp.py", line 470, in convert_notebooks
cls = get_exporter(self.export_format)
File "/home/aabe/.local/lib/python3.5/site-packages/nbconvert/exporters/base.py", line 110, in get_exporter
% (name, ', '.join(get_export_names())))
ValueError: Unknown exporter "ocaml", did you mean one of: asciidoc, custom, html, html_ch, html_embed, html_toc, html_with_lenvs, html_with_toclenvs, latex, latex_with_lenvs, markdown, notebook, pdf, python, rst, script, selectLanguage, slides? In addition, an output file from $ jupyter nbconvert --to script notebooks/introduction.ipynb
[NbConvertApp] Converting notebook notebooks/introduction.ipynb to script
[NbConvertApp] Writing 867 bytes to notebooks/introduction.ml
$ cat notebooks/introduction.ml
let x = List.map (fun x -> x * 2) [1; 3; 5; 7; 9]
#thread ;;
#require "jupyter.notebook" ;;
JupyterNotebook.display "text/html" "<b>Hello, World!</b>"
let ic = open_in_bin "datasets/lenna.png" in
let n = in_channel_length ic in
let data = really_input_string ic n in
close_in ic ;
JupyterNotebook.display ~base64:true "image/png" data
#require "jupyter.archimedes"
let vp = A.init ~w:560. ~h:260. ["jupyter"] in
A.Axes.box vp ;
A.set_color vp A.Color.red ;
A.fx vp sin 0.0 10.0 ;
A.close vp
let rec walk acc p i =
if i = 0 then List.rev acc else begin
let q = if Random.bool () then succ p else pred p in
walk (q :: acc) q (pred i)
end in
let vp = A.init ~w:560. ~h:260. ["jupyter"] in
A.Axes.box vp ;
A.set_color vp A.Color.red ;
A.List.y vp ~style:`Lines (List.map float @@ walk [] 0 1000) ; (* Plot a random walk of 1000 points. *)
A.close vp |
Actually, because you handled correctly the metadata tags, the The obvious advantage of using a |
OK. I think the custom exporter can be released in 1-2 weeks maybe. |
|
I have started to do it, can you let me try please? |
Thank you! Of course. |
Should be OK 🚀 ! See https://github.com/Naereen/Jupyter-NBConvert-OCaml See this example to see the difference between I think I will let you take it from where... I don't know how you could also for a |
And for less trivial examples of outputs, I just re-generated all the .ml files from my OCaml notebooks present in this directory. |
The code ( |
@Naereen Great! I tried your exporter and got a file including code with markdown comments. However the output
is exported to the following (* In[1]: *)
1 + 3
(* In[2] *)
let x = 42 but the above should be (* In[1]: *)
1 + 3;;
(* In[2] *)
let x = 42;; The simplest solution is naively adding |
The current installation step seems simple enough. I leave to you whether it is published on PyPI since it is your product. I will add the link to your repository in README. |
OK. But it's already weird to not use |
I can change the filter to check if there is a |
I see. You are right. ocaml jupyter kernel shouldn't execute top-level phrases without |
Yes but I can tweak the filter and force to add a |
Oh, I just saw that the GUI allows to save the notebook to a OCaml file, but it uses 1 + 3
let x = 42 and then the new (*
This OCaml script was exported from a Jupyter notebook
using an open-source software (under the MIT License) written by @Naereen
from https://github.com/Naereen/Jupyter-Notebook-OCaml
This software is still in development, please notify me of a bug at
https://github.com/Naereen/Jupyter-Notebook-OCaml/issues/new if you find one
*)
(* # Title Markdown cell! *)
(* In[1]: *)
1 + 3;;
(* In[2]: *)
let x = 42;; |
Let's publish it on Pypi like this, I let you add the links on your README, and we will see, if anyone complains about this filter adding ';;' (when needed), I will remove it... Or add options to keep or remove it. |
Thank you! |
(Naereen/Jupyter-NBConvert-OCaml#1 as soon as I can) |
To be honest, I cannot be sure that I should reject cells without |
No I don't see the point in rejecting cells without ' |
OK. Thanks. |
See this issue on iocaml for reference.
The text was updated successfully, but these errors were encountered: