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 templating for Jupyter notebooks. #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ dependencies:
test:
override:
- docker run $AWS_ECR_ENDPOINT.dkr.ecr.us-east-1.amazonaws.com/cognoma-ml-workers:$CIRCLE_SHA1 python test_ml_task_runner.py
- docker run $AWS_ECR_ENDPOINT.dkr.ecr.us-east-1.amazonaws.com/cognoma-ml-workers:$CIRCLE_SHA1 pytest nb_util

deployment:
production:
branch: master
commands:
- chmod +x ecr_push.sh ecs_deploy.sh
- ./ecr_push.sh
- ./ecs_deploy.sh --timeout 180 --cluster $AWS_CLUSTER_NAME --service-name $AWS_SERVICE_NAME --image $AWS_ECR_ENDPOINT.dkr.ecr.us-east-1.amazonaws.com/cognoma-ml-workers:$CIRCLE_SHA1
- ./ecs_deploy.sh --timeout 180 --cluster $AWS_CLUSTER_NAME --service-name $AWS_SERVICE_NAME --image $AWS_ECR_ENDPOINT.dkr.ecr.us-east-1.amazonaws.com/cognoma-ml-workers:$CIRCLE_SHA1
19 changes: 19 additions & 0 deletions nb_util/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# nbcopy
Tool for making and filling Jupyter notebook templates.

## Usage
import jupyter_template as jt

Given a Jupyter notebook, we can create a template by replacing specific strings with keywords.

fname = 'examples/2.mutation-classifier.ipynb'
new_keywords = {'7157': 'id', 'TP53': 'mutation'}
template = jt.create_template(fname, new_keywords)

Once we have a template, filling in the keywords is straightforward

keywords = {'id': 'foo', 'mutation': 'bar'}
nb = template.fill_template(keywords)
with open('examples/output.ipynb', 'w') as f:
f.writelines(nb)
f.close()
1 change: 1 addition & 0 deletions nb_util/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""nb_util package."""
Loading