-
Notifications
You must be signed in to change notification settings - Fork 10
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
firstDraft #1
firstDraft #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked to Ashutosh today in person. Summary of the discussion:
- Add
%%html
cells with the converted HTML from the spec file so we can compare our generated HTML. - Split the notebook into a series of smaller ones, each with maybe 100 cells (the full one is quite large).
- Add a section header for each example such as "Example 1" as a Markdown cell.
Oooh, I'm liking this spec file and script. Great approach for testing our own compliance. |
Hey quick question, how can I run the code cell using python command? Like I know in the notebook you can do shift+enter, but if I don't want to manually do that, and just run the code cells using my script & get the output of the code cells in the notebook, what is the command / syntax for that? |
@ashutoshbondre Where are you running it from? If you can use And if you want to do on individual cells directly, I'd recommend looking at the internals of the Execute preprocessor, specifically the |
Btw, just looked and was there a reason you used a python2 kernel? If not please switch to using python3? I anticipate that we'll eventually run into unicode bugs in this spec code otherwise. |
No reason. I will change that, and thanks for the help.
On Jun 14, 2017 3:17 PM, "M Pacer" ***@***.***> wrote:
Btw, just looked and was there a reason you used a python2 kernel? If not
please switch to using python3? I anticipate that we'll eventually run into
unicode bugs in this spec code otherwise.
…
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Looking at what you have, what I'd do is something like: # ⋮ your imports
from nbconvert import ExecutePreprocessor
kernel_name = 'python3' # set it programmatically so that you only need to change it in one place
display_name = 'Python 3'
output_path = '/Users/ashu/github/ans.ipynb' # probably want to use a relative path?
timeout_amount = 60 # none of these should take too long
metadata = {'kernelspec': {
'name': your_kernel_name
'display_name': display_name
}} # this might need to be populated with more valid metadata, but I'm not sure which metadata you'll actually need.
format_version = 4.3
# ⋮ this is where your spec reading and cell writing would happen
executor = ExecutePreprocessor(timeout=60, kernel_name=your_kernel_name)
executor.preprocess(nb, metadata)
nbformat.write(nb,"/Users/ashu/github/ans.ipynb", format_version) Hope that helps! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to find all of the little things that will make this more portable and configurable in the long run. Some of my example code would address these issues (at least by making them top level variables instead of hard-coded values).
script.py
Outdated
for i in range(len(data)): | ||
cells +=[new_markdown_cell(data[i]["markdown"])] | ||
nb=new_notebook(cells=cells,metadata={'kernelspec': { | ||
'name': 'python2', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably shouldn't hard code this.
script.py
Outdated
cells +=[new_markdown_cell(data[i]["markdown"])] | ||
nb=new_notebook(cells=cells,metadata={'kernelspec': { | ||
'name': 'python2', | ||
'display_name': 'Python 2' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't hard code this as you want it to be easily changeable.
script.py
Outdated
}}) | ||
|
||
|
||
nbformat.write(nb,"/Users/ashu/github/ans.ipynb",4.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably don't want to hard code the path or the version number as it's reasonable to expect that we want to do this on any number of potential versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably want the path to be relative, because this makes it so you're the only one who can easily run this without directly editing the file.
script.py
Outdated
import nbformat | ||
from pprint import pprint | ||
from nbformat.v4 import new_code_cell, new_markdown_cell, new_notebook | ||
with open('spec.json') as data_file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should either use absolute paths or relative paths consistently (here you're implicitly using a relative path, later you use an absolute path).
@mpacer Thanks for the review, did most of the changes. Also ExecutePreprocessor did what I wanted. One reason I used python 2 kernel was because that was the default one I had, I am having problems with executing the code in python3. Currently I am working on Python 2.7.13. Can you tell me, what can I do here, to switch to the right environment. I am pretty sure, I am just missing some minute detail. |
You would need to run `pip install nbformat` to install that package in the
2.7 environment, making sure that the right version of pip/python is in
your path. Python packages have to be installed separately in each python
version's site-packages dir.
…On Wed, Jun 14, 2017 at 5:02 PM, Ashutosh Bondre ***@***.***> wrote:
@mpacer <https://github.com/mpacer> Thanks for the review, did most of
the changes. Also ExecutePreprocessor did what I wanted.
One reason I used python 2 kernel was because that was the default one I
had, I am having problems with executing the code in python3.
I set up a different environment in python 3 using "conda create" command,
but when I execute the code there,it doesn't even recognize nbformat. Says
"no module named nbformat" .
Currently I am working on Python 2.7.13. Can you tell me, what can I do
here, to switch to the right environment. I am pretty sure, I am just
missing some minute detail.
Thanks
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABr0BaYzdmzIN1TUVhPkl-AaKy_T7pgks5sEHSTgaJpZM4N39u1>
.
--
Brian E. Granger
Associate Professor of Physics and Data Science
Cal Poly State University, San Luis Obispo
@ellisonbg on Twitter and GitHub
bgranger@calpoly.edu and ellisonbg@gmail.com
|
You need to switch into that environment and specifically install nbformat,
notebook, lab, &c. to that environment. To make it easy you could use conda
install but you should also be able to use pip if you want. If you go that
route & run into trouble let me know.
Then, you need to install the kernel relative to that environment, which
you can install by following instructions here:
http://ipython.readthedocs.io/en/stable/install/kernel_install.html
If you want access to that kernel in all your environments use
`--sys-prefix` when installing.
Then it should work.
…On Wed, Jun 14, 2017 at 17:02 Ashutosh Bondre ***@***.***> wrote:
@mpacer <https://github.com/mpacer> Thanks for the review, did most of
the changes. Also ExecutePreprocessor did what I wanted.
One reason I used python 2 kernel was because that was the default one I
had, I am having problems with executing the code in python3.
I set up a different environment in python 3 using "conda create" command,
but when I execute the code there,it doesn't even recognize nbformat. Says
"no module named nbformat" .
Currently I am working on Python 2.7.13. Can you tell me, what can I do
here, to switch to the right environment. I am pretty sure, I am just
missing some minute detail.
Thanks
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACXg6MmWwnuMzvQnzG5b8tmyThTT5Gsdks5sEHSTgaJpZM4N39u1>
.
|
The script creates as many notebook as possible, each with 100 entries.
Ready for review:
Thanks, |
All made with python3 kernel. |
I'd like to go ahead and assume that the requested changes were made and this is ready to go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sevdiğim
firstDraft.ipynb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
H
firstDraft.ipynb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aşk
Added 3 files: