Skip to content

Commit

Permalink
chore: cleanup noxfile and use isort (#966)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwotherspoon authored Jan 11, 2024
1 parent 43d7ad6 commit 3e2bfbc
Show file tree
Hide file tree
Showing 21 changed files with 135 additions and 110 deletions.
4 changes: 0 additions & 4 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[mypy]
python_version = 3.8
warn_unused_configs = True
plugins = sqlmypy
namespace_packages = True

[mypy-google.auth.*]
Expand All @@ -21,6 +20,3 @@ ignore_missing_imports = True

[mypy-pytest]
ignore_missing_imports = True

[mypy-OpenSSL]
ignore_missing_imports = True
4 changes: 2 additions & 2 deletions google/cloud/sql/connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
limitations under the License.
"""

from google.cloud.sql.connector.connector import Connector, create_async_connector
from google.cloud.sql.connector.connector import Connector
from google.cloud.sql.connector.connector import create_async_connector
from google.cloud.sql.connector.instance import IPTypes
from google.cloud.sql.connector.version import __version__


__all__ = ["__version__", "create_async_connector", "Connector", "IPTypes"]
15 changes: 6 additions & 9 deletions google/cloud/sql/connector/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@
from typing import Any, Dict, Optional, Type, TYPE_CHECKING

import google.cloud.sql.connector.asyncpg as asyncpg
from google.cloud.sql.connector.exceptions import (
ConnectorLoopError,
DnsNameResolutionError,
)
from google.cloud.sql.connector.instance import (
Instance,
IPTypes,
)
from google.cloud.sql.connector.exceptions import ConnectorLoopError
from google.cloud.sql.connector.exceptions import DnsNameResolutionError
from google.cloud.sql.connector.instance import Instance
from google.cloud.sql.connector.instance import IPTypes
import google.cloud.sql.connector.pg8000 as pg8000
import google.cloud.sql.connector.pymysql as pymysql
import google.cloud.sql.connector.pytds as pytds
from google.cloud.sql.connector.utils import format_database_user, generate_keys
from google.cloud.sql.connector.utils import format_database_user
from google.cloud.sql.connector.utils import generate_keys

if TYPE_CHECKING:
from google.auth.credentials import Credentials
Expand Down
33 changes: 12 additions & 21 deletions google/cloud/sql/connector/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,22 @@
import re
import ssl
from tempfile import TemporaryDirectory
from typing import (
Any,
Dict,
Optional,
Tuple,
TYPE_CHECKING,
)
from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING

import aiohttp

from google.auth.credentials import Credentials
from google.cloud.sql.connector.exceptions import (
AutoIAMAuthNotSupported,
CloudSQLIPTypeError,
CredentialsTypeError,
TLSVersionError,
)

from google.cloud.sql.connector.exceptions import AutoIAMAuthNotSupported
from google.cloud.sql.connector.exceptions import CloudSQLIPTypeError
from google.cloud.sql.connector.exceptions import CredentialsTypeError
from google.cloud.sql.connector.exceptions import TLSVersionError
from google.cloud.sql.connector.rate_limiter import AsyncRateLimiter
from google.cloud.sql.connector.refresh_utils import (
_get_ephemeral,
_get_metadata,
_is_valid,
_seconds_until_refresh,
)
from google.cloud.sql.connector.utils import _auth_init, write_to_file
from google.cloud.sql.connector.refresh_utils import _get_ephemeral
from google.cloud.sql.connector.refresh_utils import _get_metadata
from google.cloud.sql.connector.refresh_utils import _is_valid
from google.cloud.sql.connector.refresh_utils import _seconds_until_refresh
from google.cloud.sql.connector.utils import _auth_init
from google.cloud.sql.connector.utils import write_to_file
from google.cloud.sql.connector.version import __version__ as version

if TYPE_CHECKING:
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/sql/connector/refresh_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

from cryptography.hazmat.backends import default_backend
from cryptography.x509 import load_pem_x509_certificate

from google.auth.credentials import Credentials, Scoped
from google.auth.credentials import Credentials
from google.auth.credentials import Scoped
import google.auth.transport.requests

if TYPE_CHECKING:
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/sql/connector/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa

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


async def generate_keys() -> Tuple[bytes, str]:
Expand Down
72 changes: 59 additions & 13 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@


from __future__ import absolute_import

import os

import nox

BLACK_PATHS = ["google", "tests"]
BLACK_VERSION = "black==23.12.1"
ISORT_VERSION = "isort==5.13.2"
MYPY_VERSION = "mypy==0.982"

LINT_PATHS = ["google", "tests", "noxfile.py", "setup.py"]

if os.path.exists("samples"):
BLACK_PATHS.append("samples")
TEST_PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11"]


@nox.session
Expand All @@ -31,22 +36,63 @@ def lint(session):
Returns a failure if the linters find linting errors or sufficiently
serious code quality issues.
"""
session.install("-r", "requirements-test.txt")
session.install("-r", "requirements.txt")
session.install("flake8-import-order")
session.run("black", "--check", *BLACK_PATHS)
session.install(
"flake8",
"flake8-annotations",
MYPY_VERSION,
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",
)
session.run("mypy", "-p", "google", "--show-traceback")
session.run(
"mypy",
"-p",
"google",
"--install-types",
"--non-interactive",
"--show-traceback",
)
session.run("python", "setup.py", "sdist")
session.run("twine", "check", "dist/*")


@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,
)


def default(session, path):
# Install all test dependencies, then install this package in-place.
session.install("-r", "requirements-test.txt")
Expand All @@ -55,7 +101,7 @@ def default(session, path):
# Run py.test against the unit tests.
session.run(
"pytest",
"--cov=google/cloud/sql/connector",
"--cov=google.cloud.sql.connector",
"-v",
"--cov-config=.coveragerc",
"--cov-report=",
Expand All @@ -66,17 +112,17 @@ def default(session, path):
)


@nox.session(python=["3.8", "3.9", "3.10", "3.11"])
@nox.session(python=TEST_PYTHON_VERSIONS)
def unit(session):
default(session, os.path.join("tests", "unit"))


@nox.session(python=["3.8", "3.9", "3.10", "3.11"])
@nox.session(python=TEST_PYTHON_VERSIONS)
def system(session):
default(session, os.path.join("tests", "system"))


@nox.session(python=["3.8", "3.9", "3.10", "3.11"])
@nox.session(python=TEST_PYTHON_VERSIONS)
def test(session):
default(session, os.path.join("tests", "unit"))
default(session, os.path.join("tests", "system"))
7 changes: 0 additions & 7 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ pytest-cov==4.1.0
pytest-asyncio==0.23.3
SQLAlchemy==2.0.25
sqlalchemy-pytds==1.0.0
flake8==5.0.4
flake8-annotations==2.9.1
black==23.12.1
mypy==0.982
sqlalchemy-stubs==0.4
types-PyMySQL==1.1.0.1
types-mock==5.1.0.3
twine==4.0.2
PyMySQL==1.1.0
pg8000==1.30.4
asyncpg==0.29.0
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 = "cloud-sql-python-connector"
description = (
Expand Down Expand Up @@ -45,11 +45,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
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
from typing import Any, AsyncGenerator, Generator, Tuple

from aioresponses import aioresponses
from google.auth.credentials import Credentials
from google.auth.credentials import with_scopes_if_required
from google.oauth2 import service_account
from mock import patch
import pytest # noqa F401 Needed to run the tests
from unit.mocks import FakeCSQLInstance # type: ignore

from google.auth.credentials import Credentials, with_scopes_if_required
from google.cloud.sql.connector import Connector
from google.cloud.sql.connector.instance import Instance
from google.cloud.sql.connector.utils import generate_keys
from google.oauth2 import service_account

SCOPES = ["https://www.googleapis.com/auth/sqlservice.admin"]

Expand Down
3 changes: 2 additions & 1 deletion tests/system/test_asyncpg_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import asyncpg
import pytest
import sqlalchemy
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
from sqlalchemy.ext.asyncio import AsyncEngine
from sqlalchemy.ext.asyncio import create_async_engine

from google.cloud.sql.connector import Connector

Expand Down
3 changes: 2 additions & 1 deletion tests/system/test_asyncpg_iam_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import asyncpg
import pytest
import sqlalchemy
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
from sqlalchemy.ext.asyncio import AsyncEngine
from sqlalchemy.ext.asyncio import create_async_engine

from google.cloud.sql.connector import Connector

Expand Down
6 changes: 2 additions & 4 deletions tests/system/test_connector_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
import os
from threading import Thread

import google.auth
import pymysql
import pytest
import sqlalchemy

import google.auth
from google.cloud.sql.connector import Connector
from google.cloud.sql.connector.exceptions import (
AutoIAMAuthNotSupported,
)
from google.cloud.sql.connector.exceptions import AutoIAMAuthNotSupported


def init_connection_engine(
Expand Down
3 changes: 2 additions & 1 deletion tests/system/test_ip_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import pytest
import sqlalchemy

from google.cloud.sql.connector import Connector, IPTypes
from google.cloud.sql.connector import Connector
from google.cloud.sql.connector import IPTypes

table_name = f"books_{uuid.uuid4().hex}"

Expand Down
6 changes: 4 additions & 2 deletions tests/unit/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@

from cryptography import x509
from cryptography.hazmat.backends import default_backend
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

from google.cloud.sql.connector import IPTypes
from google.cloud.sql.connector.instance import ConnectionInfo
from google.cloud.sql.connector.utils import generate_keys, write_to_file
from google.cloud.sql.connector.utils import generate_keys
from google.cloud.sql.connector.utils import write_to_file


class MockInstance:
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_asyncpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import ssl
from typing import Any

from mock import AsyncMock, patch
from mock import AsyncMock
from mock import patch
import pytest

from google.cloud.sql.connector.asyncpg import connect
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
from mocks import MockInstance
import pytest # noqa F401 Needed to run the tests

from google.cloud.sql.connector import Connector, create_async_connector, IPTypes
from google.cloud.sql.connector import Connector
from google.cloud.sql.connector import create_async_connector
from google.cloud.sql.connector import IPTypes
from google.cloud.sql.connector.exceptions import ConnectorLoopError


Expand Down
Loading

0 comments on commit 3e2bfbc

Please sign in to comment.