-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change cli tools to not use the jupyter apps framework.
- Loading branch information
Martin Sandve Alnæs
committed
Dec 14, 2015
1 parent
0d998a4
commit 00b334d
Showing
8 changed files
with
109 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,55 @@ | ||
"""Utilities for mergeing notebooks""" | ||
"""Utilities for merging notebooks""" | ||
|
||
# Copyright (c) IPython Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
from __future__ import print_function | ||
|
||
import os | ||
import sys | ||
import nbformat | ||
import json | ||
from jupyter_core.application import JupyterApp, base_flags | ||
from ._version import __version__ | ||
from .merging import merge_notebooks | ||
|
||
nbmerge_flags = { | ||
} | ||
nbmerge_flags.update(base_flags) | ||
|
||
class NBMergeApp(JupyterApp): | ||
version = __version__ | ||
_usage = """\ | ||
Merge two Jupyter notebooks "local" and "remote" with a common ancestor "base". | ||
description="""Merge Jupyter notebooks. | ||
""" | ||
This is nbmerge from nbdime version {}. | ||
examples = """ | ||
jupyter nbmerge base.ipynb local.ipynb remote.ipynb merged.ipynb | ||
""" | ||
Example usage: | ||
flags = nbmerge_flags | ||
jupyter nbmerge base.ipynb local.ipynb remote.ipynb merged.ipynb | ||
""".format(__version__) | ||
|
||
def start(self): | ||
if len(self.extra_args) != 4: | ||
self.log.critical("Specify filenames for four notebooks: base local remote merged.") | ||
self.exit(1) | ||
|
||
bfn, lfn, rfn, mfn = self.extra_args | ||
def main_merge(bfn, lfn, rfn, mfn): | ||
for fn in (bfn, lfn, rfn): | ||
if not os.path.exists(fn): | ||
print("Cannot find file '{}'".format(fn)) | ||
print(_usage) | ||
return 1 | ||
|
||
for fn in (bfn, lfn, rfn): | ||
if not os.path.exists(fn): | ||
self.log.critical("Missing file {}".format(fn)) | ||
self.exit(1) | ||
b = nbformat.read(bfn, as_version=4) | ||
l = nbformat.read(lfn, as_version=4) | ||
r = nbformat.read(rfn, as_version=4) | ||
|
||
b = nbformat.read(bfn, as_version=4) | ||
l = nbformat.read(lfn, as_version=4) | ||
r = nbformat.read(rfn, as_version=4) | ||
m = merge_notebooks(b, l, r) | ||
|
||
m = merge_notebooks(b, l, r) | ||
verbose = True | ||
if verbose: | ||
print(m) | ||
|
||
verbose = True | ||
if verbose: | ||
print(m) | ||
nbformat.write(mfn, m) | ||
return 0 | ||
|
||
nbformat.write(mfn, m) | ||
|
||
def main(): | ||
NBMergeApp.launch_instance() | ||
args = sys.argv[1:] | ||
if len(args) != 4: | ||
r = 1 | ||
else: | ||
r = main_merge(*args) | ||
if r: | ||
print(_usage) | ||
sys.exit(r) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters