Skip to main content
Linting and Configuration

Linting and Configuration

·148 words·1 min·
Photo by Sarah Dorweiler on Unsplash
Improve your Python projects by integrating automated code formatting and linting tools. This post covers how to set up Black for consistent code style, manage development and production dependencies, and streamline your workflow with configuration best practices.

No brainer code formatting
#

Black is a Python code formatter. It is PEP 8 compliant and opinionated, thus no configuration is required to run it.

sudo -H pip install install black

Run Black on a Python project directory:

cd my-awesome-project
black .

All done! ✨ 🍰 ✨
11 files left unchanged.

Although Black enforces PEP 8 rules, we can tweak some options via ~/.config/black file:

[tool.black]
line-length = 119

Separate development and production requirements
#

mkdir requirements
touch requirements/prod.txt
touch requirements/dev.txt
nano requirements/prod.txt
click
guessit
logzero
requests
nano requirements/dev.txt
-r prod.txt
black
pylint
pre-commit

Install dev dependencies in local environment:

pip install -r requirements/dev.txt