Keeping your projects nice and clean — Jan Musílek

Learn best practices for maintaining clean Python projects using autoformatters, code checks, and CI tools. Tips for efficient development and team collaboration.

Key takeaways
  • Use autoformatters to maintain consistent code style and save cognitive effort
    • Don’t waste time arguing about specific formatting - let tools handle it
    • Code review improves code quality and serves as bidirectional mentorship between junior and senior developers
    • Set up continuous integration to enforce code quality checks
  • Use pre-commit hooks to catch issues before code reaches the server
  • Key tools recommended:
    • Black or Ruff for autoformatting
    • Flake8 for linting
    • Bandit for security checks
    • Pydoc style for docstring formatting
    • MyPy for type checking
  • Keep tool configurations simple - start with defaults and build up gradually
  • Store project configuration in pyproject.toml
  • Automate manual tasks where possible
  • Don’t run formatting in CI - do it locally during development
  • Maintain consistency across projects to improve collaboration
  • Consider “bus factor” - ensure multiple team members can maintain the codebase
  • Keep dependencies and tools up to date but pin versions to avoid breaking changes
  • Use tools that provide autofix capabilities to save time on manual corrections