Skip to content

Commit

Permalink
chore: update lint job to use isort (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwotherspoon authored Jan 11, 2024
1 parent 0a51d2f commit 3dd1b05
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 40 deletions.
1 change: 0 additions & 1 deletion google/cloud/alloydb/connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@
from google.cloud.alloydb.connector.connector import Connector
from google.cloud.alloydb.connector.version import __version__


__all__ = ["__version__", "Connector"]
2 changes: 1 addition & 1 deletion google/cloud/alloydb/connector/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from typing import List, Optional, Tuple, TYPE_CHECKING

import aiohttp

from google.auth.transport.requests import Request

from google.cloud.alloydb.connector.version import __version__ as version

if TYPE_CHECKING:
Expand Down
1 change: 1 addition & 0 deletions google/cloud/alloydb/connector/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from google.auth import default
from google.auth.credentials import with_scopes_if_required

from google.cloud.alloydb.connector.client import AlloyDBClient
from google.cloud.alloydb.connector.instance import Instance
import google.cloud.alloydb.connector.pg8000 as pg8000
Expand Down
10 changes: 5 additions & 5 deletions google/cloud/alloydb/connector/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@

from google.cloud.alloydb.connector.exceptions import RefreshError
from google.cloud.alloydb.connector.rate_limiter import AsyncRateLimiter
from google.cloud.alloydb.connector.refresh import (
_is_valid,
_seconds_until_refresh,
RefreshResult,
)
from google.cloud.alloydb.connector.refresh import _is_valid
from google.cloud.alloydb.connector.refresh import _seconds_until_refresh
from google.cloud.alloydb.connector.refresh import RefreshResult

if TYPE_CHECKING:
import ssl

from cryptography.hazmat.primitives.asymmetric import rsa

from google.cloud.alloydb.connector.client import AlloyDBClient

logger = logging.getLogger(name=__name__)
Expand Down
3 changes: 2 additions & 1 deletion google/cloud/alloydb/connector/refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from __future__ import annotations

import asyncio
from datetime import datetime, timezone
from datetime import datetime
from datetime import timezone
import logging
import ssl
from tempfile import TemporaryDirectory
Expand Down
39 changes: 34 additions & 5 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
# limitations under the License.

from __future__ import absolute_import

import os

import nox


BLACK_VERSION = "black==22.3.0"
BLACK_VERSION = "black==23.12.1"
ISORT_VERSION = "isort==5.13.2"
LINT_PATHS = ["google", "tests", "noxfile.py", "setup.py"]

SYSTEM_TEST_PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11", "3.12"]
Expand All @@ -36,22 +37,29 @@ def lint(session):
session.install("-r", "requirements.txt")
session.install(
"flake8",
"flake8-import-order",
"flake8-annotations",
"mypy",
BLACK_VERSION,
ISORT_VERSION,
"types-setuptools",
"twine",
)
session.run(
"isort",
"--fss",
"--check-only",
"--diff",
"--profile=google",
*LINT_PATHS,
)
session.run(
"black",
"--check",
"--diff",
*LINT_PATHS,
)
session.run(
"flake8",
"--import-order-style=google",
"--application-import-names=google,tests",
"google",
"tests",
)
Expand Down Expand Up @@ -80,6 +88,27 @@ def blacken(session):
)


@nox.session()
def format(session):
"""
Run isort to sort imports. Then run black
to format code to uniform standard.
"""
session.install(BLACK_VERSION, ISORT_VERSION)
# Use the --fss option to sort imports using strict alphabetical order.
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sectionss
session.run(
"isort",
"--fss",
"--profile=google",
*LINT_PATHS,
)
session.run(
"black",
*LINT_PATHS,
)


@nox.session()
def cover(session):
"""Run the final coverage report.
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import io
import os

from setuptools import find_namespace_packages, setup
import setuptools

name = "google-cloud-alloydb-connector"
description = "A Python client library for connecting securely to your Google Cloud AlloyDB instances."
Expand Down Expand Up @@ -43,11 +43,13 @@
# Only include packages under the 'google' namespace. Do not include tests,
# samples, etc.
packages = [
package for package in find_namespace_packages() if package.startswith("google")
package
for package in setuptools.find_namespace_packages()
if package.startswith("google")
]


setup(
setuptools.setup(
name=name,
version=version,
description=description,
Expand Down
1 change: 0 additions & 1 deletion tests/system/test_native_asyncpg_direct_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

# [START alloydb_native_asyncpg_connect_iam_authn_direct]
import asyncpg

import google.auth
from google.auth.transport.requests import Request

Expand Down
5 changes: 2 additions & 3 deletions tests/system/test_psycopg2_direct_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
import os

# [START alloydb_psycopg2_connect_iam_authn_direct]
import sqlalchemy
from sqlalchemy import event

import google.auth
from google.auth.credentials import Credentials
from google.auth.transport.requests import Request
import sqlalchemy
from sqlalchemy import event

# [END alloydb_psycopg2_connect_iam_authn_direct]

Expand Down
7 changes: 3 additions & 4 deletions tests/system/test_sqlalchemy_asyncpg_direct_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
import os

# [START alloydb_sqlalchemy_asyncpg_connect_iam_authn_direct]
import sqlalchemy
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy import event

import google.auth
from google.auth.credentials import Credentials
from google.auth.transport.requests import Request
import sqlalchemy
from sqlalchemy import event
from sqlalchemy.ext.asyncio import create_async_engine

# [END alloydb_sqlalchemy_asyncpg_connect_iam_authn_direct]

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

from mocks import (
FakeCredentials,
FakeInstance,
)
from mocks import FakeCredentials
from mocks import FakeInstance
import pytest


Expand Down
7 changes: 5 additions & 2 deletions tests/unit/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime, timedelta, timezone
from datetime import datetime
from datetime import timedelta
from datetime import timezone
from typing import Any, Callable, List, Optional, Tuple

from cryptography import x509
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.x509.oid import NameOID

Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from threading import Thread

from mock import patch
from mocks import FakeAlloyDBClient, FakeCredentials
from mocks import FakeAlloyDBClient
from mocks import FakeCredentials
import pytest

from google.cloud.alloydb.connector import Connector
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
# limitations under the License.

import asyncio
from datetime import datetime, timedelta
from datetime import datetime
from datetime import timedelta
from typing import Tuple

import aiohttp
from mocks import FakeAlloyDBClient
import pytest

from google.cloud.alloydb.connector.exceptions import RefreshError
from google.cloud.alloydb.connector.instance import _parse_instance_uri, Instance
from google.cloud.alloydb.connector.refresh import _is_valid, RefreshResult
from google.cloud.alloydb.connector.instance import _parse_instance_uri
from google.cloud.alloydb.connector.instance import Instance
from google.cloud.alloydb.connector.refresh import _is_valid
from google.cloud.alloydb.connector.refresh import RefreshResult
from google.cloud.alloydb.connector.utils import generate_keys


Expand Down
13 changes: 7 additions & 6 deletions tests/unit/test_refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime, timedelta, timezone
from datetime import datetime
from datetime import timedelta
from datetime import timezone
import ssl

from cryptography import x509
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from mocks import FakeInstance

from google.cloud.alloydb.connector.refresh import (
_seconds_until_refresh,
RefreshResult,
)
from google.cloud.alloydb.connector.refresh import _seconds_until_refresh
from google.cloud.alloydb.connector.refresh import RefreshResult


def test_seconds_until_refresh_over_1_hour() -> None:
Expand Down

0 comments on commit 3dd1b05

Please sign in to comment.