Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion google/cloud/alloydb/connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from google.cloud.alloydbconnector import __version__
from google.cloud.alloydbconnector import AsyncConnector
from google.cloud.alloydbconnector import Connector
from google.cloud.alloydbconnector import IPTypes
from google.cloud.alloydbconnector import RefreshStrategy
from google.cloud.alloydbconnector import __version__

__all__ = [
"__version__",
Expand Down
8 changes: 4 additions & 4 deletions google/cloud/alloydbconnector/async_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
import asyncio
import logging
from types import TracebackType
from typing import Any, Optional, TYPE_CHECKING
from typing import TYPE_CHECKING
from typing import Any
from typing import Optional

import google.auth
from google.auth.credentials import with_scopes_if_required
import google.auth.transport.requests

import google.cloud.alloydbconnector.asyncpg as asyncpg
from google.cloud.alloydbconnector.client import AlloyDBClient
from google.cloud.alloydbconnector.enums import IPTypes
Expand Down Expand Up @@ -178,8 +179,7 @@ async def connect(
cache = LazyRefreshCache(instance_uri, self._client, self._keys)
else:
logger.debug(
f"['{instance_uri}']: Refresh strategy is set to background"
" refresh"
f"['{instance_uri}']: Refresh strategy is set to background refresh"
)
cache = RefreshAheadCache(instance_uri, self._client, self._keys)
self._cache[instance_uri] = cache
Expand Down
3 changes: 2 additions & 1 deletion google/cloud/alloydbconnector/asyncpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
# limitations under the License.

import ssl
from typing import Any, TYPE_CHECKING
from typing import TYPE_CHECKING
from typing import Any

SERVER_PROXY_PORT = 5433

Expand Down
7 changes: 4 additions & 3 deletions google/cloud/alloydbconnector/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@

import asyncio
import logging
from typing import Optional, TYPE_CHECKING
from typing import TYPE_CHECKING
from typing import Optional

from cryptography import x509

from google.api_core.client_options import ClientOptions
from google.api_core.gapic_v1.client_info import ClientInfo
from google.auth.credentials import TokenState
from google.auth.transport import requests
import google.cloud.alloydb_v1beta as v1beta
from google.protobuf import duration_pb2

from google.cloud.alloydbconnector.connection_info import ConnectionInfo
from google.cloud.alloydbconnector.version import __version__ as version
from google.protobuf import duration_pb2

if TYPE_CHECKING:
from google.auth.credentials import Credentials
Expand Down
3 changes: 2 additions & 1 deletion google/cloud/alloydbconnector/connection_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from dataclasses import dataclass
import logging
import ssl
from typing import Optional, TYPE_CHECKING
from typing import TYPE_CHECKING
from typing import Optional

from aiofiles.tempfile import TemporaryDirectory

Expand Down
9 changes: 5 additions & 4 deletions google/cloud/alloydbconnector/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
import struct
from threading import Thread
from types import TracebackType
from typing import Any, Callable, Optional, TYPE_CHECKING
from typing import TYPE_CHECKING
from typing import Any
from typing import Callable
from typing import Optional

from google.auth import default
from google.auth.credentials import TokenState
from google.auth.credentials import with_scopes_if_required
from google.auth.transport import requests

import google.cloud.alloydb_connectors_v1.proto.resources_pb2 as connectorspb
from google.cloud.alloydbconnector.client import AlloyDBClient
from google.cloud.alloydbconnector.enums import IPTypes
Expand Down Expand Up @@ -221,8 +223,7 @@ async def connect_async(self, instance_uri: str, driver: str, **kwargs: Any) ->
cache = LazyRefreshCache(instance_uri, self._client, self._keys)
else:
logger.debug(
f"['{instance_uri}']: Refresh strategy is set to background"
" refresh"
f"['{instance_uri}']: Refresh strategy is set to background refresh"
)
cache = RefreshAheadCache(instance_uri, self._client, self._keys)
self._cache[instance_uri] = cache
Expand Down
3 changes: 1 addition & 2 deletions google/cloud/alloydbconnector/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ async def _perform_refresh(self) -> ConnectionInfo:
self._keys,
)
logger.debug(
f"['{self._instance_uri}']: Connection info refresh operation"
" complete"
f"['{self._instance_uri}']: Connection info refresh operation complete"
)
logger.debug(
f"['{self._instance_uri}']: Current certificate expiration = "
Expand Down
3 changes: 1 addition & 2 deletions google/cloud/alloydbconnector/lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ async def connect_info(self) -> ConnectionInfo:
)
return self._cached
logger.debug(
f"['{self._instance_uri}']: Connection info "
"refresh operation started"
f"['{self._instance_uri}']: Connection info refresh operation started"
)
try:
conn_info = await self._client.get_connection_info(
Expand Down
3 changes: 2 additions & 1 deletion google/cloud/alloydbconnector/pg8000.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, TYPE_CHECKING
from typing import TYPE_CHECKING
from typing import Any

if TYPE_CHECKING:
import ssl
Expand Down
3 changes: 2 additions & 1 deletion google/cloud/alloydbconnector/psycopg.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import ssl
import tempfile
import threading
from typing import Any, TYPE_CHECKING
from typing import TYPE_CHECKING
from typing import Any

if TYPE_CHECKING:
import psycopg
Expand Down
56 changes: 14 additions & 42 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

import nox

BLACK_VERSION = "black==23.12.1"
ISORT_VERSION = "isort==5.13.2"
RUFF_VERSION = "ruff==0.11.2"
LINT_PATHS = ["google", "tests", "noxfile.py"]

SYSTEM_TEST_PYTHON_VERSIONS = ["3.10", "3.11", "3.12", "3.13", "3.14"]
Expand All @@ -36,32 +35,22 @@ def lint(session):
session.install("-r", "requirements-test.txt")
session.install("-r", "requirements.txt")
session.install(
"flake8",
"flake8-annotations",
RUFF_VERSION,
"mypy",
BLACK_VERSION,
ISORT_VERSION,
"build",
"twine",
)
session.run(
"isort",
"--fss",
"--check-only",
"--diff",
"--profile=google",
*LINT_PATHS,
)
session.run(
"black",
"ruff",
"format",
"--check",
"--diff",
*LINT_PATHS,
)
session.run(
"flake8",
"google",
"tests",
"ruff",
"check",
*LINT_PATHS,
)
session.run(
"mypy",
Expand All @@ -77,35 +66,18 @@ def lint(session):


@nox.session
def blacken(session):
"""Run black.

Format code to uniform standard.
"""
session.install(BLACK_VERSION)
session.run(
"black",
*LINT_PATHS,
)


@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
"""Format code with ruff."""
session.install(RUFF_VERSION)
session.run(
"isort",
"--fss",
"--profile=google",
"ruff",
"check",
"--fix",
*LINT_PATHS,
)
session.run(
"black",
"ruff",
"format",
*LINT_PATHS,
)

Expand Down
33 changes: 33 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,39 @@ version = { attr = "google.cloud.alloydbconnector.version.__version__" }
# benchmarks, etc.
include = ["google*"]

[tool.ruff]
line-length = 88
target-version = "py310"
exclude = [
"google/api/*",
"google/cloud/alloydb_connectors_v1/*",
]

[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"F", # pyflakes
"W", # pycodestyle warnings
"I", # isort
"ANN", # flake8-annotations
]
ignore = [
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we decide to ignore these? Can we add a comment here explaining the reason?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were implicitly depending on these rules. Now that ruff is in, I think we should delete the ignore list and just default to whatever the standard list is. I'll send a follow-up PR for that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #542 where I've removed these rules (and the linter is now complaining). I think we can fix all these problems and have a cleaner code base as a result.

"E203",
"E231",
"E266",
"E501",
"ANN401",
]

[tool.ruff.lint.per-file-ignores]
"noxfile.py" = ["ANN"]
"tests/*" = ["ANN"]

[tool.ruff.lint.isort]
force-single-line = true
force-sort-within-sections = true
known-first-party = ["google"]

[tool.mypy]
python_version = "3.10"
namespace_packages = true
Expand Down
1 change: 1 addition & 0 deletions tests/system/test_native_asyncpg_direct_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

# [START alloydb_native_asyncpg_connect_iam_authn_direct]
import asyncpg

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

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

import sqlalchemy
from sqlalchemy import event

# [START alloydb_psycopg2_connect_iam_authn_direct]
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: 4 additions & 3 deletions tests/system/test_sqlalchemy_asyncpg_direct_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
from datetime import datetime
import os

import sqlalchemy
from sqlalchemy import event
from sqlalchemy.ext.asyncio import create_async_engine

# [START alloydb_sqlalchemy_asyncpg_connect_iam_authn_direct]
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
10 changes: 7 additions & 3 deletions tests/unit/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@
import json
import ssl
import struct
from typing import Any, Callable, Literal, Optional, Sequence
from typing import Any
from typing import Callable
from typing import Literal
from typing import Optional
from typing import Sequence

from cryptography import x509
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.auth.credentials import _helpers

from google.auth.credentials import Scoped
from google.auth.credentials import TokenState
from google.auth.credentials import _helpers
from google.auth.transport import requests

from google.cloud import alloydb_v1beta
import google.cloud.alloydb_connectors_v1.proto.resources_pb2 as connectorspb
from google.cloud.alloydbconnector.connection_info import ConnectionInfo
Expand Down
Loading
Loading