From 9b249aadb679e1f9ba2a748a6866ed50c6af9a7a Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 19 Apr 2025 10:21:21 -0400 Subject: [PATCH 1/4] chore: switch to ruff linter --- noxfile.py | 45 +++++++++------------------------------------ pyproject.toml | 6 ++++++ 2 files changed, 15 insertions(+), 36 deletions(-) diff --git a/noxfile.py b/noxfile.py index e54fd3987..d3928688f 100644 --- a/noxfile.py +++ b/noxfile.py @@ -20,8 +20,6 @@ import nox -BLACK_VERSION = "black==24.10.0" -ISORT_VERSION = "isort==5.13.2" LINT_PATHS = ["google", "tests", "noxfile.py"] @@ -36,32 +34,16 @@ def lint(session): """ session.install("-r", "requirements.txt") session.install( - "flake8", - "flake8-annotations", + "ruff", "mypy", - BLACK_VERSION, - ISORT_VERSION, "twine", "build", "importlib_metadata==7.2.1", ) session.run( - "isort", - "--fss", - "--check-only", - "--diff", - "--profile=black", - "--force-single-line-imports", - "--dont-order-by-type", - "--single-line-exclusions=typing", - "-w=88", - *LINT_PATHS, - ) - session.run("black", "--check", "--diff", *LINT_PATHS) - session.run( - "flake8", - "google", - "tests", + "ruff", + "check", + *LINT_PATHS, ) session.run( "mypy", @@ -75,28 +57,19 @@ def lint(session): session.run("python", "-m", "build", "--sdist") session.run("twine", "check", "--strict", "dist/*") - @nox.session() def format(session): """ - Run isort to sort imports. Then run black + Run isort to sort imports. Then run black to format code to uniform standard. """ - session.install(BLACK_VERSION, ISORT_VERSION) + session.install("ruff") # 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=black", - "--force-single-line-imports", - "--dont-order-by-type", - "--single-line-exclusions=typing", - "-w=88", - *LINT_PATHS, - ) - session.run( - "black", + "ruff", + "check", + "--fix", *LINT_PATHS, ) diff --git a/pyproject.toml b/pyproject.toml index 8a694369b..04885a441 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,3 +82,9 @@ exclude = ['docs/*', 'samples/*'] [tool.pytest.ini_options] asyncio_mode = "auto" + +[tool.ruff] +line-length = 88 + +[tool.ruff.format] +quote-style = "double" \ No newline at end of file From 8eb5bf4abc861e638a965574ed55768fdc077c6d Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 24 Apr 2025 14:16:00 -0400 Subject: [PATCH 2/4] chore: update isort lint config --- pyproject.toml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 04885a441..d942ef4a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -83,8 +83,14 @@ exclude = ['docs/*', 'samples/*'] [tool.pytest.ini_options] asyncio_mode = "auto" -[tool.ruff] -line-length = 88 +[tool.ruff.lint] +extend-select = ["I"] + +[tool.ruff.lint.isort] +force-single-line = true +force-sort-within-sections = true +order-by-type = false +single-line-exclusions = ["typing"] [tool.ruff.format] quote-style = "double" \ No newline at end of file From d6028b9c71481912e817697ef4b2aae4ffd9820d Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 6 May 2025 10:51:17 -0400 Subject: [PATCH 3/4] chore: update noxfile comments --- noxfile.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/noxfile.py b/noxfile.py index d3928688f..f04756241 100644 --- a/noxfile.py +++ b/noxfile.py @@ -20,7 +20,6 @@ import nox - LINT_PATHS = ["google", "tests", "noxfile.py"] TEST_PYTHON_VERSIONS = ["3.9", "3.10", "3.11", "3.12", "3.13"] @@ -60,12 +59,9 @@ def lint(session): @nox.session() def format(session): """ - Run isort to sort imports. Then run black - to format code to uniform standard. + Run Ruff to automatically format code. """ session.install("ruff") - # 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( "ruff", "check", From 4196ae2365bb8a17e77825591903197d7819876d Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 6 May 2025 10:52:00 -0400 Subject: [PATCH 4/4] chore: run Ruff formatter --- google/cloud/sql/connector/client.py | 2 +- google/cloud/sql/connector/connector.py | 1 - google/cloud/sql/connector/refresh_utils.py | 1 + google/cloud/sql/connector/resolver.py | 4 ++-- pyproject.toml | 2 +- tests/unit/mocks.py | 2 +- tests/unit/test_client.py | 2 +- tests/unit/test_connector.py | 2 +- tests/unit/test_refresh_utils.py | 8 ++++---- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/google/cloud/sql/connector/client.py b/google/cloud/sql/connector/client.py index 11508ce17..2e1fbc20d 100644 --- a/google/cloud/sql/connector/client.py +++ b/google/cloud/sql/connector/client.py @@ -22,9 +22,9 @@ import aiohttp from cryptography.hazmat.backends import default_backend from cryptography.x509 import load_pem_x509_certificate + from google.auth.credentials import TokenState from google.auth.transport import requests - from google.cloud.sql.connector.connection_info import ConnectionInfo from google.cloud.sql.connector.connection_name import ConnectionName from google.cloud.sql.connector.exceptions import AutoIAMAuthNotSupported diff --git a/google/cloud/sql/connector/connector.py b/google/cloud/sql/connector/connector.py index c76092a40..05eaa51df 100755 --- a/google/cloud/sql/connector/connector.py +++ b/google/cloud/sql/connector/connector.py @@ -28,7 +28,6 @@ import google.auth from google.auth.credentials import Credentials from google.auth.credentials import with_scopes_if_required - import google.cloud.sql.connector.asyncpg as asyncpg from google.cloud.sql.connector.client import CloudSQLClient from google.cloud.sql.connector.enums import DriverMapping diff --git a/google/cloud/sql/connector/refresh_utils.py b/google/cloud/sql/connector/refresh_utils.py index a90d40536..447c0b480 100644 --- a/google/cloud/sql/connector/refresh_utils.py +++ b/google/cloud/sql/connector/refresh_utils.py @@ -24,6 +24,7 @@ from typing import Any, Callable import aiohttp + from google.auth.credentials import Credentials from google.auth.credentials import Scoped import google.auth.transport.requests diff --git a/google/cloud/sql/connector/resolver.py b/google/cloud/sql/connector/resolver.py index 7d717ca05..7143c1047 100644 --- a/google/cloud/sql/connector/resolver.py +++ b/google/cloud/sql/connector/resolver.py @@ -14,11 +14,11 @@ import dns.asyncresolver +from google.cloud.sql.connector.connection_name import _is_valid_domain +from google.cloud.sql.connector.connection_name import _parse_connection_name from google.cloud.sql.connector.connection_name import ( _parse_connection_name_with_domain_name, ) -from google.cloud.sql.connector.connection_name import _is_valid_domain -from google.cloud.sql.connector.connection_name import _parse_connection_name from google.cloud.sql.connector.connection_name import ConnectionName from google.cloud.sql.connector.exceptions import DnsResolutionError diff --git a/pyproject.toml b/pyproject.toml index d942ef4a7..cbf0dd10f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -93,4 +93,4 @@ order-by-type = false single-line-exclusions = ["typing"] [tool.ruff.format] -quote-style = "double" \ No newline at end of file +quote-style = "double" diff --git a/tests/unit/mocks.py b/tests/unit/mocks.py index 66bf64a32..28c2fc307 100644 --- a/tests/unit/mocks.py +++ b/tests/unit/mocks.py @@ -31,10 +31,10 @@ from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.x509.oid import NameOID + from google.auth import _helpers from google.auth.credentials import Credentials from google.auth.credentials import TokenState - from google.cloud.sql.connector.connector import _DEFAULT_UNIVERSE_DOMAIN from google.cloud.sql.connector.utils import generate_keys from google.cloud.sql.connector.utils import write_to_file diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index cfe509470..2ecefe220 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -17,10 +17,10 @@ from aiohttp import ClientResponseError from aioresponses import aioresponses -from google.auth.credentials import Credentials from mocks import FakeCredentials import pytest +from google.auth.credentials import Credentials from google.cloud.sql.connector.client import CloudSQLClient from google.cloud.sql.connector.utils import generate_keys from google.cloud.sql.connector.version import __version__ as version diff --git a/tests/unit/test_connector.py b/tests/unit/test_connector.py index 498c947cc..157697723 100644 --- a/tests/unit/test_connector.py +++ b/tests/unit/test_connector.py @@ -19,10 +19,10 @@ from typing import Union from aiohttp import ClientResponseError -from google.auth.credentials import Credentials from mock import patch import pytest # noqa F401 Needed to run the tests +from google.auth.credentials import Credentials from google.cloud.sql.connector import Connector from google.cloud.sql.connector import create_async_connector from google.cloud.sql.connector import IPTypes diff --git a/tests/unit/test_refresh_utils.py b/tests/unit/test_refresh_utils.py index 119e92c7a..2d4cdb853 100644 --- a/tests/unit/test_refresh_utils.py +++ b/tests/unit/test_refresh_utils.py @@ -20,19 +20,19 @@ import datetime from conftest import SCOPES # type: ignore -import google.auth -from google.auth.credentials import Credentials -from google.auth.credentials import TokenState -import google.oauth2.credentials from mock import Mock from mock import patch import pytest # noqa F401 Needed to run the tests +import google.auth +from google.auth.credentials import Credentials +from google.auth.credentials import TokenState from google.cloud.sql.connector.refresh_utils import _downscope_credentials from google.cloud.sql.connector.refresh_utils import _exponential_backoff 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.refresh_utils import retry_50x +import google.oauth2.credentials @pytest.fixture