Skip to content
This repository has been archived by the owner on May 9, 2022. It is now read-only.

Commit

Permalink
Show modal [version 0.2.0]
Browse files Browse the repository at this point in the history
Also changed the handlers to return only a success message.
  • Loading branch information
fferegrino committed Jul 23, 2018
1 parent 4ce3b1a commit 73e2f39
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
[![CircleCI](https://circleci.com/gh/fferegrino/jupygit.svg?style=svg)](https://circleci.com/gh/fferegrino/jupygit) [![PyPI](https://img.shields.io/pypi/v/jupygit.svg)](https://pypi.org/project/jupygit/)

Integrating Jupyter Notebooks to a git workflow.

#### First of all: is this a *hack*?
**yes, yes it is**.

### Installation.
(I highly recommend installing this into a conda environment)
(I highly recommend installing this into a conda environment) To install the extension and enable it just run the following commands:

To install the extension and enable it just run the following commands:
```
pip install jupygit
jupyter serverextension enable --py jupygit --sys-prefix
Expand All @@ -25,12 +21,13 @@ I've been working with Jupyter Notebooks for a while, and I always felt somethin
### How? (and usage)
Let's say you are working on a file called `Awesome.ipynb`. What this extension will do once you press shiny new **git** button on your Notebook is:

1. Rename your current file to `Awesome-jupygit___.ipynb` using Jupyter's API so that your kernel stays alive and you do not lose any work, we'll call this the *"dirty"* file.
0. Shows a nice modal with an encouraging message.
1. Renames your current file to `Awesome-jupygit___.ipynb` using Jupyter's API so that your kernel stays alive and you do not lose any work, we'll call this the *"dirty"* file.
2. Adds the pattern `*-jupygit___.ipynb` to your .gitignore file, so that your *"dirty"* file does not show up as a new file in your git repository.
3. Creates a copy of `Awesome-jupygit___.ipynb` but with the original name `Awesome.ipynb`, this copy is clean, no outputs and no `execution_counts`, we'll call this the *"clean"* file.
4. Now is your turn to commit `Awesome.ipynb`, the *"clean"* file to source control!

Are you done pushing things to Git? Now press the **git** button again and the extension will:
Are you done pushing things to Git? Now close the dialog and this will happen:

1. Delete the file `Awesome.ipynb` (do not worry! your kernel and work is safe in the *"dirty"* file).
2. Rename `Awesome-jupygit___.ipynb` to `Awesome.ipynb` so that you can resume your work where you left it before being a good human and using source control.
6 changes: 2 additions & 4 deletions jupygit/GitHandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def post(self):
clean_path = dirty_path[:-len(self.file_suffix)] + ".ipynb"
os.remove(clean_path)

self.write({'status':200,'content':'Hola'})
self.flush()
self.set_status(200)


class GitCleanHandler(IPythonHandler):
Expand All @@ -39,8 +38,7 @@ def post(self):
with open(clean_path, "w") as w:
json.dump(dirty, w, indent=1)

self.write({'status':200,'content':'Hola'})
self.flush()
self.set_status(200)

def clean_nb(self, dirty, outputs_to_remove=[]):
cells = dirty.get('cells', [])
Expand Down
23 changes: 18 additions & 5 deletions jupygit/static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,23 @@ define([
url: clean_url,
data: data,
success: function(d) {
alert("Now you can go ahead and commit your notebook! do not forget to press the button again when you are done")
$("#jupygit-button span").text("Keep working");
var d = dialog.modal(
{
backdrop:'static',
keyboard:false,
show:true,
title: Jupyter.original_name + ' is clean and ready to be committed',
body:'You can now go ahead and commit your notebook using your favourite git client. ' +
'Close this dialog after you are done to keep working on your notebook.',
buttons: {
'Close': {
class:'btn-primary btn-large'
}
}
});
d.on('hidden.bs.modal', function () {
make_request();
})
}
});
});
Expand All @@ -55,8 +70,6 @@ define([
success: function(d) {
Jupyter.notebook.rename(Jupyter.original_name).then(function (){
Jupyter.original_name = "";
alert("You can now keep working");
$("#jupygit-button span").text("Prepare notebook");
});
}
});
Expand Down Expand Up @@ -84,7 +97,7 @@ define([

Jupyter.toolbar.add_buttons_group([{
id: 'jupygit-button',
label: 'Prepare notebook',
label: 'Prepare',
icon: 'fa-git',
help: 'Clean and prepare your notebook to be commited to Git',
callback: make_request
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
long_description = fh.read()

# Package version
VERSION = "0.1.2"
VERSION = "0.2.0"

class VerifyVersionCommand(install):
"""Custom command to verify that the git tag matches our version"""
Expand All @@ -29,7 +29,7 @@ def run(self):
author="Antonio Feregrino",
author_email="[email protected]",
version=VERSION,
description="Prepare your Notebooks to be pushed to GitHub",
description="Prepare your Notebooks to be pushed to Git",
long_description=long_description,
long_description_content_type="text/markdown",
include_package_data=True,
Expand Down

0 comments on commit 73e2f39

Please sign in to comment.