How can you make your code shine with isort, Black, Flake8 and Pylint?
In this repository, I would like to show some guidelines and best practice tips on how to write Python code.
We can use a simple deck of programs to get our code styling done. We can use isort for sorting the library imports (yes, imports have a suggested order), we can check the existence of undesired artifacts using Flake8 and Pylint, and we can keep the code within the same style using Black.
Those tools can be configured to be PEP8 compliant. PEP8 — Python Enhancement Proposal, is a style guide that provides guidelines and best practices suggestions on how to write Python code.
- Importing sorting with isort
- Formatting with Black
- Linting with Flake8
- Bug and quality checking with Pylint
(base)$: git clone git@github.com:mafda/python_best_practices.git
(base)$: cd python_best_practices
- Create the conda environment
(base)$: conda env create -f environment.yml
- Activate the environment
(base)$: conda activate linear-regression
- And run
(linear-regression)$: sh pep8.sh
(base)$: conda env create -f environment-dev.yml
(base)$: conda activate best-practices
(best-practices)$: cd your-project
You could use isort .
or isort . --check-only
You could use black --line-length 79 .
or black --line-length 79 --check .
You could use flake8 .
Fix errors:
You could use find . -type f -name "*.py" | xargs pylint
made with 💙 by mafda