From 18757d97ea8942e55e2b56ae94a5f4d810b04b12 Mon Sep 17 00:00:00 2001 From: Michiel De Smet Date: Fri, 19 Aug 2022 14:55:46 +0200 Subject: [PATCH] Added black (code formatting) and isort (import sorting) --- .flake8 | 11 +++++++++++ .pre-commit-config.yaml | 13 +++++++++++++ README.md | 12 ++++++++++++ setup.py | 3 +++ 4 files changed, 39 insertions(+) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..21c33d71 --- /dev/null +++ b/.flake8 @@ -0,0 +1,11 @@ +[flake8] +select = + E + W + F +ignore = + W503 # makes Flake8 work like black + W504 + E203 # makes Flake8 work like black + E741 + E501 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 32bf21cc..b815fc8a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,3 +13,16 @@ repos: additional_dependencies: - "types-pytz" - "types-requests" + + - repo: https://github.com/psf/black + rev: 22.3.0 + hooks: + - id: black + args: + - "--line-length=99" + + - repo: https://github.com/pycqa/isort + rev: 5.6.4 + hooks: + - id: isort + args: [ "--profile", "black", "--filter-files" ] diff --git a/README.md b/README.md index d45c6554..98b01322 100644 --- a/README.md +++ b/README.md @@ -424,6 +424,7 @@ We recommend that you use Python3's `venv` for development: $ python3 -m venv .venv $ . .venv/bin/activate $ pip install -e '.[tests]' +$ pre-commit install ``` With `-e` passed to `pip install` above pip can reference the code you are @@ -441,6 +442,17 @@ When the code is ready, submit a Pull Request. See also Trino's [guidelines](https://github.com/trinodb/trino/blob/master/.github/DEVELOPMENT.md). Most of them also apply to code in trino-python-client. +### `pre-commit` checks + +Code is automatically checked on commit by a [pre-commit](https://pre-commit.com/) git hook. + +Following checks are performed: + +- [`flake8`](https://flake8.pycqa.org/en/latest/) for code linting +- [`black`](https://github.com/psf/black) for code formatting +- [`isort`](https://pycqa.github.io/isort/) for sorting imports +- [`mypy`](https://mypy.readthedocs.io/en/stable/) for static type checking + ### Running tests `trino-python-client` uses [pytest](https://pytest.org/) for its tests. To run diff --git a/setup.py b/setup.py index 0bc76ec7..2ee59cb2 100755 --- a/setup.py +++ b/setup.py @@ -39,6 +39,9 @@ "pytest", "pytest-runner", "click", + "pre-commit", + "black", + "isort", ] setup(