This PR refactors the CI steps executed by CircleCI and adds a new series of pre-commit and pre-push validations by using git hooks, husky, and pre-commit (python package).
The following packages are being used:
flake8 for linting code and detecting errors.
black for formatting code.
isort for sorting the imports.
husky for setting up the git hooks
pre-commit to define the use of flake8, black and isort before every commit and checking migrations before every push.
The CI steps are changed in the following ways:
Two jobs are executed in parallel, test and lint
The test is the old build job, but now it caches the npm cache.
The lint job checks the code with flake8, black and isort
How is everything configured
Black comes with its default settings.
Flake8 is being called in a way so it follows black.
Isort is separating the imports in the following sections:
STDLIB, DJANGO, and THIRDPARTY are preceded y comments
Any preexisting comments will be maintained
pyproject.toml
The last two years a new settings format, pyproject.toml has been gaining traction.
Now we can configure a lot of python-only tools (like poetry) in this file. For example, all the isort configuration is in this file under [tools.isort], which allows the dev to simply use isort isntead of a really long line of flags and configs. If we where to configure black, we would use this file too.
Pytest added support for this format on its 6.0.0 version, since we are already on that version I moved the configuration to this file.
The only problem with this setup is that flake8 doesn't support this config file.
TO-DO
[ ] Validate black formatting decisions and configure it if necessary
[ ] Validate current isort configuration and change it if necessary
[ ] Decide between flake8 or another linter.
Flake8 is a good linter as is, but we would have to add another file to configure it. If we where to use another linter, for example, pylint, that supports pyproject.toml, we could have all our python-only config in just one file.
[ ] Check if .coveragerc can be translated to pyproject.toml
[ ] Apply the black, isort and the selected linter to all the files
[ ] Change the startapp template to follow black, isort, and the linter.
What is being added
This PR refactors the CI steps executed by CircleCI and adds a new series of pre-commit and pre-push validations by using git hooks, husky, and pre-commit (python package).
The following packages are being used:
The CI steps are changed in the following ways:
How is everything configured
pyproject.toml
The last two years a new settings format, pyproject.toml has been gaining traction.
Now we can configure a lot of python-only tools (like poetry) in this file. For example, all the isort configuration is in this file under [tools.isort], which allows the dev to simply use isort isntead of a really long line of flags and configs. If we where to configure black, we would use this file too.
Pytest added support for this format on its 6.0.0 version, since we are already on that version I moved the configuration to this file.
The only problem with this setup is that flake8 doesn't support this config file.
TO-DO
Flake8 is a good linter as is, but we would have to add another file to configure it. If we where to use another linter, for example, pylint, that supports pyproject.toml, we could have all our python-only config in just one file.