https://github.com/mafda/python_best_practices
How to make your code shine with isort, Black, Flake8, and Pylint. Guidelines and best practice suggestions on how to write Python code.
https://github.com/mafda/python_best_practices
best-practices black clean-code flake8 formatter good-practices isort linting pep8 pep8-checker pylint python python-best-practices python-clean-code styleguide
Last synced: 11 days ago
JSON representation
How to make your code shine with isort, Black, Flake8, and Pylint. Guidelines and best practice suggestions on how to write Python code.
- Host: GitHub
- URL: https://github.com/mafda/python_best_practices
- Owner: mafda
- Created: 2022-05-13T00:39:50.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-07T23:42:04.000Z (almost 3 years ago)
- Last Synced: 2025-04-15T12:12:36.336Z (11 days ago)
- Topics: best-practices, black, clean-code, flake8, formatter, good-practices, isort, linting, pep8, pep8-checker, pylint, python, python-best-practices, python-clean-code, styleguide
- Language: Python
- Homepage:
- Size: 1.16 MB
- Stars: 34
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Python Best Practices
**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](https://medium.com/semantixbr/how-to-make-your-code-shine-with-gitlab-ci-pipelines-48ade99192d1)
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](https://peps.python.org/pep-0008/)
compliant. **PEP8 — Python Enhancement Proposal**, is a style guide that
provides guidelines and best practices suggestions on how to write Python code.## Python tools
* Importing sorting with [isort](https://pycqa.github.io/isort/)
* Formatting with [Black](https://github.com/psf/black)
* Linting with [Flake8](https://flake8.pycqa.org/en/latest/)
* Bug and quality checking with [Pylint](https://www.pylint.org/)## Project Setup
### Clone this repository
```shell
(base)$: git clone [email protected]:mafda/python_best_practices.git
(base)$: cd python_best_practices
```### Configure environment
- Create the conda environment
```shell
(base)$: conda env create -f environment.yml
```- Activate the environment
```shell
(base)$: conda activate linear-regression
```- And run
```shell
(linear-regression)$: sh pep8.sh
```## Use these tools in your project and clean your code!
```shell
(base)$: conda env create -f environment-dev.yml
(base)$: conda activate best-practices
(best-practices)$: cd your-project
```### isort
You could use `isort .` or `isort . --check-only`

### Black
You could use `black --line-length 79 .` or `black --line-length 79 --check .`

### Flake8
You could use `flake8 .`

Fix errors:

### PyLint
You could use `find . -type f -name "*.py" | xargs pylint`
---
made with 💙 by [mafda](https://mafda.github.io/)