From e3e83b50989e50e665a6042624c6823f02c45852 Mon Sep 17 00:00:00 2001 From: Michiel De Smet Date: Thu, 1 Sep 2022 13:32:22 +0200 Subject: [PATCH] Add black and isort autoformatting --- .flake8 | 12 ++++++++++++ .github/workflows/ci.yml | 2 +- .pre-commit-config.yaml | 15 +++++++++++++++ README.md | 15 +++++++++++++++ setup.py | 5 ++++- 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..a870046d --- /dev/null +++ b/.flake8 @@ -0,0 +1,12 @@ +[flake8] +# See https://flake8.pycqa.org/en/2.5.5/warnings.html +select = + E # pep8 errors + W # pep8 warnings + F # PyFlake codes +ignore = + W503 # line break before binary operator (makes Flake8 work like black) + W504 # line break after binary operator + E203 # whitespace before ‘:’ (makes Flake8 work like black) + E741 # do not use variables named ‘l’, ‘O’, or ‘I’ + E501 # line too long (82 > 79 characters) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bde0ee1a..4524b425 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: run: pip install pre-commit - name: "Run pre-commit checks" - run: pre-commit run --all-files + run: pre-commit run --hook-stage manual --all-files build: runs-on: ubuntu-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 32bf21cc..20c43c5c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,6 +4,7 @@ repos: hooks: - id: "flake8" name: "Python: analysis" + stages: [manual] - repo: "https://github.com/pre-commit/mirrors-mypy" rev: "v0.910" @@ -13,3 +14,17 @@ repos: additional_dependencies: - "types-pytz" - "types-requests" + stages: [manual] + + - repo: https://github.com/psf/black + rev: 22.3.0 + hooks: + - id: black + args: + - "--line-length=120" + + - repo: https://github.com/pycqa/isort + rev: 5.6.4 + hooks: + - id: isort + args: [ "--profile", "black"] diff --git a/README.md b/README.md index d45c6554..896d70e4 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,20 @@ 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: + +- [`black`](https://github.com/psf/black) for code formatting +- [`isort`](https://pycqa.github.io/isort/) for sorting imports + +In the CI build following additional checks are performed. You can manually execute them using `pre-commit run --hook-stage manual`. + +- [`flake8`](https://flake8.pycqa.org/en/latest/) for code linting +- [`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 49e310c9..2ee59cb2 100755 --- a/setup.py +++ b/setup.py @@ -39,6 +39,9 @@ "pytest", "pytest-runner", "click", + "pre-commit", + "black", + "isort", ] setup( @@ -75,7 +78,7 @@ "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Database :: Front-Ends", ], - python_requires='>=3.7', + python_requires=">=3.7", install_requires=["pytz", "requests"], extras_require={ "all": all_require,