def enable(scope=None): """Enable nbdime git merge driver""" cmd = ['git', 'config'] if scope: cmd.append('--%s' % scope) check_call(cmd + [ 'merge.jupyternotebook.driver', 'git-nbmergedriver merge %O %A %B %L %P' ]) check_call(cmd + ['merge.jupyternotebook.name', 'jupyter notebook merge driver']) gitattributes = locate_gitattributes(scope) if gitattributes is None: assert scope is None, "No gitattributes found for scope: %s" % scope print("No .git directory in %s, skipping git attributes" % os.curdir, file=sys.stderr) return if os.path.exists(gitattributes): with io.open(gitattributes, encoding="utf8") as f: if 'merge=jupyternotebook' in f.read(): # already written, nothing to do return else: ensure_dir_exists(os.path.dirname(gitattributes)) with io.open(gitattributes, 'a', encoding="utf8") as f: f.write(u'\n*.ipynb\tmerge=jupyternotebook\n')
def enable(scope=None): """Enable nbdime git merge driver""" cmd = ["git", "config"] if scope: cmd.append("--%s" % scope) check_call( cmd + ["merge.packson.driver", "git-pjmergedriver merge %O %A %B %L %P"]) check_call(cmd + ["merge.packson.name", "npm package.json merge driver"]) gitattributes = locate_gitattributes(scope) if gitattributes is None: assert scope is None, "No gitattributes found for scope: %s" % scope print( "No .git directory in %s, skipping git attributes" % os.curdir, file=sys.stderr, ) return if os.path.exists(gitattributes): with io.open(gitattributes, encoding="utf8") as f: if "merge=packson" in f.read(): # already written, nothing to do return else: ensure_dir_exists(os.path.dirname(gitattributes)) with io.open(gitattributes, "a", encoding="utf8") as f: f.write(u"\npackage.json\tmerge=packson\n")
def enable(scope=None): """Enable nbdime git diff driver""" cmd = ['git', 'config'] if scope: cmd.append('--%s' % scope) try: check_call(cmd + ['diff.jupyternotebook.command', 'git-nbdiffdriver diff']) except CalledProcessError as e: return # Not in git repository gitattributes = locate_gitattributes(scope) if gitattributes is None: assert scope is None, "No gitattributes found for scope: %s" % scope print("No .git directory in %s, skipping git attributes" % os.curdir, file=sys.stderr) return if os.path.exists(gitattributes): with io.open(gitattributes, encoding="utf8") as f: if 'diff=jupyternotebook' in f.read(): # already written, nothing to do return else: ensure_dir_exists(os.path.dirname(gitattributes)) with io.open(gitattributes, 'a', encoding="utf8") as f: f.write(u'\n*.ipynb\tdiff=jupyternotebook\n')
def enable(scope=None): """Enable nbdime git diff driver""" cmd = ['git', 'config'] if scope: cmd.append('--%s' % scope) try: check_call(cmd + ['diff.jupyternotebook.command', 'git-nbdiffdriver diff']) except CalledProcessError: return # Not in git repository gitattributes = locate_gitattributes(scope) if gitattributes is None: assert scope is None, "No gitattributes found for scope: %s" % scope print("No .git directory in %s, skipping git attributes" % os.curdir, file=sys.stderr) return if os.path.exists(gitattributes): with io.open(gitattributes, encoding="utf8") as f: if 'diff=jupyternotebook' in f.read(): # already written, nothing to do return else: ensure_dir_exists(os.path.dirname(gitattributes)) with io.open(gitattributes, 'a', encoding="utf8") as f: f.write(u'\n*.ipynb\tdiff=jupyternotebook\n')
def enable(scope=None): """Enable nbdime git merge driver""" cmd = ['git', 'config'] if scope: cmd.append('--%s' % scope) check_call(cmd + ['merge.jupyternotebook.driver', 'git-nbmergedriver merge %O %A %B %L %P']) check_call(cmd + ['merge.jupyternotebook.name', 'jupyter notebook merge driver']) gitattributes = locate_gitattributes(scope) if gitattributes is None: assert scope is None, "No gitattributes found for scope: %s" % scope print("No .git directory in %s, skipping git attributes" % os.curdir, file=sys.stderr) return if os.path.exists(gitattributes): with io.open(gitattributes, encoding="utf8") as f: if 'merge=jupyternotebook' in f.read(): # already written, nothing to do return else: ensure_dir_exists(os.path.dirname(gitattributes)) with io.open(gitattributes, 'a', encoding="utf8") as f: f.write(u'\n*.ipynb\tmerge=jupyternotebook\n')
def test_interrogate_filter_blank(git_repo): gitattr = locate_gitattributes() with io.open(gitattr, 'a', encoding="utf8") as f: f.write(u'\n*.ipynb\tfilter=\n') attr = interrogate_filter(pjoin(git_repo, 'foo--1.ipynb')) assert attr is None
def test_interrogate_filter_unset(git_repo): gitattr = locate_gitattributes() with io.open(gitattr, 'a', encoding="utf8") as f: f.write(u'\n*.ipynb\t-filter\n') attr = interrogate_filter(pjoin(git_repo, 'diff.ipynb')) assert attr is None
def _config_filter_driver(name, capsys): path = os.path.abspath(pjoin(os.path.dirname(__file__), 'filters', '%s.py' % name)) base_cmd = '%s %s' % (sys.executable, path) gitattr = locate_gitattributes() with io.open(gitattr, 'a', encoding="utf8") as f: f.write(u'\n*.ipynb\tfilter=%s\n' % (name,)) with capsys.disabled(): call('git config --local --add filter.%s.clean "%s clean"' % (name, base_cmd)) call('git config --local --add filter.%s.smudge "%s smudge"' % (name, base_cmd))
def test_apply_filter_valid_filter(git_repo): path = pjoin(git_repo, 'diff.ipynb') gitattr = locate_gitattributes() with io.open(gitattr, 'a', encoding="utf8") as f: f.write(u'\n*.ipynb\tfilter=myfilter\n') call('git config --local --add filter.myfilter.clean "cat"') f = apply_possible_filter(path) assert isinstance(f, StringIO) # Read validates notebook: nbformat.validate(nbformat.read(f, as_version=4))
def test_apply_filter_valid_filter(git_repo): try: call('cat --help') filter_cmd = 'cat' except (CalledProcessError, FileNotFoundError): filter_cmd = 'findstr x*' path = pjoin(git_repo, 'diff.ipynb') gitattr = locate_gitattributes() with io.open(gitattr, 'a', encoding="utf8") as f: f.write(u'\n*.ipynb\tfilter=myfilter\n') call('git config --local --add filter.myfilter.clean "%s"' % filter_cmd) f = apply_possible_filter(path) assert isinstance(f, StringIO) # Read validates notebook: nbformat.validate(nbformat.read(f, as_version=4))
def test_locate_gitattributes_local(git_repo): gitattr = locate_gitattributes(scope=None) assert gitattr is not None
def test_locate_gitattributes_system(): gitattr = locate_gitattributes(scope='system') assert gitattr is not None
def test_locate_gitattributes_global(): gitattr = locate_gitattributes(scope='global') assert gitattr is not None
def test_locate_gitattributes_system(needs_git): gitattr = locate_gitattributes(scope='system') assert gitattr is not None
def test_apply_filter_invalid_filter(git_repo): path = pjoin(git_repo, 'diff.ipynb') gitattr = locate_gitattributes() with io.open(gitattr, 'a', encoding="utf8") as f: f.write(u'\n*.ipynb\tfilter=myfilter\n') assert apply_possible_filter(path) == path
def test_locate_gitattributes_global(needs_git): gitattr = locate_gitattributes(scope='global') assert gitattr is not None