Skip to content
Draft
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
50 changes: 39 additions & 11 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ exclude = (?x)(
| (^|/)tests/unit/gapic/
)


# ==============================================================================
# GLOBAL THIRD-PARTY & SHARED LIBRARY IGNORES
# ==============================================================================
Expand All @@ -28,13 +27,7 @@ ignore_missing_imports = True
[mypy-flask]
ignore_missing_imports = True

[mypy-google.auth.*]
ignore_missing_imports = True

[mypy-google.cloud.bigtable]
ignore_missing_imports = True

[mypy-google.cloud.pubsub]
[mypy-google.api.*]
ignore_missing_imports = True

[mypy-google.colab]
Expand All @@ -61,6 +54,9 @@ ignore_missing_imports = True
[mypy-grpc.*]
ignore_missing_imports = True

[mypy-grpc_status]
ignore_missing_imports = True

[mypy-ibis.*]
ignore_missing_imports = True

Expand All @@ -86,15 +82,47 @@ ignore_missing_imports = True
# ==============================================================================
# PACKAGE-SPECIFIC OVERRIDES & EXCEPTIONS
# ==============================================================================
# --- bigframes ---
[mypy-bigframes_vendored.*]
ignore_errors = True

# --- google-auth ---
[mypy-google.auth.*]
ignore_missing_imports = True

# --- google-cloud-bigtable ---
[mypy-google.cloud.bigtable.*]
ignore_errors = True
[mypy-google.cloud.bigtable]
ignore_missing_imports = True

[mypy-google.cloud.bigtable.data.*]
[mypy-google.cloud.bigtable.*]
check_untyped_defs = True
warn_unreachable = True
disallow_any_generics = True
ignore_errors = True

[mypy-google.cloud.bigtable.data.*]
ignore_errors = False

[mypy-google.cloud.bigtable_admin.*]
ignore_errors = True

[mypy-google.cloud.bigtable_admin_v2.*]
ignore_errors = True

[mypy-google.cloud.bigtable_v2.*]
ignore_errors = True

# --- google-cloud-datastore ---
[mypy-google.cloud.datastore.*]
ignore_missing_imports = True

[mypy-google.cloud.datastore._app_engine_key_pb2]
ignore_errors = True

# --- google-cloud-firestore ---
[mypy-google.cloud.firestore.*]
check_untyped_defs = True

# --- google-cloud-pubsub ---
[mypy-google.cloud.pubsub]
ignore_missing_imports = True
Comment thread
chalmerlowe marked this conversation as resolved.
15 changes: 0 additions & 15 deletions packages/google-cloud-spanner/mypy.ini

This file was deleted.

12 changes: 12 additions & 0 deletions packages/google-cloud-spanner/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@
SYSTEM_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {}

CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
# Path to the centralized mypy configuration file at the repository root.
# Search upwards to support running nox from both monorepo packages and integration test goldens.
MYPY_CONFIG_FILE = next(
(
str(p / "mypy.ini")
for p in CURRENT_DIRECTORY.parents
if (p / "mypy.ini").exists()
),
str(CURRENT_DIRECTORY.parent.parent / "mypy.ini"),
)


nox.options.sessions = [
"unit-3.10",
Expand Down Expand Up @@ -767,6 +778,7 @@ def mypy(session):
session.install(".")
session.run(
"mypy",
f"--config-file={MYPY_CONFIG_FILE}",
"-p",
"google",
# "--check-untyped-defs",
Expand Down
28 changes: 26 additions & 2 deletions packages/google-cloud-spanner/tests/system/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import time
import uuid

from google.api_core import exceptions
from google.api_core import datetime_helpers, exceptions
from google.cloud.spanner_v1 import instance as instance_mod
from test_utils import retry

from google.cloud.spanner_v1 import instance as instance_mod
from tests import _fixtures

CREATE_INSTANCE_ENVVAR = "GOOGLE_CLOUD_TESTS_CREATE_SPANNER_INSTANCE"
Expand Down Expand Up @@ -159,6 +159,30 @@ def cleanup_old_instances(spanner_client):
scrub_instance_ignore_not_found(instance)


def cleanup_stale_databases(instance, cutoff_seconds=600):
"""Delete stale databases in the given instance older than cutoff_seconds."""
cutoff_ms = (int(time.time()) - cutoff_seconds) * 1000

for database_pb in instance.list_databases():
if database_pb.create_time is not None:
create_time_ms = datetime_helpers.to_milliseconds(database_pb.create_time)

if create_time_ms < cutoff_ms:
db = instance.database(database_pb.name.split("/")[-1])
try:
db.reload()
if db.enable_drop_protection:
db.enable_drop_protection = False
operation = db.update(["enable_drop_protection"])
operation.result(DATABASE_OPERATION_TIMEOUT_IN_SECONDS)
db.drop()
except exceptions.NotFound:
pass
except exceptions.GoogleAPIError:
# Ignore other API errors during cleanup
pass


def unique_id(prefix, separator="-"):
# Database name size: Spanner database names are limited to 30 characters.
# See: https://docs.cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#createdatabaserequest
Expand Down
3 changes: 2 additions & 1 deletion packages/google-cloud-spanner/tests/system/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import time

import pytest

from google.cloud import spanner_v1
from google.cloud.spanner_admin_database_v1 import DatabaseDialect
from google.cloud.spanner_admin_database_v1.types.backup import (
Expand Down Expand Up @@ -218,6 +217,8 @@ def shared_instance(
instance = spanner_client.instance(shared_instance_id)
instance.reload()

_helpers.cleanup_stale_databases(instance)

yield instance

if _helpers.CREATE_INSTANCE:
Expand Down
Loading