Skip to content

Commit

Permalink
Added black (code formatting) and isort (import sorting)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdesmet committed Aug 22, 2022
1 parent 1823cc6 commit 3ee643e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ repos:
hooks:
- id: "flake8"
name: "Python: analysis"
stages: [manual]

- repo: "https://github.com/pre-commit/mirrors-mypy"
rev: "v0.910"
Expand All @@ -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", "--filter-files" ]
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
"pytest",
"pytest-runner",
"click",
"pre-commit",
"black",
"isort",
]

setup(
Expand Down

0 comments on commit 3ee643e

Please sign in to comment.