Commit 732581ec authored by André Anjos's avatar André Anjos 💬
Browse files

Merge branch 'click_beat_editor' into 'master'

Click beat editor

Closes #137

See merge request !12
parents 00b9f776 c642f6ce
Pipeline #23362 passed with stages
in 51 minutes and 20 seconds
......@@ -101,6 +101,13 @@ build_macosx_36:
image: docker.idiap.ch/beat/ci.env.editor:0.0.1r0
before_script:
# safe keep artifacts as before_build.sh will erase those...
- apt-get update > /dev/null
- apt-get install -y locales > /dev/null
- echo "en_US UTF-8" > /etc/locale.gen
- locale-gen en_US.UTF-8
- export LANG=en_US.UTF-8
- export LANGUAGE=en_US:en
- export LC_ALL=en_US.UTF-8
- mv ${CONDA_ROOT}/conda-bld .
- ./_ci/install.sh _ci master #updates ci support scripts
- ./_ci/before_build.sh
......
......@@ -26,61 +26,59 @@
###############################################################################
"""Starts the BEAT editor
Usage: %(prog)s [-v...] [--debug] [--prefix=<path>] [--cache=<path>] [--dev]
%(prog)s --help
%(prog)s --version
Options:
-h, --help Shows this help message and exits
-V, --version Prints the version and exits
-v, --verbose Increases the output verbosity level. Using "-vv"
allows the program to output informational messages as
it goes along.
-d, --debug Use the debug version of the javascript source to
launch the editor
--dev Use the development version, which doesn't open a new
web browser tab.
-p, --prefix=<path> Overrides the prefix of your local data. If not set use
the value from your RC file
[default: %(prefix)s]
-c, --cache=<path> Overrides the cache prefix. If not set, use the value
from your RC file, otherwise defaults to
`<prefix>/%(cache)s'
Examples:
Start the editor:
$ %(prog)s -vv
Start the editor in development mode:
$ %(prog)s -vv --debug
"""The main entry for beat.editor (click-based) scripts.
"""
import os
import sys
import docopt
import click
import pkg_resources
from click_plugins import with_plugins
from beat.cmdline.click_helper import AliasedGroup
from beat.cmdline.decorators import verbosity_option
from beat.cmdline.decorators import raise_on_error
from beat.cmdline.config import Configuration
def main(user_input=None):
if user_input is not None:
argv = user_input
else:
argv = sys.argv[1:]
import pkg_resources
EPILOG = '''\b
Example:
$ beat editor serve
$ beat editor serve --dev
To run the development server add option --dev
'''
@with_plugins(pkg_resources.iter_entry_points('beat.editor.cli'))
@click.group(cls=AliasedGroup)
@click.pass_context
def editor(ctx):
"""beat.editor commands webserver."""
pass
@editor.command(epilog=EPILOG)
@click.option('--dev', help='Use the development version, which doesn\'t open a new web browser tab.',
is_flag=True)
@click.option('--debug', '-d', help='Use the debug version of the javascript source to lauch the editor',
is_flag=True)
@click.option('--prefix', '-p', help='Overrides the prefix of your local data. If not set use the value from your RC file [default: %(prefix)s]',
type=click.STRING)
@click.option('--cache', '-c', help='Overrides the cache prefix. If not set, use the value from your RC file, otherwise defaults to `<prefix>/%(cache)s\'',
type=click.STRING)
@verbosity_option()
@click.pass_context
@raise_on_error
def serve(ctx, dev, debug, prefix, cache):
'''Run Flask server
To run the development server add option --dev
$ beat editor serve --dev
'''
ctx.meta['dev'] = dev
ctx.meta['debug'] = debug
ctx.meta['prefix'] = prefix
ctx.meta['cache'] = cache
completions = dict(
prog=os.path.basename(sys.argv[0]),
......@@ -90,17 +88,11 @@ def main(user_input=None):
from beat.cmdline.config import Configuration
completions.update(Configuration({}).as_dict())
args = docopt.docopt(
__doc__ % completions,
argv=argv,
version=completions['version'],
)
# Check that we are in a BEAT working folder
from ..utils import setup_logger
logger = setup_logger('beat.editor', args['--verbose'])
logger = setup_logger('beat.editor', ctx.meta['verbosity'])
# Check that we are in a BEAT working folder
config = Configuration(args)
config = Configuration(ctx.meta)
logger.info('BEAT prefix set to `%s\'', config.path)
logger.info('BEAT cache set to `%s\'', config.cache)
......@@ -133,11 +125,8 @@ def main(user_input=None):
api.add_resource(gen_endpoint(entity), '/' + entity,
resource_class_kwargs={'config': config})
# open the browser tab right before starting the server
# the latency of opening the tab will keep us from getting 404s
if not args['--dev']:
if dev:
import webbrowser
webbrowser.open('http://localhost:5000/')
webbrowser.open('http://localhost:5000')
app.run(debug=args['--debug'])
return app.run(debug=debug)
......@@ -6,8 +6,6 @@ package:
version: {{ environ.get('BOB_PACKAGE_VERSION', '0.0.1') }}
build:
entry_points:
- beateditor = beat.editor.scripts.server:main
number: {{ environ.get('BOB_BUILD_NUMBER', 0) }}
run_exports:
- {{ pin_subpackage(name) }}
......@@ -55,7 +53,8 @@ test:
- {{ name }}
commands:
- beateditor --help
- beat editor --help
- beat editor serve --help
- nosetests --with-coverage --cover-package={{ name }} -sv {{ name }}
- sphinx-build -aEW {{ project_dir }}/doc {{ project_dir }}/sphinx
- sphinx-build -aEb doctest {{ project_dir }}/doc sphinx
......
......@@ -26,7 +26,8 @@
###############################################################################
from setuptools import setup, find_packages
from setuptools import setup, find_packages, dist
dist.Distribution(dict(setup_requires=['beat.cmdline']))
def load_requirements(f):
retval = [str(k.strip()) for k in open(f, 'rt')]
......@@ -50,9 +51,14 @@ setup(
zip_safe=False,
install_requires=load_requirements('requirements.txt'),
entry_points={
'console_scripts': [
'beateditor = beat.editor.scripts.server:main',
# main entry for beat editor cli
'beat.cli': [
'editor = beat.editor.scripts.server_cli:editor',
],
'beat.editor.cli': [
'serve = beat.editor.scripts.server_cli:serve',
],
},
classifiers = [
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment