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 blackRun 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 = 119Separate development and production requirements#
mkdir requirements
touch requirements/prod.txt
touch requirements/dev.txtnano requirements/prod.txtclick
guessit
logzero
requestsnano requirements/dev.txt-r prod.txt
black
pylint
pre-commitInstall dev dependencies in local environment:
pip install -r requirements/dev.txt