With the importnb
extension installed by default IPython can run notebooks as modules. The notebook can be a great interactive interface for develiping applications.
import click
@click.group()
@click.option('--debug/--no-debug', default=False)
def cli(debug):
click.echo('Debug mode is %s' % ('on' if debug else 'off'))
@cli.command()
def sync():
click.echo('Synching')
The command line application will be run in the main context and it will have a file attribute. Otherwise, we test the function on the command line. We must use IPython and know that our importnb
loaders and included.
if globals().get('__file__', None) and __name__ == '__main__':
cli()
def _demonstrate_click_parser_for_a_notebook():
from IPython import get_ipython
!ipython -m deathbeds.2018-07-15-click-arguments-from-a-notebook -- --debug sync
]0;IPython: deathbeds.github.io/deathbedsDebug mode is on Synching