Skip to content

Commit 073acb7

Browse files
committed
Added black (code formatting) and isort (sorting imports)
1 parent 88ad0bc commit 073acb7

27 files changed

+831
-672
lines changed

.flake8

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[flake8]
2+
select =
3+
E
4+
W
5+
F
6+
ignore =
7+
W503 # makes Flake8 work like black
8+
W504
9+
E203 # makes Flake8 work like black
10+
E741
11+
E501

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,16 @@ repos:
1313
additional_dependencies:
1414
- "types-pytz"
1515
- "types-requests"
16+
17+
- repo: https://github.com/psf/black
18+
rev: 22.3.0
19+
hooks:
20+
- id: black
21+
args:
22+
- "--line-length=99"
23+
24+
- repo: https://github.com/pycqa/isort
25+
rev: 5.6.4
26+
hooks:
27+
- id: isort
28+
args: [ "--profile", "black", "--filter-files" ]

README.md

Lines changed: 12 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,17 @@ 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+
- [`flake8`](https://flake8.pycqa.org/en/latest/) for code linting
452+
- [`black`](https://github.com/psf/black) for code formatting
453+
- [`isort`](https://pycqa.github.io/isort/) for sorting imports
454+
- [`mypy`](https://mypy.readthedocs.io/en/stable/) for static type checking
455+
444456
### Running tests
445457

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

setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import re
1717
import textwrap
1818

19-
from setuptools import setup, find_packages
19+
from setuptools import find_packages, setup
2020

2121
_version_re = re.compile(r"__version__\s+=\s+(.*)")
2222

@@ -39,6 +39,9 @@
3939
"pytest",
4040
"pytest-runner",
4141
"click",
42+
"pre-commit",
43+
"black",
44+
"isort",
4245
]
4346

4447
setup(
@@ -75,7 +78,7 @@
7578
"Programming Language :: Python :: Implementation :: PyPy",
7679
"Topic :: Database :: Front-Ends",
7780
],
78-
python_requires='>=3.7',
81+
python_requires=">=3.7",
7982
install_requires=["pytz", "requests"],
8083
extras_require={
8184
"all": all_require,

tests/integration/conftest.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
from uuid import uuid4
1919

2020
import click
21-
import trino.logging
2221
import pytest
23-
from trino.client import TrinoQuery, TrinoRequest, ClientSession
24-
from trino.constants import DEFAULT_PORT
2522

23+
import trino.logging
24+
from trino.client import ClientSession, TrinoQuery, TrinoRequest
25+
from trino.constants import DEFAULT_PORT
2626

2727
logger = trino.logging.get_logger(__name__)
2828

@@ -64,13 +64,7 @@ def start_trino(image_tag=None):
6464

6565

6666
def wait_for_trino_workers(host, port, timeout=180):
67-
request = TrinoRequest(
68-
host=host,
69-
port=port,
70-
client_session=ClientSession(
71-
user="test_fixture"
72-
)
73-
)
67+
request = TrinoRequest(host=host, port=port, client_session=ClientSession(user="test_fixture"))
7468
sql = "SELECT state FROM system.runtime.nodes"
7569
t0 = time.time()
7670
while True:
@@ -116,9 +110,7 @@ def start_trino_and_wait(image_tag=None):
116110
if host:
117111
port = os.environ.get("TRINO_RUNNING_PORT", DEFAULT_PORT)
118112
else:
119-
container_id, proc, host, port = start_local_trino_server(
120-
image_tag
121-
)
113+
container_id, proc, host, port = start_local_trino_server(image_tag)
122114

123115
print("trino.server.hostname {}".format(host))
124116
print("trino.server.port {}".format(port))
@@ -167,9 +159,7 @@ def cli():
167159
pass
168160

169161

170-
@click.option(
171-
"--cache/--no-cache", default=True, help="enable/disable Docker build cache"
172-
)
162+
@click.option("--cache/--no-cache", default=True, help="enable/disable Docker build cache")
173163
@click.command()
174164
def trino_server():
175165
container_id, _, _, _ = start_trino_and_wait()
@@ -198,9 +188,7 @@ def trino_cli(container_id=None):
198188

199189
@cli.command("list")
200190
def list_():
201-
subprocess.check_call(
202-
["docker", "ps", "--filter", "name=trino-python-client-tests-"]
203-
)
191+
subprocess.check_call(["docker", "ps", "--filter", "name=trino-python-client-tests-"])
204192

205193

206194
@cli.command()

0 commit comments

Comments
 (0)