From 4b79b2c3aefaeafae3302762699d29fd085a83ef Mon Sep 17 00:00:00 2001 From: Deko Date: Sun, 12 Mar 2023 17:29:30 +0100 Subject: [PATCH] Add pre-commit --- .pre-commit-config.yaml | 20 +++++++++ README.md | 20 +++++++++ poetry.lock | 99 ++++++++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + 4 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..547877a --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,20 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + exclude: README.md + - id: end-of-file-fixer + - id: check-yaml + - repo: https://github.com/psf/black + rev: 23.1.0 + hooks: + - id: black + - repo: https://github.com/timothycrosley/isort + rev: 5.12.0 + hooks: + - id: isort + - repo: https://github.com/pycqa/flake8 + rev: 6.0.0 + hooks: + - id: flake8 diff --git a/README.md b/README.md index d1258c7..6de0540 100644 --- a/README.md +++ b/README.md @@ -150,3 +150,23 @@ poetry shell source .env python -m app.main ``` + +### Linting + +This project uses multiple linting plugins to ensure code formatting is consistent. + +1. `black .` is opinionated but uncompromising code formatting. +2. `flake8` enforces style guide, i.E. PEP8. +3. `isort .` sorts imports. + +Additionally, there is a pre-commit hook you can install to fix trailing whitespace, end of file and some yaml issues. +```bash +pre-commit install +``` + +You may also use it to quickly check through everything without needing to commit: +```bash +pre-commit run --all-files +``` + +Depending on your shell compatibility with poetry, you may have to prefix all of the above commands with `poetry run`. diff --git a/poetry.lock b/poetry.lock index 5303fd4..d87b541 100644 --- a/poetry.lock +++ b/poetry.lock @@ -43,6 +43,14 @@ category = "main" optional = false python-versions = ">=3.6" +[[package]] +name = "cfgv" +version = "3.3.1" +description = "Validate configuration and produce human readable error messages." +category = "main" +optional = false +python-versions = ">=3.6.1" + [[package]] name = "charset-normalizer" version = "3.0.1" @@ -81,6 +89,26 @@ python-versions = ">=3.7" [package.extras] toml = ["tomli"] +[[package]] +name = "distlib" +version = "0.3.6" +description = "Distribution utilities" +category = "main" +optional = false +python-versions = "*" + +[[package]] +name = "filelock" +version = "3.9.0" +description = "A platform independent file lock." +category = "main" +optional = false +python-versions = ">=3.7" + +[package.extras] +docs = ["furo (>=2022.12.7)", "sphinx-autodoc-typehints (>=1.19.5)", "sphinx (>=5.3)"] +testing = ["covdefaults (>=2.2.2)", "coverage (>=7.0.1)", "pytest-cov (>=4)", "pytest-timeout (>=2.1)", "pytest (>=7.2)"] + [[package]] name = "flake8" version = "6.0.0" @@ -94,6 +122,17 @@ mccabe = ">=0.7.0,<0.8.0" pycodestyle = ">=2.10.0,<2.11.0" pyflakes = ">=3.0.0,<3.1.0" +[[package]] +name = "identify" +version = "2.5.20" +description = "File identification library for Python" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.extras] +license = ["ukkonen"] + [[package]] name = "idna" version = "3.4" @@ -155,6 +194,14 @@ category = "dev" optional = false python-versions = ">=3.5" +[[package]] +name = "nodeenv" +version = "1.7.0" +description = "Node.js virtual environment builder" +category = "main" +optional = false +python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*" + [[package]] name = "packaging" version = "23.0" @@ -175,7 +222,7 @@ python-versions = ">=3.7" name = "platformdirs" version = "3.1.0" description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." -category = "dev" +category = "main" optional = false python-versions = ">=3.7" @@ -195,6 +242,21 @@ python-versions = ">=3.6" dev = ["pre-commit", "tox"] testing = ["pytest", "pytest-benchmark"] +[[package]] +name = "pre-commit" +version = "3.1.1" +description = "A framework for managing and maintaining multi-language pre-commit hooks." +category = "main" +optional = false +python-versions = ">=3.8" + +[package.dependencies] +cfgv = ">=2.0.0" +identify = ">=1.0.0" +nodeenv = ">=0.11.1" +pyyaml = ">=5.1" +virtualenv = ">=20.10.0" + [[package]] name = "pycodestyle" version = "2.10.0" @@ -244,6 +306,14 @@ pytest = ">=4.6" [package.extras] testing = ["fields", "hunter", "process-tests", "six", "pytest-xdist", "virtualenv"] +[[package]] +name = "pyyaml" +version = "6.0" +description = "YAML parser and emitter for Python" +category = "main" +optional = false +python-versions = ">=3.6" + [[package]] name = "requests" version = "2.28.2" @@ -299,6 +369,23 @@ brotli = ["brotlicffi (>=0.8.0)", "brotli (>=1.0.9)", "brotlipy (>=0.6.0)"] secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "urllib3-secure-extra", "ipaddress"] socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] +[[package]] +name = "virtualenv" +version = "20.20.0" +description = "Virtual Python Environment builder" +category = "main" +optional = false +python-versions = ">=3.7" + +[package.dependencies] +distlib = ">=0.3.6,<1" +filelock = ">=3.4.1,<4" +platformdirs = ">=2.4,<4" + +[package.extras] +docs = ["furo (>=2022.12.7)", "proselint (>=0.13)", "sphinx-argparse (>=0.4)", "sphinx (>=6.1.3)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=22.12)"] +test = ["covdefaults (>=2.2.2)", "coverage-enable-subprocess (>=1)", "coverage (>=7.1)", "flaky (>=3.7)", "packaging (>=23)", "pytest-env (>=0.8.1)", "pytest-freezegun (>=0.4.2)", "pytest-mock (>=3.10)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "pytest (>=7.2.1)"] + [[package]] name = "win32-setctime" version = "1.1.0" @@ -313,12 +400,13 @@ dev = ["pytest (>=4.6.2)", "black (>=19.3b0)"] [metadata] lock-version = "1.1" python-versions = "^3.11" -content-hash = "49398c01804a5f064b961089ffcdf2764ee95e2dd8bb35ece7bac34eec617534" +content-hash = "214ba051cbd09df53ac7c0fcce560c9617314f3d26ab703df34f31169bd63eb3" [metadata.files] attrs = [] black = [] certifi = [] +cfgv = [] charset-normalizer = [] click = [ {file = "click-8.1.3-py3-none-any.whl", hash = "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48"}, @@ -326,23 +414,30 @@ click = [ ] colorama = [] coverage = [] +distlib = [] +filelock = [] flake8 = [] +identify = [] idna = [] iniconfig = [] isort = [] loguru = [] mccabe = [] mypy-extensions = [] +nodeenv = [] packaging = [] pathspec = [] platformdirs = [] pluggy = [] +pre-commit = [] pycodestyle = [] pyflakes = [] pytest = [] pytest-cov = [] +pyyaml = [] requests = [] requests-mock = [] six = [] urllib3 = [] +virtualenv = [] win32-setctime = [] diff --git a/pyproject.toml b/pyproject.toml index ced7ebb..5512a75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,7 @@ authors = ["Deko "] python = "^3.11" requests = "^2.28.2" loguru = "^0.6.0" +pre-commit = "^3.1.1" [tool.poetry.dev-dependencies] black = "^23.1.0"