Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6697 beakerx commands refactor #6727

Merged
merged 3 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ conda create -y -n beakerx 'python>=3' nodejs pandas openjdk maven
source activate beakerx
conda install -y -c conda-forge ipywidgets
(cd beakerx; pip install -e . --verbose)
beakerx-install
beakerx install
```

### Build and Install for Lab
Expand All @@ -67,7 +67,7 @@ conda create -y -n labx 'python>=3' nodejs pandas openjdk maven pytest
source activate labx
conda install -y -c conda-forge jupyterlab
(cd beakerx; pip install -e . --verbose)
beakerx-install
beakerx install
jupyter labextension install @jupyter-widgets/jupyterlab-manager
(cd js/lab; jupyter labextension install .)
```
Expand Down
10 changes: 8 additions & 2 deletions beakerx/beakerx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ._version import version_info, __version__
from .handlers import load_jupyter_server_extension
from .environment import *
import json
from .commands import parse

def _jupyter_nbextension_paths():
return [{
Expand All @@ -40,5 +40,11 @@ def _jupyter_nbextension_paths():
def _jupyter_server_extension_paths():
return [dict(module="beakerx")]


beakerx = BeakerX()

def run():
try:
parse()
except KeyboardInterrupt:
return 130
return 0
15 changes: 7 additions & 8 deletions beakerx/beakerx/bkr2ipynb.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,15 @@ def convertNotebook(notebook):
nb = parseBkr(data)
nbformat.write(nb, notebook.partition('.')[0] + '.ipynb')

def main():
def main(args):
for notebook in args.notebooks:
convertNotebook(notebook)

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('notebooks', nargs='+',
help="beaker notebooks to be converted. Enter *.bkr in case you want to convert all notebooks at once.")
help="beaker notebooks to be converted. Enter *.bkr in case you want to convert all notebooks at once.")
if len(sys.argv) == 1:
parser.print_help()
args = parser.parse_args()

for notebook in args.notebooks:
convertNotebook(notebook)

if __name__ == "__main__":
main()
main(args)
65 changes: 65 additions & 0 deletions beakerx/beakerx/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright 2018 TWO SIGMA OPEN SOURCE, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

banner

import sys
import beakerx
from notebook import notebookapp as app
from .install import install, uninstall
from .bkr2ipynb import main

def install_subparser(subparser):
install_parser = subparser.add_parser('install', help='installs BeakerX extensions')
install_parser.set_defaults(func = install)
install_parser.add_argument("--prefix",
help="location of the environment to install into",
default=sys.prefix)
return subparser

def uninstall_subparser(subparser):
uninstall_parser = subparser.add_parser('uninstall', help='uninstalls BeakerX extensions')
uninstall_parser.set_defaults(func=lambda args : uninstall())
return subparser

def bkr2ipynb_subparser(subparser):
bkr2ipynb_parser = subparser.add_parser('bkr2ipynb', help='converts Beaker notebooks to ipynb format')
bkr2ipynb_parser.set_defaults(func=main)
bkr2ipynb_parser.add_argument('notebooks', nargs='+',
help="Beaker notebooks to be converted. Enter *.bkr in case you want to convert all notebooks at once.")
return subparser

def run_jupyter(jupyter_commands):
app.launch_new_instance(jupyter_commands)

def init_parser():

parser = argparse.ArgumentParser()
parser.add_argument('--version', action='version', version=beakerx.__version__)
parser.set_defaults(func=run_jupyter)

subparsers = parser.add_subparsers()
install_subparser(subparsers)
uninstall_subparser(subparsers)
bkr2ipynb_subparser(subparsers)
return parser

def parse():
parser = init_parser()
args, jupyter_commands = parser.parse_known_args()
if args.func == run_jupyter:
args.func(jupyter_commands)
elif not jupyter_commands:
args.func(args)
else:
parser.parse_args(jupyter_commands)

16 changes: 5 additions & 11 deletions beakerx/beakerx/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,11 @@ def _install_beakerx(args):
_set_conf_privileges()


def install():
try:
parser = make_parser()
args = parser.parse_args()
if args.disable:
_disable_beakerx()
else:
_install_beakerx(args)
except KeyboardInterrupt:
return 130
return 0
def install(args):
_install_beakerx(args)

def uninstall():
_disable_beakerx()


if __name__ == "__main__":
Expand Down
3 changes: 1 addition & 2 deletions beakerx/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@
],
entry_points={
'console_scripts': [
'beakerx-install = beakerx.install:install',
'bkr2ipynb = beakerx.bkr2ipynb:main',
'beakerx = beakerx:run'
]
},
package_data={
Expand Down
2 changes: 1 addition & 1 deletion docker/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

source activate beakerx
(cd beakerx; pip install -e . --verbose)
beakerx-install
beakerx install
jupyter labextension install @jupyter-widgets/jupyterlab-manager
(cd js/lab; jupyter labextension install .)

Expand Down