forked from Pelagicore/qface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
executable file
·102 lines (72 loc) · 2.26 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
# Copyright (c) Pelagicore AB 2016
import click
from subprocess import call
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer
from path import Path
import time
import os
import yaml
import logging
import logging.config
here = Path(__file__).abspath().dirname()
logging.config.dictConfig(yaml.load((here / 'log.yaml').open()))
logger = logging.getLogger(__name__)
os.environ['PYTHONPATH'] = Path.getcwd()
def sh(cmd, all=False, **kwargs):
click.echo('$ {0}'.format(cmd))
return call(cmd, shell=True, **kwargs)
@click.group()
def cli():
pass
@cli.command()
def antlr():
"""generate a new parser based on the grammar using antlr"""
cwd = str(Path('qface/idl/parser').abspath())
sh('antlr4 -Dlanguage=Python3 -Werror -package qface.idl.parser -o . -listener -visitor T.g4', cwd=cwd)
@cli.command()
@click.option('--debug/--nodebug')
def test(debug):
"""run the tests"""
sh('python3 -m pytest -v -s -l {0}'.format('-pdb' if debug else ''))
@cli.command()
def test_ci():
"""run the tests for CI integration"""
sh('python3 -m pytest --cov=qface -v -l tests/')
@click.option('--editable/--no-editable', default=False, help='install editable package')
@cli.command()
def install(editable):
"""install the script onto the system using pip3"""
script_dir = str(Path(__file__).parent.abspath())
click.secho(script_dir, fg='blue')
if editable:
sh('pip3 install --editable {0} --upgrade'.format(script_dir))
else:
sh('pip3 install {0} --upgrade'.format(script_dir))
@cli.command()
def uninstall():
"""uninstall the script from the system using pip3"""
sh('pip3 uninstall qface')
@cli.command()
def upload():
sh('twine upload dist/*')
Path('build').rmtree_p()
@cli.command()
def pack():
Path('build').rmtree_p()
Path('dist').rmtree_p()
sh('python3 setup.py bdist_wheel')
sh('unzip -l dist/*.whl')
@cli.command()
def docs_serve():
server = Server()
server.watch('docs/*.rst', shell('make html', cwd='docs'))
server.serve(root='docs/_build/html', open_url=True)
@cli.command()
def clean():
Path('build').rmtree_p()
Path('dist').rmtree_p()
Path('qface.egg-info').rmtree_p()
if __name__ == '__main__':
cli()