Add black formatting

master
James Curtin 6 years ago committed by James Curtin
parent 6fe4eb17f7
commit 64b644a490
  1. 1
      .travis.yml
  2. 2
      cookiecutter.json
  3. 11
      tasks.py
  4. 2
      {{cookiecutter.app_name}}/.isort.cfg
  5. 6
      {{cookiecutter.app_name}}/.travis.yml
  6. 3
      {{cookiecutter.app_name}}/Pipfile
  7. 9
      {{cookiecutter.app_name}}/README.rst
  8. 4
      {{cookiecutter.app_name}}/requirements/dev.txt
  9. 10
      {{cookiecutter.app_name}}/setup.cfg
  10. 17
      {{cookiecutter.app_name}}/{{cookiecutter.app_name}}/commands.py

@ -2,7 +2,6 @@
dist: xenial dist: xenial
language: python language: python
python: python:
- 3.5
- 3.6 - 3.6
- 3.7 - 3.7

@ -6,6 +6,6 @@
"app_name": "{{cookiecutter.project_name.lower().replace('-', '_').replace(' ', '_')}}", "app_name": "{{cookiecutter.project_name.lower().replace('-', '_').replace(' ', '_')}}",
"project_short_description": "A flasky app.", "project_short_description": "A flasky app.",
"use_pipenv": ["no", "yes"], "use_pipenv": ["no", "yes"],
"python_version": ["3.7", "3.6", "3.5"], "python_version": ["3.7", "3.6"],
"node_version": ["12", "10", "8"] "node_version": ["12", "10", "8"]
} }

@ -41,9 +41,12 @@ def clean(ctx):
print('App directory does not exist. Skipping.') print('App directory does not exist. Skipping.')
def _run_flask_command(ctx, command): def _run_flask_command(ctx, command, *args):
os.chdir(COOKIE) 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]) @task(pre=[clean, build])
@ -55,9 +58,7 @@ def test(ctx):
os.chdir(COOKIE) os.chdir(COOKIE)
shutil.copyfile(os.path.join(COOKIE, '.env.example'), shutil.copyfile(os.path.join(COOKIE, '.env.example'),
os.path.join(COOKIE, '.env')) os.path.join(COOKIE, '.env'))
os.environ["FLASK_ENV"] = "production" _run_flask_command(ctx, 'lint', '--check')
os.environ["FLASK_DEBUG"] = "0"
_run_flask_command(ctx, 'lint')
_run_flask_command(ctx, 'test') _run_flask_command(ctx, 'test')

@ -1,2 +0,0 @@
[settings]
line_length=120

@ -1,11 +1,9 @@
# Config file for automatic testing at travis-ci.org # Config file for automatic testing at travis-ci.org
dist: xenial
language: python language: python
env: env:
- FLASK_APP=autoapp.py FLASK_DEBUG=1 - FLASK_APP=autoapp.py FLASK_DEBUG=1
python: python:
- 2.7
- 3.4
- 3.5
- 3.6 - 3.6
- 3.7 - 3.7
install: install:
@ -16,5 +14,5 @@ install:
before_script: before_script:
- npm run lint - npm run lint
- npm run build - npm run build
- flask lint - flask lint --check
script: flask test script: flask test

@ -53,12 +53,11 @@ factory-boy = "==2.12.*"
pdbpp = "==0.10.0" pdbpp = "==0.10.0"
# Lint and code style # Lint and code style
black = "==19.3b0"
flake8 = "==3.7.7" flake8 = "==3.7.7"
flake8-blind-except = "==0.1.1" flake8-blind-except = "==0.1.1"
flake8-debugger = "==3.1.0" flake8-debugger = "==3.1.0"
flake8-docstrings = "==1.3.0" flake8-docstrings = "==1.3.0"
flake8-isort = "==2.7.0" flake8-isort = "==2.7.0"
flake8-quotes = "==2.0.1"
isort = "==4.3.20" isort = "==4.3.20"
pep8-naming = "==0.8.2" 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``. By default, you will have access to the flask ``app``.
Running Tests Running Tests/Linter
------------- --------------------
To run all tests, run :: To run all tests, run ::
flask test 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 Migrations
---------- ----------

@ -8,11 +8,11 @@ factory-boy==2.11.1
pdbpp==0.10.0 pdbpp==0.10.0
# Lint and code style # Lint and code style
flake8==3.5.0 black==19.3b0
flake8==3.7.7
flake8-blind-except==0.1.1 flake8-blind-except==0.1.1
flake8-debugger==3.1.0 flake8-debugger==3.1.0
flake8-docstrings==1.3.0 flake8-docstrings==1.3.0
flake8-isort==2.5 flake8-isort==2.5
flake8-quotes==1.0.0
isort==4.3.4 isort==4.3.4
pep8-naming==0.7.0 pep8-naming==0.7.0

@ -1,3 +1,11 @@
[flake8] [flake8]
ignore = D401 ignore = D401,D202,E226,E302,E41
max-line-length=120 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.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') help='Fix imports using isort, before linting')
def lint(fix_imports): @click.option('-c', '--check', default=False, is_flag=True, help="Don't make any changes to files, just confirm they are formatted correctly")
"""Lint and check code style with flake8 and isort.""" def lint(fix_imports, check):
skip = ['node_modules', 'requirements'] """Lint and check code style with black, flake8 and isort."""
skip = ['node_modules', 'requirements', 'migrations']
root_files = glob('*.py') root_files = glob('*.py')
root_directories = [ root_directories = [
name for name in next(os.walk('.'))[1] if not name.startswith('.')] name for name in next(os.walk('.'))[1] if not name.startswith('.')]
@ -42,8 +43,14 @@ def lint(fix_imports):
if rv != 0: if rv != 0:
exit(rv) exit(rv)
isort_args = ["-rc"]
black_args = []
if check:
isort_args.append('-c')
black_args.append('--check')
if fix_imports: 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') execute_tool('Checking code style', 'flake8')

Loading…
Cancel
Save