Skip to content

Commit 27f6de3

Browse files
chore: switch to ruff linter (#1289)
1 parent 1e8215a commit 27f6de3

File tree

10 files changed

+32
-51
lines changed

10 files changed

+32
-51
lines changed

google/cloud/sql/connector/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import aiohttp
2323
from cryptography.hazmat.backends import default_backend
2424
from cryptography.x509 import load_pem_x509_certificate
25+
2526
from google.auth.credentials import TokenState
2627
from google.auth.transport import requests
27-
2828
from google.cloud.sql.connector.connection_info import ConnectionInfo
2929
from google.cloud.sql.connector.connection_name import ConnectionName
3030
from google.cloud.sql.connector.exceptions import AutoIAMAuthNotSupported

google/cloud/sql/connector/connector.py

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import google.auth
2929
from google.auth.credentials import Credentials
3030
from google.auth.credentials import with_scopes_if_required
31-
3231
import google.cloud.sql.connector.asyncpg as asyncpg
3332
from google.cloud.sql.connector.client import CloudSQLClient
3433
from google.cloud.sql.connector.enums import DriverMapping

google/cloud/sql/connector/refresh_utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from typing import Any, Callable
2525

2626
import aiohttp
27+
2728
from google.auth.credentials import Credentials
2829
from google.auth.credentials import Scoped
2930
import google.auth.transport.requests

google/cloud/sql/connector/resolver.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
import dns.asyncresolver
1616

17+
from google.cloud.sql.connector.connection_name import _is_valid_domain
18+
from google.cloud.sql.connector.connection_name import _parse_connection_name
1719
from google.cloud.sql.connector.connection_name import (
1820
_parse_connection_name_with_domain_name,
1921
)
20-
from google.cloud.sql.connector.connection_name import _is_valid_domain
21-
from google.cloud.sql.connector.connection_name import _parse_connection_name
2222
from google.cloud.sql.connector.connection_name import ConnectionName
2323
from google.cloud.sql.connector.exceptions import DnsResolutionError
2424

noxfile.py

+9-40
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020

2121
import nox
2222

23-
BLACK_VERSION = "black==24.10.0"
24-
ISORT_VERSION = "isort==5.13.2"
25-
2623
LINT_PATHS = ["google", "tests", "noxfile.py"]
2724

2825
TEST_PYTHON_VERSIONS = ["3.9", "3.10", "3.11", "3.12", "3.13"]
@@ -36,32 +33,16 @@ def lint(session):
3633
"""
3734
session.install("-r", "requirements.txt")
3835
session.install(
39-
"flake8",
40-
"flake8-annotations",
36+
"ruff",
4137
"mypy",
42-
BLACK_VERSION,
43-
ISORT_VERSION,
4438
"twine",
4539
"build",
4640
"importlib_metadata==7.2.1",
4741
)
4842
session.run(
49-
"isort",
50-
"--fss",
51-
"--check-only",
52-
"--diff",
53-
"--profile=black",
54-
"--force-single-line-imports",
55-
"--dont-order-by-type",
56-
"--single-line-exclusions=typing",
57-
"-w=88",
58-
*LINT_PATHS,
59-
)
60-
session.run("black", "--check", "--diff", *LINT_PATHS)
61-
session.run(
62-
"flake8",
63-
"google",
64-
"tests",
43+
"ruff",
44+
"check",
45+
*LINT_PATHS,
6546
)
6647
session.run(
6748
"mypy",
@@ -75,28 +56,16 @@ def lint(session):
7556
session.run("python", "-m", "build", "--sdist")
7657
session.run("twine", "check", "--strict", "dist/*")
7758

78-
7959
@nox.session()
8060
def format(session):
8161
"""
82-
Run isort to sort imports. Then run black
83-
to format code to uniform standard.
62+
Run Ruff to automatically format code.
8463
"""
85-
session.install(BLACK_VERSION, ISORT_VERSION)
86-
# Use the --fss option to sort imports using strict alphabetical order.
87-
# See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sectionss
88-
session.run(
89-
"isort",
90-
"--fss",
91-
"--profile=black",
92-
"--force-single-line-imports",
93-
"--dont-order-by-type",
94-
"--single-line-exclusions=typing",
95-
"-w=88",
96-
*LINT_PATHS,
97-
)
64+
session.install("ruff")
9865
session.run(
99-
"black",
66+
"ruff",
67+
"check",
68+
"--fix",
10069
*LINT_PATHS,
10170
)
10271

pyproject.toml

+12
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,15 @@ exclude = ['docs/*', 'samples/*']
8282

8383
[tool.pytest.ini_options]
8484
asyncio_mode = "auto"
85+
86+
[tool.ruff.lint]
87+
extend-select = ["I"]
88+
89+
[tool.ruff.lint.isort]
90+
force-single-line = true
91+
force-sort-within-sections = true
92+
order-by-type = false
93+
single-line-exclusions = ["typing"]
94+
95+
[tool.ruff.format]
96+
quote-style = "double"

tests/unit/mocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
from cryptography.hazmat.primitives import serialization
3232
from cryptography.hazmat.primitives.asymmetric import rsa
3333
from cryptography.x509.oid import NameOID
34+
3435
from google.auth import _helpers
3536
from google.auth.credentials import Credentials
3637
from google.auth.credentials import TokenState
37-
3838
from google.cloud.sql.connector.connector import _DEFAULT_UNIVERSE_DOMAIN
3939
from google.cloud.sql.connector.utils import generate_keys
4040
from google.cloud.sql.connector.utils import write_to_file

tests/unit/test_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
from aiohttp import ClientResponseError
1919
from aioresponses import aioresponses
20-
from google.auth.credentials import Credentials
2120
from mocks import FakeCredentials
2221
import pytest
2322

23+
from google.auth.credentials import Credentials
2424
from google.cloud.sql.connector.client import CloudSQLClient
2525
from google.cloud.sql.connector.utils import generate_keys
2626
from google.cloud.sql.connector.version import __version__ as version

tests/unit/test_connector.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
from typing import Union
2020

2121
from aiohttp import ClientResponseError
22-
from google.auth.credentials import Credentials
2322
from mock import patch
2423
import pytest # noqa F401 Needed to run the tests
2524

25+
from google.auth.credentials import Credentials
2626
from google.cloud.sql.connector import Connector
2727
from google.cloud.sql.connector import create_async_connector
2828
from google.cloud.sql.connector import IPTypes

tests/unit/test_refresh_utils.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@
2020
import datetime
2121

2222
from conftest import SCOPES # type: ignore
23-
import google.auth
24-
from google.auth.credentials import Credentials
25-
from google.auth.credentials import TokenState
26-
import google.oauth2.credentials
2723
from mock import Mock
2824
from mock import patch
2925
import pytest # noqa F401 Needed to run the tests
3026

27+
import google.auth
28+
from google.auth.credentials import Credentials
29+
from google.auth.credentials import TokenState
3130
from google.cloud.sql.connector.refresh_utils import _downscope_credentials
3231
from google.cloud.sql.connector.refresh_utils import _exponential_backoff
3332
from google.cloud.sql.connector.refresh_utils import _is_valid
3433
from google.cloud.sql.connector.refresh_utils import _seconds_until_refresh
3534
from google.cloud.sql.connector.refresh_utils import retry_50x
35+
import google.oauth2.credentials
3636

3737

3838
@pytest.fixture

0 commit comments

Comments
 (0)