Skip to content

Commit 3ee643e

Browse files
committed
Added black (code formatting) and isort (import sorting)
1 parent 1823cc6 commit 3ee643e

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

.flake8

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[flake8]
2+
# See https://flake8.pycqa.org/en/2.5.5/warnings.html
3+
select =
4+
E # pep8 errors
5+
W # pep8 warnings
6+
F # PyFlake codes
7+
ignore =
8+
W503 # line break before binary operator (makes Flake8 work like black)
9+
W504 # line break after binary operator
10+
E203 # whitespace before ‘:’ (makes Flake8 work like black)
11+
E741 # do not use variables named ‘l’, ‘O’, or ‘I’
12+
E501 # line too long (82 > 79 characters)

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
run: pip install pre-commit
2828

2929
- name: "Run pre-commit checks"
30-
run: pre-commit run --all-files
30+
run: pre-commit run --hook-stage manual --all-files
3131

3232
build:
3333
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ repos:
44
hooks:
55
- id: "flake8"
66
name: "Python: analysis"
7+
stages: [manual]
78

89
- repo: "https://github.com/pre-commit/mirrors-mypy"
910
rev: "v0.910"
@@ -13,3 +14,17 @@ repos:
1314
additional_dependencies:
1415
- "types-pytz"
1516
- "types-requests"
17+
stages: [manual]
18+
19+
- repo: https://github.com/psf/black
20+
rev: 22.3.0
21+
hooks:
22+
- id: black
23+
args:
24+
- "--line-length=120"
25+
26+
- repo: https://github.com/pycqa/isort
27+
rev: 5.6.4
28+
hooks:
29+
- id: isort
30+
args: [ "--profile", "black", "--filter-files" ]

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ We recommend that you use Python3's `venv` for development:
424424
$ python3 -m venv .venv
425425
$ . .venv/bin/activate
426426
$ pip install -e '.[tests]'
427+
$ pre-commit install
427428
```
428429

429430
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.
441442
See also Trino's [guidelines](https://github.com/trinodb/trino/blob/master/.github/DEVELOPMENT.md).
442443
Most of them also apply to code in trino-python-client.
443444

445+
### `pre-commit` checks
446+
447+
Code is automatically checked on commit by a [pre-commit](https://pre-commit.com/) git hook.
448+
449+
Following checks are performed:
450+
451+
- [`black`](https://github.com/psf/black) for code formatting
452+
- [`isort`](https://pycqa.github.io/isort/) for sorting imports
453+
454+
In the CI build following additional checks are performed. You can manually execute them using `pre-commit run --hook-stage manual`.
455+
456+
- [`flake8`](https://flake8.pycqa.org/en/latest/) for code linting
457+
- [`mypy`](https://mypy.readthedocs.io/en/stable/) for static type checking
458+
444459
### Running tests
445460

446461
`trino-python-client` uses [pytest](https://pytest.org/) for its tests. To run

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
"pytest",
4040
"pytest-runner",
4141
"click",
42+
"pre-commit",
43+
"black",
44+
"isort",
4245
]
4346

4447
setup(

0 commit comments

Comments
 (0)