From 702d7d47c69c4cca74f2b4f4acd4f9373199d7f2 Mon Sep 17 00:00:00 2001 From: Kamil Páral Date: Jun 30 2021 14:46:08 +0000 Subject: install code linters (flake8, mypy) Add new requirements-development.txt, which installs code linters. These linters often have editor/IDE integration, or can be run manually. Update development.rst to include some guidance. Create setup.cfg to have a centralized tool configuration. Move pytest.ini content into setup.cfg. (Also add a few more deprecation warning filters for our libraries). --- diff --git a/.gitignore b/.gitignore index 12fa78b..a26f683 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ # cache files /.cache/ +/.mypy_cache/ /.pytest_cache/ .sass-cache/ *__pycache__* diff --git a/docs/source/development.rst b/docs/source/development.rst index 46580c3..c9d6ef7 100644 --- a/docs/source/development.rst +++ b/docs/source/development.rst @@ -46,6 +46,10 @@ virtualenv (ie. activate the virtualenv first):: pip install -r requirements.txt +Then install development helper packages, which are not required to run or test the project, but help when writing the code:: + + pip install -r requirements-development.txt + Configuring dev environment =========================== @@ -132,3 +136,21 @@ Unit tests have been written using `pytest `_ and can be run from the root project directory with:: pytest + + +Configuring and running linters +=============================== + +As part of the ``requirements-development.txt`` file, there are various source +code linters. The integration part for most of them is the +``python-language-server``, which can run the available linters automatically +and then provide the results to your editor/IDE. Check your editor +configuration or plugins, whether you can make use of the language-server (or +at least use the installed linters directly). Make sure to start your editor +from the virtualenv, though, so that it can access those packages. + +If your editor doesn't support linter integration, you can still run them from +the command line manually (inside the virtualenv):: + + flake8 + mypy diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index c698f13..0000000 --- a/pytest.ini +++ /dev/null @@ -1,8 +0,0 @@ -[pytest] -minversion = 2.0 -python_functions=test should -python_files=test_* testfunc_* -testpaths = testing -filterwarnings = - ignore:the imp module is deprecated in favour of importlib:DeprecationWarning:koji - ignore:defusedxml.cElementTree is deprecated, import from defusedxml.ElementTree instead:DeprecationWarning:openid diff --git a/requirements-development.txt b/requirements-development.txt new file mode 100644 index 0000000..1706de1 --- /dev/null +++ b/requirements-development.txt @@ -0,0 +1,11 @@ +## linters +# this automatically also pulls rope and flake8 (which pulls pyflakes, pycodestyle and mccabe) +python-language-server[rope,flake8] +mypy + +## additional type hints for mypy +sqlalchemy-stubs +types-Flask +munch-stubs +types-requests +types-mock diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..1eedd6c --- /dev/null +++ b/setup.cfg @@ -0,0 +1,45 @@ +[flake8] +extend-exclude = alembic/, conf/, docs/ +max-line-length = 100 + +[mypy] +files = blockerbugs/, testing/, *.py +# make sure to install the stubs from requirements-development.txt +plugins = sqlmypy + +# There seem to be no typing stubs available for these libraries: +[mypy-flask_sqlalchemy.*] +ignore_missing_imports = True +[mypy-flask_wtf.*] +ignore_missing_imports = True +[mypy-flask_fas_openid.*] +ignore_missing_imports = True +[mypy-flask_admin.*] +ignore_missing_imports = True +[mypy-alembic.*] +ignore_missing_imports = True +[mypy-wtforms.*] +ignore_missing_imports = True +[mypy-iso8601.*] +ignore_missing_imports = True +[mypy-koji.*] +ignore_missing_imports = True +[mypy-bugzilla.*] +ignore_missing_imports = True +[mypy-fedora.*] +ignore_missing_imports = True +[mypy-bodhi.*] +ignore_missing_imports = True + +[tool:pytest] +minversion = 2.0 +python_functions=test should +python_files=test_* testfunc_* +testpaths = testing +filterwarnings = + ignore:the imp module is deprecated in favour of importlib:DeprecationWarning:koji + ignore:defusedxml.cElementTree is deprecated, import from defusedxml.ElementTree instead:DeprecationWarning:openid + ignore:Importing 'itsdangerous.json' is deprecated and will be removed in ItsDangerous 2.1. Use Python's 'json' module instead.:DeprecationWarning:flask + ignore:'contextfunction' is renamed to 'pass_context', the old name will be removed in Jinja 3.1.:DeprecationWarning:flask_admin + ignore:The 'autoescape' extension is deprecated and will be removed in Jinja 3.1. This is built in now.:DeprecationWarning:jinja2 + ignore:The 'with' extension is deprecated and will be removed in Jinja 3.1. This is built in now.:DeprecationWarning:jinja2