diff --git a/spanner/observability/README.md b/spanner/observability/README.md index ac034d79f1..423db1f4fb 100644 --- a/spanner/observability/README.md +++ b/spanner/observability/README.md @@ -11,10 +11,10 @@ Python samples demonstrating Cloud Spanner OpenTelemetry client-side and end-to- source env/bin/activate ``` -2. Install dependencies: +2. Install the samples and their dependencies: ```sh - pip install -r requirements.txt + pip install -e . ``` ## Running Tests diff --git a/spanner/observability/pyproject.toml b/spanner/observability/pyproject.toml index 79a4c92311..66e969b356 100644 --- a/spanner/observability/pyproject.toml +++ b/spanner/observability/pyproject.toml @@ -22,13 +22,10 @@ build-backend = "setuptools.build_meta" name = "spanner-observability-samples" version = "0.0.0" requires-python = ">=3.13" -dependencies = [ - "google-api-core==2.44.0", - "google-cloud-spanner==3.72.0", - "opentelemetry-api==1.45.2", - "opentelemetry-exporter-gcp-trace==1.15.0", - "opentelemetry-exporter-otlp-proto-grpc==1.45.2", - "opentelemetry-sdk==1.45.2", -] +# Dependencies are pinned in requirements.txt, the single source of truth. +dynamic = ["dependencies"] # PyPI rejects uploads with this classifier. classifiers = ["Private :: Do Not Upload"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} diff --git a/spanner/observability/tests/disable_builtin_metrics_test.py b/spanner/observability/tests/disable_builtin_metrics_test.py index f06442fe37..6127120541 100644 --- a/spanner/observability/tests/disable_builtin_metrics_test.py +++ b/spanner/observability/tests/disable_builtin_metrics_test.py @@ -25,7 +25,6 @@ PROJECT_ID = "example-project-id" INSTANCE_ID = "example-instance" DATABASE_ID = "example-db" -DATABASE_NAME = f"projects/{PROJECT_ID}/instances/{INSTANCE_ID}/databases/{DATABASE_ID}" SPANNER_CLIENT = "google.cloud.spanner.Client" @@ -36,7 +35,6 @@ def test_disable_builtin_metrics_success( database = ( mock_client_class.return_value.instance.return_value.database.return_value ) - database.name = DATABASE_NAME snapshot = database.snapshot.return_value.__enter__.return_value snapshot.execute_sql.return_value = [(1,)] @@ -99,7 +97,6 @@ def test_disable_builtin_metrics_cli_entrypoint( database = ( mock_client_class.return_value.instance.return_value.database.return_value ) - database.name = DATABASE_NAME snapshot = database.snapshot.return_value.__enter__.return_value snapshot.execute_sql.return_value = [(1,)] monkeypatch.setattr( diff --git a/spanner/search_and_ai/README.md b/spanner/search_and_ai/README.md index a14b471779..f9841ddf37 100644 --- a/spanner/search_and_ai/README.md +++ b/spanner/search_and_ai/README.md @@ -11,10 +11,10 @@ Python samples demonstrating vector search (`COSINE_DISTANCE`, `APPROX_COSINE_DI source env/bin/activate ``` -2. Install dependencies: +2. Install the samples and their dependencies: ```sh - pip install -r requirements.txt + pip install -e . ``` 3. Set your Google Cloud project ID and run a sample: diff --git a/spanner/search_and_ai/pyproject.toml b/spanner/search_and_ai/pyproject.toml index 9e46f803fc..1dfb885d7f 100644 --- a/spanner/search_and_ai/pyproject.toml +++ b/spanner/search_and_ai/pyproject.toml @@ -22,9 +22,10 @@ build-backend = "setuptools.build_meta" name = "spanner-search-and-ai-samples" version = "0.0.0" requires-python = ">=3.13" -dependencies = [ - "google-api-core==2.44.0", - "google-cloud-spanner==3.72.0", -] +# Dependencies are pinned in requirements.txt, the single source of truth. +dynamic = ["dependencies"] # PyPI rejects uploads with this classifier. classifiers = ["Private :: Do Not Upload"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} diff --git a/spanner/search_and_ai/tests/vector_search_knn_test.py b/spanner/search_and_ai/tests/vector_search_knn_test.py index d38e32f8ae..dd83a97a19 100644 --- a/spanner/search_and_ai/tests/vector_search_knn_test.py +++ b/spanner/search_and_ai/tests/vector_search_knn_test.py @@ -27,7 +27,7 @@ SPANNER_CLIENT = "google.cloud.spanner.Client" -@mock.patch(SPANNER_CLIENT) +@mock.patch(SPANNER_CLIENT, autospec=True) def test_find_k_nearest_neighbors_success( mock_client_class: mock.MagicMock, capsys: pytest.CaptureFixture[str] ) -> None: @@ -68,7 +68,7 @@ def test_find_k_nearest_neighbors_success( ), ], ) -@mock.patch(SPANNER_CLIENT) +@mock.patch(SPANNER_CLIENT, autospec=True) def test_find_k_nearest_neighbors_errors( mock_client_class: mock.MagicMock, capsys: pytest.CaptureFixture[str], @@ -89,7 +89,7 @@ def test_find_k_nearest_neighbors_errors( assert PROJECT_ID not in err -@mock.patch(SPANNER_CLIENT) +@mock.patch(SPANNER_CLIENT, autospec=True) def test_find_k_nearest_neighbors_cli_entrypoint( mock_client_class: mock.MagicMock, monkeypatch: pytest.MonkeyPatch, @@ -118,6 +118,8 @@ def test_find_k_nearest_neighbors_cli_entrypoint( assert "Document ID: 101" in capsys.readouterr().out +# Live integration test: skipped unless RUN_INTEGRATION_TESTS=true is set along with +# GOOGLE_CLOUD_PROJECT, SPANNER_INSTANCE_ID, and SPANNER_DATABASE_ID. @conftest.live_only def test_find_k_nearest_neighbors_live( capsys: pytest.CaptureFixture[str],