Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isort (for sorting imports) #227

Merged
merged 3 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ See [Commits and pull requests](https://github.com/trinodb/trino/blob/master/.gi

To run linting and formatting checks before opening a PR: `pip install pre-commit && pre-commit run --all-files`

Code can also be automatically checked on commit by a [pre-commit](https://pre-commit.com/) git hook by executing `pre-commit install`.

In addition to that you should also adhere to the following:

### Readability
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ repos:
additional_dependencies:
- "types-pytz"
- "types-requests"

- repo: https://github.com/pycqa/isort
rev: 5.6.4
hooks:
- id: isort
args: [ "--profile", "black"]
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting changes should be in a separate commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A separate commit would fail the build if ran by itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Make it the first commit.


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

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

setup(
Expand Down Expand Up @@ -76,7 +79,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
6 changes: 3 additions & 3 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
4 changes: 2 additions & 2 deletions tests/integration/test_dbapi_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import math
from datetime import datetime, time, date, timezone, timedelta
from datetime import date, datetime, time, timedelta, timezone
from decimal import Decimal

import pytest
Expand All @@ -20,7 +20,7 @@
import trino
from tests.integration.conftest import trino_version
from trino import constants
from trino.exceptions import TrinoQueryError, TrinoUserError, NotSupportedError
from trino.exceptions import NotSupportedError, TrinoQueryError, TrinoUserError
from trino.transaction import IsolationLevel


Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_sqlalchemy_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# limitations under the License
import pytest
import sqlalchemy as sqla
from sqlalchemy.sql import and_, or_, not_
from sqlalchemy.sql import and_, not_, or_
from sqlalchemy_utils import create_view

from tests.unit.conftest import sqlalchemy_version
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/test_types_integration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import math
import pytest
from decimal import Decimal

import pytest

import trino


Expand Down
3 changes: 2 additions & 1 deletion tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest
from unittest.mock import MagicMock, patch

import pytest


@pytest.fixture(scope="session")
def sample_post_response_data():
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/sqlalchemy/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import pytest
from sqlalchemy.sql.sqltypes import ARRAY

from trino.sqlalchemy.datatype import MAP, ROW, SQLType, TIMESTAMP, TIME
from trino.sqlalchemy.datatype import MAP, ROW, TIME, TIMESTAMP, SQLType


@pytest.fixture(scope="session")
Expand Down
10 changes: 1 addition & 9 deletions tests/unit/sqlalchemy/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest
from sqlalchemy import (
Column,
insert,
Integer,
MetaData,
select,
String,
Table,
)
from sqlalchemy import Column, Integer, MetaData, String, Table, insert, select
from sqlalchemy.schema import CreateTable
from sqlalchemy.sql import column, table

Expand Down
16 changes: 2 additions & 14 deletions tests/unit/sqlalchemy/test_datatype_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,11 @@
# limitations under the License.
import pytest
from sqlalchemy.exc import UnsupportedCompilationError
from sqlalchemy.sql.sqltypes import (
CHAR,
VARCHAR,
ARRAY,
INTEGER,
DECIMAL,
DATE
)
from sqlalchemy.sql.sqltypes import ARRAY, CHAR, DATE, DECIMAL, INTEGER, VARCHAR
from sqlalchemy.sql.type_api import TypeEngine

from trino.sqlalchemy import datatype
from trino.sqlalchemy.datatype import (
MAP,
ROW,
TIME,
TIMESTAMP
)
from trino.sqlalchemy.datatype import MAP, ROW, TIME, TIMESTAMP


@pytest.mark.parametrize(
Expand Down
10 changes: 7 additions & 3 deletions tests/unit/sqlalchemy/test_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
from unittest import mock

import pytest
from sqlalchemy.engine.url import make_url, URL
from sqlalchemy.engine.url import URL, make_url

from trino.auth import BasicAuthentication
from trino.dbapi import Connection
from trino.sqlalchemy.dialect import CertificateAuthentication, JWTAuthentication, TrinoDialect
from trino.transaction import IsolationLevel
from trino.sqlalchemy import URL as trino_url
from trino.sqlalchemy.dialect import (
CertificateAuthentication,
JWTAuthentication,
TrinoDialect,
)
from trino.transaction import IsolationLevel


class TestTrinoDialect:
Expand Down
27 changes: 21 additions & 6 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import threading
import time
import uuid
from typing import Optional, Dict
from typing import Dict, Optional
from unittest import mock
from urllib.parse import urlparse

Expand All @@ -24,13 +24,28 @@
from requests_kerberos.exceptions import KerberosExchangeError

import trino.exceptions
from tests.unit.oauth_test_utils import RedirectHandler, GetTokenCallback, PostStatementCallback, \
MultithreadedTokenServer, _post_statement_requests, _get_token_requests, REDIRECT_RESOURCE, TOKEN_RESOURCE, \
SERVER_ADDRESS
from tests.unit.oauth_test_utils import (
REDIRECT_RESOURCE,
SERVER_ADDRESS,
TOKEN_RESOURCE,
GetTokenCallback,
MultithreadedTokenServer,
PostStatementCallback,
RedirectHandler,
_get_token_requests,
_post_statement_requests,
)
from trino import constants
from trino.auth import KerberosAuthentication, _OAuth2TokenBearer
from trino.client import TrinoQuery, TrinoRequest, TrinoResult, ClientSession, _DelayExponential, _retry_with, \
_RetryWithExponentialBackoff
from trino.client import (
ClientSession,
TrinoQuery,
TrinoRequest,
TrinoResult,
_DelayExponential,
_retry_with,
_RetryWithExponentialBackoff,
)


@mock.patch("trino.client.TrinoRequest.http")
Expand Down
12 changes: 10 additions & 2 deletions tests/unit/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@
from httpretty import httprettified
from requests import Session

from tests.unit.oauth_test_utils import _post_statement_requests, _get_token_requests, RedirectHandler, \
GetTokenCallback, REDIRECT_RESOURCE, TOKEN_RESOURCE, PostStatementCallback, SERVER_ADDRESS
from tests.unit.oauth_test_utils import (
REDIRECT_RESOURCE,
SERVER_ADDRESS,
TOKEN_RESOURCE,
GetTokenCallback,
PostStatementCallback,
RedirectHandler,
_get_token_requests,
_post_statement_requests,
)
from trino import constants
from trino.auth import OAuth2Authentication
from trino.dbapi import connect
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from trino.client import get_header_values, get_session_property_values
from trino import constants
from trino.client import get_header_values, get_session_property_values


def test_get_header_values():
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from trino.transaction import IsolationLevel
import pytest

from trino.transaction import IsolationLevel


def test_isolation_level_levels() -> None:
levels = {
Expand Down
7 changes: 1 addition & 6 deletions trino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from . import auth
from . import dbapi
from . import client
from . import constants
from . import exceptions
from . import logging
from . import auth, client, constants, dbapi, exceptions, logging

__all__ = ['auth', 'dbapi', 'client', 'constants', 'exceptions', 'logging']

Expand Down
4 changes: 2 additions & 2 deletions trino/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
# limitations under the License.

import abc
import importlib
import json
import os
import re
import threading
import webbrowser
from typing import Optional, List, Callable
from typing import Callable, List, Optional
from urllib.parse import urlparse

from requests import Request
from requests.auth import AuthBase, extract_cookies_to_jar
from requests.utils import parse_dict_header
import importlib

import trino.logging
from trino.client import exceptions
Expand Down
1 change: 0 additions & 1 deletion trino/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from typing import Any, Optional


DEFAULT_PORT = 8080
DEFAULT_TLS_PORT = 443
DEFAULT_SOURCE = "trino-python-client"
Expand Down
23 changes: 11 additions & 12 deletions trino/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,29 @@
Fetch methods returns rows as a list of lists on purpose to let the caller
decide to convert then to a list of tuples.
"""
from decimal import Decimal
from typing import Any, List, Optional # NOQA for mypy types

import uuid
import datetime
import math
import uuid
from decimal import Decimal
from typing import Any, List, Optional # NOQA for mypy types

from trino import constants
import trino.exceptions
import trino.client
import trino.exceptions
import trino.logging
from trino.transaction import Transaction, IsolationLevel, NO_TRANSACTION
from trino import constants
from trino.exceptions import (
Warning,
Error,
InterfaceError,
DatabaseError,
DataError,
OperationalError,
Error,
IntegrityError,
InterfaceError,
InternalError,
ProgrammingError,
NotSupportedError,
OperationalError,
ProgrammingError,
Warning,
)
from trino.transaction import NO_TRANSACTION, IsolationLevel, Transaction

__all__ = [
# https://www.python.org/dev/peps/pep-0249/#globals
Expand Down
1 change: 1 addition & 0 deletions trino/sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from sqlalchemy.dialects import registry

from .util import _url as URL # noqa

registry.register("trino", "trino.sqlalchemy.dialect", "TrinoDialect")
1 change: 0 additions & 1 deletion trino/sqlalchemy/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from sqlalchemy.sql import compiler
from sqlalchemy.sql.base import DialectKWArgs


# https://trino.io/docs/current/language/reserved.html
RESERVED_WORDS = {
"alter",
Expand Down
2 changes: 1 addition & 1 deletion trino/sqlalchemy/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# limitations under the License.
import json
import re
from typing import Iterator, List, Optional, Tuple, Type, Union, Dict, Any
from typing import Any, Dict, Iterator, List, Optional, Tuple, Type, Union

from sqlalchemy import util
from sqlalchemy.sql import sqltypes
Expand Down
3 changes: 2 additions & 1 deletion trino/sqlalchemy/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from sqlalchemy.engine.default import DefaultDialect, DefaultExecutionContext
from sqlalchemy.engine.url import URL

from trino import dbapi as trino_dbapi, logging
from trino import dbapi as trino_dbapi
from trino import logging
from trino.auth import BasicAuthentication, CertificateAuthentication, JWTAuthentication
from trino.dbapi import Cursor
from trino.sqlalchemy import compiler, datatype, error
Expand Down
Loading