From 73e2f3943d7ea5fdedfb7309758ff3977b4e6b67 Mon Sep 17 00:00:00 2001 From: Antonio Feregrino Date: Mon, 23 Jul 2018 21:26:07 +0100 Subject: [PATCH] Show modal [version 0.2.0] Also changed the handlers to return only a success message. --- README.md | 11 ++++------- jupygit/GitHandlers.py | 6 ++---- jupygit/static/index.js | 23 ++++++++++++++++++----- setup.py | 4 ++-- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 429488a..92dcc1e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. \ No newline at end of file diff --git a/jupygit/GitHandlers.py b/jupygit/GitHandlers.py index eb981ec..70c8ab4 100644 --- a/jupygit/GitHandlers.py +++ b/jupygit/GitHandlers.py @@ -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): @@ -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', []) diff --git a/jupygit/static/index.js b/jupygit/static/index.js index 4e7ae70..3baf528 100644 --- a/jupygit/static/index.js +++ b/jupygit/static/index.js @@ -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(); + }) } }); }); @@ -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"); }); } }); @@ -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 diff --git a/setup.py b/setup.py index 3a193af..6cb40f6 100644 --- a/setup.py +++ b/setup.py @@ -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""" @@ -29,7 +29,7 @@ def run(self): author="Antonio Feregrino", author_email="antonio.feregrino@gmail.com", 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,