Skip to content

Commit

Permalink
Added black (code formatting) and isort (sorting imports)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdesmet committed Aug 19, 2022
1 parent 88ad0bc commit 073acb7
Show file tree
Hide file tree
Showing 27 changed files with 831 additions and 672 deletions.
11 changes: 11 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
12 changes: 12 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,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
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import re
import textwrap

from setuptools import setup, find_packages
from setuptools import find_packages, setup

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

Expand All @@ -39,6 +39,9 @@
"pytest",
"pytest-runner",
"click",
"pre-commit",
"black",
"isort",
]

setup(
Expand Down Expand Up @@ -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,
Expand Down
26 changes: 7 additions & 19 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
from uuid import uuid4

import click
import trino.logging
import pytest
from trino.client import TrinoQuery, TrinoRequest, ClientSession
from trino.constants import DEFAULT_PORT

import trino.logging
from trino.client import ClientSession, TrinoQuery, TrinoRequest
from trino.constants import DEFAULT_PORT

logger = trino.logging.get_logger(__name__)

Expand Down Expand Up @@ -64,13 +64,7 @@ def start_trino(image_tag=None):


def wait_for_trino_workers(host, port, timeout=180):
request = TrinoRequest(
host=host,
port=port,
client_session=ClientSession(
user="test_fixture"
)
)
request = TrinoRequest(host=host, port=port, client_session=ClientSession(user="test_fixture"))
sql = "SELECT state FROM system.runtime.nodes"
t0 = time.time()
while True:
Expand Down Expand Up @@ -116,9 +110,7 @@ def start_trino_and_wait(image_tag=None):
if host:
port = os.environ.get("TRINO_RUNNING_PORT", DEFAULT_PORT)
else:
container_id, proc, host, port = start_local_trino_server(
image_tag
)
container_id, proc, host, port = start_local_trino_server(image_tag)

print("trino.server.hostname {}".format(host))
print("trino.server.port {}".format(port))
Expand Down Expand Up @@ -167,9 +159,7 @@ def cli():
pass


@click.option(
"--cache/--no-cache", default=True, help="enable/disable Docker build cache"
)
@click.option("--cache/--no-cache", default=True, help="enable/disable Docker build cache")
@click.command()
def trino_server():
container_id, _, _, _ = start_trino_and_wait()
Expand Down Expand Up @@ -198,9 +188,7 @@ def trino_cli(container_id=None):

@cli.command("list")
def list_():
subprocess.check_call(
["docker", "ps", "--filter", "name=trino-python-client-tests-"]
)
subprocess.check_call(["docker", "ps", "--filter", "name=trino-python-client-tests-"])


@cli.command()
Expand Down
Loading

0 comments on commit 073acb7

Please sign in to comment.