Skip to content

Instantly share code, notes, and snippets.

@jean-leonco
Created October 10, 2022 01:14
Show Gist options
  • Save jean-leonco/f2b13f239671a1c6b0893914fdfb2e1f to your computer and use it in GitHub Desktop.
Save jean-leonco/f2b13f239671a1c6b0893914fdfb2e1f to your computer and use it in GitHub Desktop.
Basic python setup
[flake8]
max-line-length = 88
extend-exclude = .venv
extend-ignore =
E203, # whitespace before ':' (conflicts with Black)
E231, # Bad trailing comma (conflicts with Black)
E501, # line too long (conflicts with Black)
W503, # line break before binary operator (conflicts with Black)
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-toml
- id: check-yaml
exclude: ^helm/
- id: check-added-large-files
- id: requirements-txt-fixer
args: ['requirements.in', 'requirements-dev.txt']
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
hooks:
- id: isort
# Reference https://github.com/psf/black/blob/main/.pre-commit-config.yaml#L34
- repo: https://gitlab.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
# additional_dependencies:
# - flake8-bugbear
# - flake8-comprehensions
# - flake8-simplify
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v1.2.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
# Setup application and install dependencies
setup:
pip install -U pip
pip install -r requirements-dev.txt
pip install -r requirements.txt
pre-commit install
# Setup application and install dependencies on CI mode
setup-ci:
pip install -U pip
pip install -r requirements-dev.txt
pip install -r requirements.txt
# Generate lock file for production dependencies
generate-requirements:
pip-compile --generate-hashes --output-file=requirements.txt requirements.in
# Run application tests
test:
pytest
# Run coverage for application tests
coverage:
coverage run -m pytest
coverage report -m
coverage xml
# Format code style
format:
black .
isort .
# Run lint
lint:
flake8 . --count --show-source --statistics
[tool.black]
extend-exclude = ".git, __pycache__, .venv"
[tool.isort]
profile = "black"
skip_gitignore = true
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
[pytest]
addopts = -r a --capture=no -vv --log-level=INFO --color=yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment