From 0b284dfd858a15c21f9d388696a9c558cb08f50d Mon Sep 17 00:00:00 2001 From: Vermeer GRANGE Date: Fri, 13 Mar 2020 12:37:40 +0200 Subject: [PATCH] Setup new code quality tools and drop pylint Welcome black, isort and flake8. Drop pylint which is slow as hell. --- .pylintrc | 75 ------------------------------------------------ Makefile | 27 +++++++++++------ README.md | 4 ++- requirements.in | 7 ++++- requirements.txt | 15 ++++++++-- setup.cfg | 21 ++++++++++++++ 6 files changed, 61 insertions(+), 88 deletions(-) delete mode 100644 .pylintrc create mode 100644 setup.cfg diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index d965f948e..000000000 --- a/.pylintrc +++ /dev/null @@ -1,75 +0,0 @@ -[MASTER] - -# Add files or directories to the blacklist. They should be base names, not -# paths. -ignore=migrations,south_migrations - -# Add files or directories matching the regex patterns to the blacklist. The -# regex matches against base names, not paths. -ignore-patterns=.*_pb2.py - - -[MESSAGES CONTROL] - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once).You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use"--disable=all --enable=classes -# --disable=W" -disable= - attribute-defined-outside-init, - bad-continuation, - cyclic-import, - duplicate-code, - fixme, - file-ignored, - invalid-name, - locally-enabled, - locally-disabled, - missing-docstring, - no-init, - no-member, - no-self-use, - old-style-class, - protected-access, - redefined-variable-type, - superfluous-parens, - too-few-public-methods, - too-many-ancestors, - too-many-arguments, - too-many-branches, - too-many-instance-attributes, - too-many-lines, - too-many-locals, - too-many-public-methods, - too-many-statements, - unused-argument - - -[REPORTS] - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details -msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" - - -[FORMAT] - -# Maximum number of characters on a single line. -max-line-length=120 - - -[DESIGN] - -# Maximum number of arguments for function / method -max-args=8 - -# Maximum number of parents for a class (see R0901). -max-parents=10 - -# Maximum number of attributes for a class (see R0902). -max-attributes=10 diff --git a/Makefile b/Makefile index ffe9bfa83..3cb4a1255 100644 --- a/Makefile +++ b/Makefile @@ -83,14 +83,25 @@ clean-services: stop-services ## Delete containers and attached volumes # Code quality # ------------ -# Run pylint on the whole project. -pylint-all: - pylint --rcfile=.pylintrc --reports=no --output-format=colorized $(PACKAGE_DIR) || true - -# Run pylint on a specific file, e.g.: -# make pylint FILE=labonneboite/web/app.py -pylint: - pylint --rcfile=.pylintrc --reports=no --output-format=colorized $(FILE) || true +quality: + docker exec -ti itou_django black --check --line-length 119 itou + docker exec -ti itou_django isort --check-only --recursive itou + docker exec -ti itou_django flake8 itou + +black: + black --line-length 119 . + +isort: + isort --recursive . + +flake8: + flake8 . + +setup_git_pre_commit_hook: + touch .git/hooks/pre-commit + chmod +x .git/hooks/pre-commit + echo "docker exec -t itou_django black --line-length 119 itou" > .git/hooks/pre-commit + echo "docker exec -t itou_django isort --recursive itou" >> .git/hooks/pre-commit # Local dev diff --git a/README.md b/README.md index 13b7808f2..7fb8ed7db 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Table of contents: - [Elastic Search](#elasticsearch) - [DB content in the development environment](#db-content-in-the-development-environment) - [Running scripts](#running-scripts) -- [Running Pylint](#running-pylint) +- [Running Pylint](#running-pylint) FIXME - [Debugging safely in development, staging or production](#debugging-safely-in-a-development-staging-or-production-environment) - [Importer](#importer) - [Single ROME versus multi-ROME search](#single-rome-vs-multi-rome-search) @@ -236,6 +236,8 @@ For example `create_index`: ## Running pylint +FIXME + You can run [pylint](https://www.pylint.org) on the whole project: $ make pylint-all diff --git a/requirements.in b/requirements.in index 7ed318318..57828b272 100644 --- a/requirements.in +++ b/requirements.in @@ -26,9 +26,14 @@ huey Flask-DebugToolbar ipdb ipython -pylint pip-tools +# Code quality. +pylint +flake8 +black==19.3b0 +isort + # profiling tools used in create_index.py pycallgraph pyprof2calltree diff --git a/requirements.txt b/requirements.txt index 9521a4419..7243eb400 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,19 +5,25 @@ # pip-compile --output-file requirements.txt requirements.in # alembic==0.9.10 +appdirs==1.4.3 # via black +appnope==0.1.0 # via ipython astroid==1.6.5 # via pylint +attrs==19.3.0 # via black babel==2.6.0 # via flask-babelex backcall==0.1.0 # via ipython +black==19.3b0 blinker==1.4 # via flask-debugtoolbar, raven certifi==2017.4.17 # via requests chardet==3.0.4 # via requests -click==6.7 # via flask, pip-tools +click==6.7 # via black, flask, pip-tools cssmin==0.2.0 decorator==4.3.0 # via ipython, traitlets, validators defusedxml==0.5.0 # via python3-openid, social-auth-core easyprocess==0.2.3 # via pyvirtualdisplay elasticsearch==1.9.0 +entrypoints==0.3 # via flake8 first==2.0.1 # via pip-tools +flake8==3.7.8 flask-admin==1.5.3 flask-assets==0.12 flask-babelex==0.9.3 @@ -40,7 +46,7 @@ idna==2.5 # via requests ipdb==0.11 ipython-genutils==0.2.0 # via traitlets ipython==6.4.0 -isort==4.2.15 # via pylint +isort==4.3.21 itsdangerous==0.24 # via flask, flask-debugtoolbar jedi==0.12.0 # via ipython jinja2==2.10.1 # via flask, flask-babelex @@ -51,7 +57,7 @@ locustio==0.7.5 mailjet-rest==1.3.3 mako==1.0.7 # via alembic markupsafe==1.1.1 -mccabe==0.6.1 # via pylint +mccabe==0.6.1 # via flake8, pylint msgpack-python==0.5.6 # via locustio mysqlclient==1.4.2.post1 nose==1.3.7 @@ -67,7 +73,9 @@ pip-tools==2.0.2 prompt-toolkit==1.0.15 # via ipython ptyprocess==0.6.0 # via pexpect pycallgraph==1.0.1 +pycodestyle==2.5.0 # via flake8 pycryptodomex==3.6.3 # via pyjwkest +pyflakes==2.1.1 # via flake8 pygments==2.2.0 # via ipython pyjwkest==1.4.0 # via social-auth-core pyjwt==1.5.2 # via social-auth-core @@ -99,6 +107,7 @@ social-auth-storage-sqlalchemy==1.1.0 # via social-auth-app-flask-sqlalchemy speaklater==1.3 sqlalchemy-utils==0.32.13 sqlalchemy==1.3.3 +toml==0.10.0 # via black traitlets==4.3.2 # via ipython unidecode==0.4.21 # via python-slugify urllib3==1.24.3 # via elasticsearch, requests, selenium diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 000000000..7386093f9 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,21 @@ +# - https://timothycrosley.github.io/isort/ +# - https://github.com/timothycrosley/isort#configuring-isort +# - https://github.com/timothycrosley/isort/wiki/isort-Settings + +[isort] +combine_as_imports = True +ensure_newline_before_comments = True +force_grid_wrap = 0 +include_trailing_comma = True +known_first_party = labonneboite +lines_after_imports = 2 +line_length = 119 +multi_line_output = 3 +use_parentheses = True + +# - https://www.flake8rules.com +# - http://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html#changing-the-ignore-list + +[flake8] +ignore = E203, W503 +max-line-length = 119