parent
7bf22549bd
commit
c9dff24208
@ -1,17 +1,45 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
"""Click commands.""" |
"""Click commands.""" |
||||||
import click |
import click |
||||||
import os |
|
||||||
from flask.cli import with_appcontext |
from flask.cli import with_appcontext |
||||||
|
from glob import glob |
||||||
|
import os |
||||||
|
from subprocess import call |
||||||
|
|
||||||
HERE = os.path.abspath(os.path.dirname(__file__)) |
HERE = os.path.abspath(os.path.dirname(__file__)) |
||||||
PROJECT_ROOT = os.path.join(HERE, os.pardir) |
PROJECT_ROOT = os.path.join(HERE, os.pardir) |
||||||
TEST_PATH = os.path.join(PROJECT_ROOT, 'tests') |
TEST_PATH = os.path.join(PROJECT_ROOT, 'tests') |
||||||
|
|
||||||
|
|
||||||
@click.command('test') |
@click.command() |
||||||
@with_appcontext |
@with_appcontext |
||||||
def test_command(): |
def test(): |
||||||
"""Run the tests.""" |
"""Run the tests.""" |
||||||
import pytest |
import pytest |
||||||
pytest.main([TEST_PATH, '--verbose']) |
pytest.main([TEST_PATH, '--verbose']) |
||||||
|
|
||||||
|
|
||||||
|
@click.command() |
||||||
|
@click.option('-f', '--fix-imports', default=False, is_flag=True, |
||||||
|
help='Fix imports using isort, before linting') |
||||||
|
@with_appcontext |
||||||
|
def lint(fix_imports): |
||||||
|
"""Lint and check code style with flake8 and isort.""" |
||||||
|
skip = ['requirements'] |
||||||
|
root_files = glob('*.py') |
||||||
|
root_directories = [ |
||||||
|
name for name in next(os.walk('.'))[1] if not name.startswith('.')] |
||||||
|
files_and_directories = [ |
||||||
|
arg for arg in root_files + root_directories if arg not in skip] |
||||||
|
|
||||||
|
def execute_tool(description, *args): |
||||||
|
"""Execute a checking tool with its arguments.""" |
||||||
|
command_line = list(args) + files_and_directories |
||||||
|
click.echo('{}: {}'.format(description, ' '.join(command_line))) |
||||||
|
rv = call(command_line) |
||||||
|
if rv is not 0: |
||||||
|
exit(rv) |
||||||
|
|
||||||
|
if fix_imports: |
||||||
|
execute_tool('Fixing import order', 'isort', '-rc') |
||||||
|
execute_tool('Checking code style', 'flake8') |
||||||
|
Loading…
Reference in new issue