initial creation
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import os
|
||||
|
||||
import click
|
||||
|
||||
cmd_folder = os.path.join(os.path.dirname(__file__), 'commands')
|
||||
cmd_prefix = 'cmd_'
|
||||
|
||||
|
||||
class CLI(click.MultiCommand):
|
||||
def list_commands(self, ctx):
|
||||
"""
|
||||
Obtain a list of all available commands.
|
||||
|
||||
:param ctx: Click context
|
||||
:return: List of sorted commands
|
||||
"""
|
||||
commands = []
|
||||
|
||||
for filename in os.listdir(cmd_folder):
|
||||
if filename.endswith('.py') and filename.startswith(cmd_prefix):
|
||||
commands.append(filename[4:-3])
|
||||
|
||||
commands.sort()
|
||||
|
||||
return commands
|
||||
|
||||
def get_command(self, ctx, name):
|
||||
"""
|
||||
Get a specific command by looking up the module.
|
||||
|
||||
:param ctx: Click context
|
||||
:param name: Command name
|
||||
:return: Module's cli function
|
||||
"""
|
||||
ns = {}
|
||||
|
||||
filename = os.path.join(cmd_folder, cmd_prefix + name + '.py')
|
||||
|
||||
with open(filename) as f:
|
||||
code = compile(f.read(), filename, 'exec')
|
||||
eval(code, ns, ns)
|
||||
|
||||
return ns['cli']
|
||||
|
||||
|
||||
@click.command(cls=CLI)
|
||||
def cli():
|
||||
""" Commands to help manage your project. """
|
||||
pass
|
||||
@@ -0,0 +1,16 @@
|
||||
import subprocess
|
||||
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument('path', default='snakeeyes')
|
||||
def cli(path):
|
||||
"""
|
||||
Run a test coverage report.
|
||||
|
||||
:param path: Test coverage path
|
||||
:return: Subprocess call result
|
||||
"""
|
||||
cmd = 'py.test --cov-report term-missing --cov {0}'.format(path)
|
||||
return subprocess.call(cmd, shell=True)
|
||||
@@ -0,0 +1,24 @@
|
||||
import subprocess
|
||||
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.option('--skip-init/--no-skip-init', default=True,
|
||||
help='Skip __init__.py files?')
|
||||
@click.argument('path', default='snakeeyes')
|
||||
def cli(skip_init, path):
|
||||
"""
|
||||
Run flake8 to analyze your code base.
|
||||
|
||||
:param skip_init: Skip checking __init__.py files
|
||||
:param path: Test coverage path
|
||||
:return: Subprocess call result
|
||||
"""
|
||||
flake8_flag_exclude = ''
|
||||
|
||||
if skip_init:
|
||||
flake8_flag_exclude = ' --exclude __init__.py'
|
||||
|
||||
cmd = 'flake8 {0}{1}'.format(path, flake8_flag_exclude)
|
||||
return subprocess.call(cmd, shell=True)
|
||||
@@ -0,0 +1,17 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument('path', default=os.path.join('snakeeyes', 'tests'))
|
||||
def cli(path):
|
||||
"""
|
||||
Run tests with Pytest.
|
||||
|
||||
:param path: Test path
|
||||
:return: Subprocess call result
|
||||
"""
|
||||
cmd = 'py.test {0}'.format(path)
|
||||
return subprocess.call(cmd, shell=True)
|
||||
Reference in New Issue
Block a user