From 22a5f66d6f2aecd720e483a85c1b06f3672abd5b Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Tue, 10 Apr 2018 00:03:22 +0200 Subject: [PATCH 01/12] ability to launch into jupyterlab (pre-test) --- README.md | 4 +++- nbgitpuller/handlers.py | 21 +++++++++++++++++---- nbgitpuller/static/index.js | 14 ++++---------- nbgitpuller/templates/status.html | 6 +++--- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 64b2a897..db8a35e5 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ You should *not* use this when: You can construct a working nbgitpuller URL like this: ``` -myjupyterhub.org/hub/user-redirect/git-pull?repo=&branch=&subPath= +myjupyterhub.org/hub/user-redirect/git-pull?repo=&branch=&subPath=&app= ``` - **repo** is the URL of the git repository you want to clone. This paramter is required. @@ -72,6 +72,8 @@ myjupyterhub.org/hub/user-redirect/git-pull?repo=&branch= Date: Tue, 10 Apr 2018 00:25:05 +0200 Subject: [PATCH 02/12] ability to launch into jupyterlab (post-test) --- nbgitpuller/handlers.py | 2 +- nbgitpuller/static/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nbgitpuller/handlers.py b/nbgitpuller/handlers.py index 1482203d..49d493d0 100644 --- a/nbgitpuller/handlers.py +++ b/nbgitpuller/handlers.py @@ -144,7 +144,7 @@ def get(self): path = os.path.join(repo_dir, subPath) if app == 'lab': path = 'lab/tree/' + path - else if path.endsWith('.ipynb'): + elif path.endswith('.ipynb'): path = 'notebooks/' + path else: path = 'tree/' + path diff --git a/nbgitpuller/static/index.js b/nbgitpuller/static/index.js index e6fcfda4..b391f9fd 100644 --- a/nbgitpuller/static/index.js +++ b/nbgitpuller/static/index.js @@ -153,7 +153,7 @@ require([ utils.get_body_data('baseUrl'), utils.get_body_data('repo'), utils.get_body_data('branch'), - utils.get_body_data('path'), + utils.get_body_data('path') ); var gsv = new GitSyncView( From be405c89a75be0f22c27bfba69bcf7e5ac536507 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Tue, 10 Apr 2018 02:13:17 +0200 Subject: [PATCH 03/12] urlPath now in readme --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index db8a35e5..9ba5c1a7 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,12 @@ myjupyterhub.org/hub/user-redirect/git-pull?repo=&branch= Date: Sat, 14 Apr 2018 14:06:51 +0200 Subject: [PATCH 04/12] bumped version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 562adb5d..fc8544ee 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='nbgitpuller', - version='0.3', + version='0.4', url='https://github.com/data-8/nbgitpuller', license='BSD', author='Peter Veerman', From b774acf2b6e279d63caf626e454216d60b9d76b7 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Sun, 15 Apr 2018 02:32:58 +0200 Subject: [PATCH 05/12] .js invalidation using version querystring --- nbgitpuller/__init__.py | 4 ++-- nbgitpuller/handlers.py | 3 ++- nbgitpuller/templates/status.html | 2 +- nbgitpuller/version.py | 2 ++ setup.py | 5 ++++- 5 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 nbgitpuller/version.py diff --git a/nbgitpuller/__init__.py b/nbgitpuller/__init__.py index 412485f7..1d17328e 100644 --- a/nbgitpuller/__init__.py +++ b/nbgitpuller/__init__.py @@ -1,9 +1,9 @@ +from .version import __version__ from .handlers import SyncHandler, UIHandler, LegacyInteractRedirectHandler, LegacyGitSyncRedirectHandler +from .pull import GitPuller from notebook.utils import url_path_join from tornado.web import StaticFileHandler import os -from .pull import GitPuller - def _jupyter_server_extension_paths(): return [{ diff --git a/nbgitpuller/handlers.py b/nbgitpuller/handlers.py index 49d493d0..3013de3a 100644 --- a/nbgitpuller/handlers.py +++ b/nbgitpuller/handlers.py @@ -11,6 +11,7 @@ import jinja2 from .pull import GitPuller +from .version import __version__ class SyncHandler(IPythonHandler): def __init__(self, *args, **kwargs): @@ -152,7 +153,7 @@ def get(self): self.write( self.render_template( 'status.html', - repo=repo, branch=branch, path=path + repo=repo, branch=branch, path=path, version=__version__ )) self.flush() diff --git a/nbgitpuller/templates/status.html b/nbgitpuller/templates/status.html index 16d8e7c7..9314b43e 100644 --- a/nbgitpuller/templates/status.html +++ b/nbgitpuller/templates/status.html @@ -32,7 +32,7 @@ {% block script %} {{super()}} - {% endblock %} diff --git a/nbgitpuller/version.py b/nbgitpuller/version.py new file mode 100644 index 00000000..289a116a --- /dev/null +++ b/nbgitpuller/version.py @@ -0,0 +1,2 @@ +""""The nbgitpuller package SemVer version.""" +__version__ = '0.4.0' diff --git a/setup.py b/setup.py index fc8544ee..7ef5fde2 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,11 @@ +"""PyPI packaging settings""" + from setuptools import find_packages, setup +from nbgitpuller import __version__ setup( name='nbgitpuller', - version='0.4', + version=__version__, url='https://github.com/data-8/nbgitpuller', license='BSD', author='Peter Veerman', From d0a7344932c8f7ea2be236ea008ec4e7d2a8833b Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Sun, 15 Apr 2018 03:15:52 +0200 Subject: [PATCH 06/12] pleasing of flake8 --- tests/test_gitpuller.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/test_gitpuller.py b/tests/test_gitpuller.py index d8027dad..b825559d 100644 --- a/tests/test_gitpuller.py +++ b/tests/test_gitpuller.py @@ -3,11 +3,9 @@ import subprocess as sp import glob import time -import random -import string -import pytest from nbgitpuller import GitPuller + class Remote: def __init__(self, path='remote'): self.path = path @@ -27,6 +25,7 @@ def git(self, *args): stderr=sp.STDOUT ).decode().strip() + class Pusher: def __init__(self, remote, path='pusher'): self.path = path @@ -62,6 +61,7 @@ def push_file(self, path, content): self.git('commit', '-am', 'Ignore the message') self.git('push', 'origin', 'master') + class Puller: def __init__(self, remote, path='puller'): self.path = path @@ -98,6 +98,7 @@ def read_file(self, path): # 5. Make change in puller to file, make change in pusher to same part of file, run puller # 6. Make untracked file in puller, add file with same name to pusher, run puller + def test_initialize(): with Remote() as remote, Pusher(remote) as pusher: pusher.push_file('README.md', '1') @@ -108,6 +109,7 @@ def test_initialize(): assert puller.git('name-rev', '--name-only', 'HEAD') == 'master' assert puller.git('rev-parse', 'HEAD') == pusher.git('rev-parse', 'HEAD') + def test_simple_push_pull(): """ Test the 'happy path' push/pull interaction @@ -143,7 +145,7 @@ def test_simple_push_pull(): assert puller.read_file('another-file') == pusher.read_file('another-file') == '3' pusher.git('rm', 'another-file') - pusher.git('commit', '-m','Removing File') + pusher.git('commit', '-m', 'Removing File') pusher.git('push', 'origin', 'master') for l in puller.gp.pull(): @@ -152,6 +154,7 @@ def test_simple_push_pull(): assert puller.git('rev-parse', 'HEAD') == pusher.git('rev-parse', 'HEAD') assert not os.path.exists(os.path.join(puller.path, 'another-file')) + def test_git_lock(): """ Test the 'happy path', but with stale/unstale git locks @@ -168,11 +171,10 @@ def test_git_lock(): for l in puller.gp.pull(): print(puller.path + l) assert False - except: + except Exception: # This should raise an exception, since our .git/lock is new assert True - new_time = time.time() - 700 os.utime(os.path.join(puller.path, '.git', 'index.lock'), (new_time, new_time)) @@ -217,6 +219,7 @@ def test_merging_simple(): assert puller.read_file('README.md') == '2' + def test_untracked_puller(): """ Test that untracked files in puller are preserved when pulling @@ -236,6 +239,7 @@ def test_untracked_puller(): renamed_file = glob.glob(os.path.join(puller.path, 'another-file_*'))[0] assert puller.read_file(os.path.basename(renamed_file)) == '3' + def test_reset_file(): """ Test that deleting files locally & pulling restores pristine copy From 7bc039af9135b707a425b2c8daad50c582c2af5e Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Sun, 15 Apr 2018 03:17:49 +0200 Subject: [PATCH 07/12] Solves requirement troubles for tox I'm not confident at all about this commit ... --- tox.ini | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tox.ini b/tox.ini index 719db02d..7521ebce 100644 --- a/tox.ini +++ b/tox.ini @@ -8,11 +8,15 @@ deps= six pytest pytest-cov + tornado + notebook [testenv:flake8] basepython = python3.5 deps = flake8 six + tornado + notebook commands = flake8 gitautosync tests --max-line-length=150 From bcc94a1b0d7bf6a5d2a0b77ee978ab8210a08213 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Sun, 15 Apr 2018 03:21:51 +0200 Subject: [PATCH 08/12] tornado added to 'install_requires' --- setup.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 7ef5fde2..822d2980 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,8 @@ -"""PyPI packaging settings""" - from setuptools import find_packages, setup -from nbgitpuller import __version__ setup( name='nbgitpuller', - version=__version__, + version='0.3', url='https://github.com/data-8/nbgitpuller', license='BSD', author='Peter Veerman', @@ -14,7 +11,7 @@ packages=find_packages(), include_package_data=True, platforms='any', - install_requires=['notebook'], + install_requires=['notebook', 'tornado'], entry_points={ 'console_scripts': [ 'gitpuller = nbgitpuller.pull:main', From 1081ae0ec06028a57de317846dfc5f64e4f0d55b Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Sun, 15 Apr 2018 04:01:54 +0200 Subject: [PATCH 09/12] version bump --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 822d2980..4bfce967 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='nbgitpuller', - version='0.3', + version='0.4.0', url='https://github.com/data-8/nbgitpuller', license='BSD', author='Peter Veerman', From 529acc47c9d5b8e0810e9032a80a2a27d1ff861d Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Mon, 23 Apr 2018 23:07:00 +0200 Subject: [PATCH 10/12] DRY __version__ --- nbgitpuller/version.py | 2 +- setup.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/nbgitpuller/version.py b/nbgitpuller/version.py index 289a116a..b0847d35 100644 --- a/nbgitpuller/version.py +++ b/nbgitpuller/version.py @@ -1,2 +1,2 @@ -""""The nbgitpuller package SemVer version.""" +""""The nbgitpuller PyPI package SemVer version.""" __version__ = '0.4.0' diff --git a/setup.py b/setup.py index 4bfce967..361aaa08 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,16 @@ from setuptools import find_packages, setup +from distutils.util import convert_path + +# Imports __version__, reference: https://stackoverflow.com/a/24517154/2220152 +ns = {} +ver_path = convert_path('nbgitpuller/version.py') +with open(ver_path) as ver_file: + exec(ver_file.read(), ns) +__version__ = ns['__version__'] setup( name='nbgitpuller', - version='0.4.0', + version=__version__, url='https://github.com/data-8/nbgitpuller', license='BSD', author='Peter Veerman', From 7e9a6ace14c34027cd480bd5d55343320b444dc7 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Mon, 23 Apr 2018 23:24:58 +0200 Subject: [PATCH 11/12] test against py36 instead of py35 --- .travis.yml | 2 +- tox.ini | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 98d1b028..beaa2d02 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ sudo: false language: python python: - - "3.5" + - "3.6" install: pip install tox-travis script: tox diff --git a/tox.ini b/tox.ini index 7521ebce..70ec3d73 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=py35, flake8 +envlist=py36, flake8 [testenv] commands= @@ -12,7 +12,7 @@ deps= notebook [testenv:flake8] -basepython = python3.5 +basepython = python3.6 deps = flake8 six From b9f439889e4567edbcffb992014c6e8cb8de9b5e Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Mon, 30 Apr 2018 21:01:29 +0200 Subject: [PATCH 12/12] Reduced case sensitivity Now urlPath and subPath with all lower case letters is allowed. I wanted to allow urlpath especially as mybinder.org also has such querystring, but then in lowercase only. Also any `.ipynb` file extension, no matter character case will be treated as a jupyter notebook. --- nbgitpuller/handlers.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nbgitpuller/handlers.py b/nbgitpuller/handlers.py index 3013de3a..d5d4c74f 100644 --- a/nbgitpuller/handlers.py +++ b/nbgitpuller/handlers.py @@ -134,8 +134,10 @@ def get(self): repo = self.get_argument('repo') branch = self.get_argument('branch', 'master') - urlPath = self.get_argument('urlPath', None) - subPath = self.get_argument('subPath', '.') + urlPath = self.get_argument('urlpath', None) or \ + self.get_argument('urlPath', None) + subPath = self.get_argument('subpath', None) or \ + self.get_argument('subPath', '.') app = self.get_argument('app', app_env) if urlPath: @@ -143,9 +145,9 @@ def get(self): else: repo_dir = repo.split('/')[-1] path = os.path.join(repo_dir, subPath) - if app == 'lab': + if app.lower() == 'lab': path = 'lab/tree/' + path - elif path.endswith('.ipynb'): + elif path.lower().endswith('.ipynb'): path = 'notebooks/' + path else: path = 'tree/' + path