Skip to content
Snippets Groups Projects
Commit 64b644a4 authored by James Curtin's avatar James Curtin Committed by James Curtin
Browse files

Add black formatting

parent 6fe4eb17
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,6 @@
dist: xenial
language: python
python:
- 3.5
- 3.6
- 3.7
......
......@@ -6,6 +6,6 @@
"app_name": "{{cookiecutter.project_name.lower().replace('-', '_').replace(' ', '_')}}",
"project_short_description": "A flasky app.",
"use_pipenv": ["no", "yes"],
"python_version": ["3.7", "3.6", "3.5"],
"python_version": ["3.7", "3.6"],
"node_version": ["12", "10", "8"]
}
......@@ -41,9 +41,12 @@ def clean(ctx):
print('App directory does not exist. Skipping.')
def _run_flask_command(ctx, command):
def _run_flask_command(ctx, command, *args):
os.chdir(COOKIE)
ctx.run('flask {0}'.format(command), echo=True)
flask_command = 'flask {0}'.format(command)
if args:
flask_command = '{0} {1}'.format(flask_command, ' '.join(args))
ctx.run(flask_command, echo=True)
@task(pre=[clean, build])
......@@ -55,9 +58,7 @@ def test(ctx):
os.chdir(COOKIE)
shutil.copyfile(os.path.join(COOKIE, '.env.example'),
os.path.join(COOKIE, '.env'))
os.environ["FLASK_ENV"] = "production"
os.environ["FLASK_DEBUG"] = "0"
_run_flask_command(ctx, 'lint')
_run_flask_command(ctx, 'lint', '--check')
_run_flask_command(ctx, 'test')
......
[settings]
line_length=120
# Config file for automatic testing at travis-ci.org
dist: xenial
language: python
env:
- FLASK_APP=autoapp.py FLASK_DEBUG=1
python:
- 2.7
- 3.4
- 3.5
- 3.6
- 3.7
install:
......@@ -16,5 +14,5 @@ install:
before_script:
- npm run lint
- npm run build
- flask lint
- flask lint --check
script: flask test
......@@ -53,12 +53,11 @@ factory-boy = "==2.12.*"
pdbpp = "==0.10.0"
# Lint and code style
black = "==19.3b0"
flake8 = "==3.7.7"
flake8-blind-except = "==0.1.1"
flake8-debugger = "==3.1.0"
flake8-docstrings = "==1.3.0"
flake8-isort = "==2.7.0"
flake8-quotes = "==2.0.1"
isort = "==4.3.20"
pep8-naming = "==0.8.2"
......@@ -57,13 +57,18 @@ To open the interactive shell, run ::
By default, you will have access to the flask ``app``.
Running Tests
-------------
Running Tests/Linter
--------------------
To run all tests, run ::
flask test
To run the linter, run ::
flask lint
The ``lint`` command will attempt to fix any linting/style errors in the code. If you only want to know if the code will pass CI and do not wish for the linter to make changes, add the ``--check`` argument.
Migrations
----------
......
......@@ -8,11 +8,11 @@ factory-boy==2.11.1
pdbpp==0.10.0
# Lint and code style
flake8==3.5.0
black==19.3b0
flake8==3.7.7
flake8-blind-except==0.1.1
flake8-debugger==3.1.0
flake8-docstrings==1.3.0
flake8-isort==2.5
flake8-quotes==1.0.0
isort==4.3.4
pep8-naming==0.7.0
[flake8]
ignore = D401
ignore = D401,D202,E226,E302,E41
max-line-length=120
exclude = migrations/*
max-complexity = 10
[isort]
line_length=88
multi_line_output=3
skip=migrations/*
include_trailing_comma=true
......@@ -23,11 +23,12 @@ def test():
@click.command()
@click.option('-f', '--fix-imports', default=False, is_flag=True,
@click.option('-f', '--fix-imports', default=True, is_flag=True,
help='Fix imports using isort, before linting')
def lint(fix_imports):
"""Lint and check code style with flake8 and isort."""
skip = ['node_modules', 'requirements']
@click.option('-c', '--check', default=False, is_flag=True, help="Don't make any changes to files, just confirm they are formatted correctly")
def lint(fix_imports, check):
"""Lint and check code style with black, flake8 and isort."""
skip = ['node_modules', 'requirements', 'migrations']
root_files = glob('*.py')
root_directories = [
name for name in next(os.walk('.'))[1] if not name.startswith('.')]
......@@ -42,8 +43,14 @@ def lint(fix_imports):
if rv != 0:
exit(rv)
isort_args = ["-rc"]
black_args = []
if check:
isort_args.append('-c')
black_args.append('--check')
if fix_imports:
execute_tool('Fixing import order', 'isort', '-rc')
execute_tool('Fixing import order', 'isort', *isort_args)
execute_tool('Formatting style', 'black', *black_args)
execute_tool('Checking code style', 'flake8')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment