Skip to content

Commit 3e2bfbc

Browse files
chore: cleanup noxfile and use isort (#966)
1 parent 43d7ad6 commit 3e2bfbc

21 files changed

+135
-110
lines changed

.mypy.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[mypy]
22
python_version = 3.8
33
warn_unused_configs = True
4-
plugins = sqlmypy
54
namespace_packages = True
65

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

2221
[mypy-pytest]
2322
ignore_missing_imports = True
24-
25-
[mypy-OpenSSL]
26-
ignore_missing_imports = True

google/cloud/sql/connector/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
limitations under the License.
1515
"""
1616

17-
from google.cloud.sql.connector.connector import Connector, create_async_connector
17+
from google.cloud.sql.connector.connector import Connector
18+
from google.cloud.sql.connector.connector import create_async_connector
1819
from google.cloud.sql.connector.instance import IPTypes
1920
from google.cloud.sql.connector.version import __version__
2021

21-
2222
__all__ = ["__version__", "create_async_connector", "Connector", "IPTypes"]

google/cloud/sql/connector/connector.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@
2424
from typing import Any, Dict, Optional, Type, TYPE_CHECKING
2525

2626
import google.cloud.sql.connector.asyncpg as asyncpg
27-
from google.cloud.sql.connector.exceptions import (
28-
ConnectorLoopError,
29-
DnsNameResolutionError,
30-
)
31-
from google.cloud.sql.connector.instance import (
32-
Instance,
33-
IPTypes,
34-
)
27+
from google.cloud.sql.connector.exceptions import ConnectorLoopError
28+
from google.cloud.sql.connector.exceptions import DnsNameResolutionError
29+
from google.cloud.sql.connector.instance import Instance
30+
from google.cloud.sql.connector.instance import IPTypes
3531
import google.cloud.sql.connector.pg8000 as pg8000
3632
import google.cloud.sql.connector.pymysql as pymysql
3733
import google.cloud.sql.connector.pytds as pytds
38-
from google.cloud.sql.connector.utils import format_database_user, generate_keys
34+
from google.cloud.sql.connector.utils import format_database_user
35+
from google.cloud.sql.connector.utils import generate_keys
3936

4037
if TYPE_CHECKING:
4138
from google.auth.credentials import Credentials

google/cloud/sql/connector/instance.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,22 @@
2121
import re
2222
import ssl
2323
from tempfile import TemporaryDirectory
24-
from typing import (
25-
Any,
26-
Dict,
27-
Optional,
28-
Tuple,
29-
TYPE_CHECKING,
30-
)
24+
from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING
3125

3226
import aiohttp
33-
3427
from google.auth.credentials import Credentials
35-
from google.cloud.sql.connector.exceptions import (
36-
AutoIAMAuthNotSupported,
37-
CloudSQLIPTypeError,
38-
CredentialsTypeError,
39-
TLSVersionError,
40-
)
28+
29+
from google.cloud.sql.connector.exceptions import AutoIAMAuthNotSupported
30+
from google.cloud.sql.connector.exceptions import CloudSQLIPTypeError
31+
from google.cloud.sql.connector.exceptions import CredentialsTypeError
32+
from google.cloud.sql.connector.exceptions import TLSVersionError
4133
from google.cloud.sql.connector.rate_limiter import AsyncRateLimiter
42-
from google.cloud.sql.connector.refresh_utils import (
43-
_get_ephemeral,
44-
_get_metadata,
45-
_is_valid,
46-
_seconds_until_refresh,
47-
)
48-
from google.cloud.sql.connector.utils import _auth_init, write_to_file
34+
from google.cloud.sql.connector.refresh_utils import _get_ephemeral
35+
from google.cloud.sql.connector.refresh_utils import _get_metadata
36+
from google.cloud.sql.connector.refresh_utils import _is_valid
37+
from google.cloud.sql.connector.refresh_utils import _seconds_until_refresh
38+
from google.cloud.sql.connector.utils import _auth_init
39+
from google.cloud.sql.connector.utils import write_to_file
4940
from google.cloud.sql.connector.version import __version__ as version
5041

5142
if TYPE_CHECKING:

google/cloud/sql/connector/refresh_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
from cryptography.hazmat.backends import default_backend
2525
from cryptography.x509 import load_pem_x509_certificate
26-
27-
from google.auth.credentials import Credentials, Scoped
26+
from google.auth.credentials import Credentials
27+
from google.auth.credentials import Scoped
2828
import google.auth.transport.requests
2929

3030
if TYPE_CHECKING:

google/cloud/sql/connector/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
from cryptography.hazmat.backends import default_backend
1919
from cryptography.hazmat.primitives import serialization
2020
from cryptography.hazmat.primitives.asymmetric import rsa
21-
2221
from google.auth import default
23-
from google.auth.credentials import Credentials, with_scopes_if_required
22+
from google.auth.credentials import Credentials
23+
from google.auth.credentials import with_scopes_if_required
2424

2525

2626
async def generate_keys() -> Tuple[bytes, str]:

noxfile.py

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@
1616

1717

1818
from __future__ import absolute_import
19+
1920
import os
21+
2022
import nox
2123

22-
BLACK_PATHS = ["google", "tests"]
24+
BLACK_VERSION = "black==23.12.1"
25+
ISORT_VERSION = "isort==5.13.2"
26+
MYPY_VERSION = "mypy==0.982"
27+
28+
LINT_PATHS = ["google", "tests", "noxfile.py", "setup.py"]
2329

24-
if os.path.exists("samples"):
25-
BLACK_PATHS.append("samples")
30+
TEST_PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11"]
2631

2732

2833
@nox.session
@@ -31,22 +36,63 @@ def lint(session):
3136
Returns a failure if the linters find linting errors or sufficiently
3237
serious code quality issues.
3338
"""
34-
session.install("-r", "requirements-test.txt")
3539
session.install("-r", "requirements.txt")
36-
session.install("flake8-import-order")
37-
session.run("black", "--check", *BLACK_PATHS)
40+
session.install(
41+
"flake8",
42+
"flake8-annotations",
43+
MYPY_VERSION,
44+
BLACK_VERSION,
45+
ISORT_VERSION,
46+
"types-setuptools",
47+
"twine",
48+
)
49+
session.run(
50+
"isort",
51+
"--fss",
52+
"--check-only",
53+
"--diff",
54+
"--profile=google",
55+
*LINT_PATHS,
56+
)
57+
session.run("black", "--check", "--diff", *LINT_PATHS)
3858
session.run(
3959
"flake8",
40-
"--import-order-style=google",
41-
"--application-import-names=google,tests",
4260
"google",
4361
"tests",
4462
)
45-
session.run("mypy", "-p", "google", "--show-traceback")
63+
session.run(
64+
"mypy",
65+
"-p",
66+
"google",
67+
"--install-types",
68+
"--non-interactive",
69+
"--show-traceback",
70+
)
4671
session.run("python", "setup.py", "sdist")
4772
session.run("twine", "check", "dist/*")
4873

4974

75+
@nox.session()
76+
def format(session):
77+
"""
78+
Run isort to sort imports. Then run black
79+
to format code to uniform standard.
80+
"""
81+
session.install(BLACK_VERSION, ISORT_VERSION)
82+
# Use the --fss option to sort imports using strict alphabetical order.
83+
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sectionss
84+
session.run(
85+
"isort",
86+
"--fss",
87+
"--profile=google",
88+
*LINT_PATHS,
89+
)
90+
session.run(
91+
"black",
92+
*LINT_PATHS,
93+
)
94+
95+
5096
def default(session, path):
5197
# Install all test dependencies, then install this package in-place.
5298
session.install("-r", "requirements-test.txt")
@@ -55,7 +101,7 @@ def default(session, path):
55101
# Run py.test against the unit tests.
56102
session.run(
57103
"pytest",
58-
"--cov=google/cloud/sql/connector",
104+
"--cov=google.cloud.sql.connector",
59105
"-v",
60106
"--cov-config=.coveragerc",
61107
"--cov-report=",
@@ -66,17 +112,17 @@ def default(session, path):
66112
)
67113

68114

69-
@nox.session(python=["3.8", "3.9", "3.10", "3.11"])
115+
@nox.session(python=TEST_PYTHON_VERSIONS)
70116
def unit(session):
71117
default(session, os.path.join("tests", "unit"))
72118

73119

74-
@nox.session(python=["3.8", "3.9", "3.10", "3.11"])
120+
@nox.session(python=TEST_PYTHON_VERSIONS)
75121
def system(session):
76122
default(session, os.path.join("tests", "system"))
77123

78124

79-
@nox.session(python=["3.8", "3.9", "3.10", "3.11"])
125+
@nox.session(python=TEST_PYTHON_VERSIONS)
80126
def test(session):
81127
default(session, os.path.join("tests", "unit"))
82128
default(session, os.path.join("tests", "system"))

requirements-test.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@ pytest-cov==4.1.0
44
pytest-asyncio==0.23.3
55
SQLAlchemy==2.0.25
66
sqlalchemy-pytds==1.0.0
7-
flake8==5.0.4
8-
flake8-annotations==2.9.1
9-
black==23.12.1
10-
mypy==0.982
117
sqlalchemy-stubs==0.4
12-
types-PyMySQL==1.1.0.1
13-
types-mock==5.1.0.3
14-
twine==4.0.2
158
PyMySQL==1.1.0
169
pg8000==1.30.4
1710
asyncpg==0.29.0

setup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import io
1515
import os
1616

17-
from setuptools import find_namespace_packages, setup
17+
import setuptools
1818

1919
name = "cloud-sql-python-connector"
2020
description = (
@@ -45,11 +45,13 @@
4545
# Only include packages under the 'google' namespace. Do not include tests,
4646
# samples, etc.
4747
packages = [
48-
package for package in find_namespace_packages() if package.startswith("google")
48+
package
49+
for package in setuptools.find_namespace_packages()
50+
if package.startswith("google")
4951
]
5052

5153

52-
setup(
54+
setuptools.setup(
5355
name=name,
5456
version=version,
5557
description=description,

tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@
2020
from typing import Any, AsyncGenerator, Generator, Tuple
2121

2222
from aioresponses import aioresponses
23+
from google.auth.credentials import Credentials
24+
from google.auth.credentials import with_scopes_if_required
25+
from google.oauth2 import service_account
2326
from mock import patch
2427
import pytest # noqa F401 Needed to run the tests
2528
from unit.mocks import FakeCSQLInstance # type: ignore
2629

27-
from google.auth.credentials import Credentials, with_scopes_if_required
2830
from google.cloud.sql.connector import Connector
2931
from google.cloud.sql.connector.instance import Instance
3032
from google.cloud.sql.connector.utils import generate_keys
31-
from google.oauth2 import service_account
3233

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

0 commit comments

Comments
 (0)