Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit fc15893

Browse files
committed
chore: update noxfile in generator-input
1 parent c37532c commit fc15893

File tree

7 files changed

+121
-52
lines changed

7 files changed

+121
-52
lines changed

.librarian/generator-input/librarian.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,4 @@
250250

251251
# Use a python runtime which is available in the owlbot post processor here
252252
# https://github.com/googleapis/synthtool/blob/master/docker/owlbot/python/Dockerfile
253-
s.shell.run(["nox", "-s", "blacken-3.14"], hide_output=False)
253+
s.shell.run(["nox", "-s", "format-3.14"], hide_output=False)

.librarian/generator-input/noxfile.py

Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
1718
# Generated by synthtool. DO NOT EDIT!
1819

1920
from __future__ import absolute_import
@@ -64,6 +65,7 @@
6465
SYSTEM_TEST_STANDARD_DEPENDENCIES: List[str] = [
6566
"mock",
6667
"pytest",
68+
"pytest-asyncio",
6769
"google-cloud-testutils",
6870
]
6971
SYSTEM_TEST_EXTERNAL_DEPENDENCIES: List[str] = []
@@ -217,9 +219,8 @@ def unit(session, protobuf_implementation):
217219
session.install("protobuf<4")
218220

219221
# Run py.test against the unit tests.
220-
session.run(
222+
args = [
221223
"py.test",
222-
"--quiet",
223224
"-s",
224225
f"--junitxml=unit_{session.python}_sponge_log.xml",
225226
"--cov=google",
@@ -228,8 +229,13 @@ def unit(session, protobuf_implementation):
228229
"--cov-config=.coveragerc",
229230
"--cov-report=",
230231
"--cov-fail-under=0",
231-
os.path.join("tests", "unit"),
232-
*session.posargs,
232+
]
233+
if not session.posargs:
234+
args.append(os.path.join("tests", "unit"))
235+
args.extend(session.posargs)
236+
237+
session.run(
238+
*args,
233239
env={
234240
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
235241
},
@@ -362,25 +368,67 @@ def system(session, protobuf_implementation, database_dialect):
362368

363369
# Run py.test against the system tests.
364370
if system_test_exists:
365-
session.run(
371+
args = [
366372
"py.test",
367373
"--quiet",
374+
"-o",
375+
"asyncio_mode=auto",
368376
f"--junitxml=system_{session.python}_sponge_log.xml",
369-
system_test_path,
370-
*session.posargs,
377+
]
378+
if not session.posargs:
379+
args.append(system_test_path)
380+
args.extend(session.posargs)
381+
382+
session.run(
383+
*args,
371384
env={
372385
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
373386
"SPANNER_DATABASE_DIALECT": database_dialect,
374387
"SKIP_BACKUP_TESTS": "true",
375388
},
376389
)
377390
elif system_test_folder_exists:
391+
# Run sync tests
392+
sync_args = [
393+
"py.test",
394+
"--quiet",
395+
"-o",
396+
"asyncio_mode=auto",
397+
f"--junitxml=system_{session.python}_sync_sponge_log.xml",
398+
]
399+
if not session.posargs:
400+
sync_args.append(os.path.join("tests", "system"))
401+
sync_args.append("--ignore=tests/system/_async")
402+
else:
403+
sync_args.extend(session.posargs)
404+
378405
session.run(
406+
*sync_args,
407+
env={
408+
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
409+
"SPANNER_DATABASE_DIALECT": database_dialect,
410+
"SKIP_BACKUP_TESTS": "true",
411+
},
412+
)
413+
414+
# Run async tests
415+
async_args = [
379416
"py.test",
380417
"--quiet",
381-
f"--junitxml=system_{session.python}_sponge_log.xml",
382-
system_test_folder_path,
383-
*session.posargs,
418+
"-o",
419+
"asyncio_mode=auto",
420+
f"--junitxml=system_{session.python}_async_sponge_log.xml",
421+
]
422+
if not session.posargs:
423+
async_args.append(os.path.join("tests", "system", "_async"))
424+
else:
425+
# If posargs are provided, only run if they match async tests
426+
# or just skip if they were already run in sync.
427+
# For simplicity, we only run async folder if no posargs.
428+
return
429+
430+
session.run(
431+
*async_args,
384432
env={
385433
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
386434
"SPANNER_DATABASE_DIALECT": database_dialect,
@@ -551,6 +599,10 @@ def prerelease_deps(session, protobuf_implementation, database_dialect):
551599
"google-cloud-testutils",
552600
# dependencies of google-cloud-testutils"
553601
"click",
602+
# dependency of google-auth
603+
"cffi",
604+
"cryptography",
605+
"cachetools",
554606
]
555607

556608
for dep in prerel_deps:
@@ -589,6 +641,8 @@ def prerelease_deps(session, protobuf_implementation, database_dialect):
589641
session.run(
590642
"py.test",
591643
"--verbose",
644+
"-o",
645+
"asyncio_mode=auto",
592646
f"--junitxml=system_{session.python}_sponge_log.xml",
593647
system_test_path,
594648
*session.posargs,
@@ -602,6 +656,8 @@ def prerelease_deps(session, protobuf_implementation, database_dialect):
602656
session.run(
603657
"py.test",
604658
"--verbose",
659+
"-o",
660+
"asyncio_mode=auto",
605661
f"--junitxml=system_{session.python}_sponge_log.xml",
606662
system_test_folder_path,
607663
*session.posargs,
@@ -611,3 +667,10 @@ def prerelease_deps(session, protobuf_implementation, database_dialect):
611667
"SKIP_BACKUP_TESTS": "true",
612668
},
613669
)
670+
671+
672+
@nox.session(python=DEFAULT_PYTHON_VERSION)
673+
def generate(session):
674+
"""Regenerate synchronous code from asynchronous code."""
675+
session.install("black", "autoflake")
676+
session.run("python", ".cross_sync/generate.py", "google/cloud/spanner_v1")

.librarian/state.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ libraries:
2121
- ^google/cloud/spanner_v1/types
2222
- ^google/cloud/spanner_admin_database_v1
2323
- ^google/cloud/spanner_admin_instance_v1
24-
- ^tests/unit/gapic
24+
- ^tests/unit/gapic/spanner
25+
- ^tests/unit/gapic/__init__.py
2526
- ^tests/__init__.py
2627
- ^tests/unit/__init__.py
2728
- ^.pre-commit-config.yaml

google/cloud/spanner_v1/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
BatchWriteRequest,
6464
BatchWriteResponse,
6565
BeginTransactionRequest,
66-
ClientContext,
6766
CommitRequest,
6867
CreateSessionRequest,
6968
DeleteSessionRequest,
@@ -124,7 +123,6 @@
124123
"BatchWriteRequest",
125124
"BatchWriteResponse",
126125
"BeginTransactionRequest",
127-
"ClientContext",
128126
"CommitRequest",
129127
"CommitResponse",
130128
"CreateSessionRequest",

google/cloud/spanner_v1/_helpers.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
from google.rpc.error_details_pb2 import RetryInfo
3333

3434
from google.cloud._helpers import _date_from_iso8601_date
35-
from google.cloud.spanner_v1.types import ClientContext
3635
from google.cloud.spanner_v1.types import RequestOptions
3736
from google.cloud.spanner_v1.data_types import JsonObject, Interval
3837
from google.cloud.spanner_v1.exceptions import wrap_with_request_id
@@ -196,17 +195,17 @@ def _merge_query_options(base, merge):
196195
def _merge_client_context(base, merge):
197196
"""Merge higher precedence ClientContext with current ClientContext.
198197
199-
:type base: :class:`~google.cloud.spanner_v1.types.ClientContext`
198+
:type base: :class:`~google.cloud.spanner_v1.types.RequestOptions.ClientContext`
200199
or :class:`dict` or None
201200
:param base: The current ClientContext that is intended for use.
202201
203-
:type merge: :class:`~google.cloud.spanner_v1.types.ClientContext`
202+
:type merge: :class:`~google.cloud.spanner_v1.types.RequestOptions.ClientContext`
204203
or :class:`dict` or None
205204
:param merge:
206205
The ClientContext that has a higher priority than base. These options
207206
should overwrite the fields in base.
208207
209-
:rtype: :class:`~google.cloud.spanner_v1.types.ClientContext`
208+
:rtype: :class:`~google.cloud.spanner_v1.types.RequestOptions.ClientContext`
210209
or None
211210
:returns:
212211
ClientContext object formed by merging the two given ClientContexts.
@@ -215,15 +214,23 @@ def _merge_client_context(base, merge):
215214
return None
216215

217216
# Avoid in-place modification of base
218-
combined_pb = ClientContext()._pb
217+
combined_pb = RequestOptions.ClientContext()._pb
219218
if base:
220-
base_pb = ClientContext(base)._pb if isinstance(base, dict) else base._pb
219+
base_pb = (
220+
RequestOptions.ClientContext(base)._pb
221+
if isinstance(base, dict)
222+
else base._pb
223+
)
221224
combined_pb.MergeFrom(base_pb)
222225
if merge:
223-
merge_pb = ClientContext(merge)._pb if isinstance(merge, dict) else merge._pb
226+
merge_pb = (
227+
RequestOptions.ClientContext(merge)._pb
228+
if isinstance(merge, dict)
229+
else merge._pb
230+
)
224231
combined_pb.MergeFrom(merge_pb)
225232

226-
combined = ClientContext(combined_pb)
233+
combined = RequestOptions.ClientContext(combined_pb)
227234

228235
if not combined.secure_context:
229236
return None
@@ -233,18 +240,18 @@ def _merge_client_context(base, merge):
233240
def _validate_client_context(client_context):
234241
"""Validate and convert client_context.
235242
236-
:type client_context: :class:`~google.cloud.spanner_v1.types.ClientContext`
243+
:type client_context: :class:`~google.cloud.spanner_v1.types.RequestOptions.ClientContext`
237244
or :class:`dict`
238245
:param client_context: (Optional) Client context to use.
239246
240-
:rtype: :class:`~google.cloud.spanner_v1.types.ClientContext`
247+
:rtype: :class:`~google.cloud.spanner_v1.types.RequestOptions.ClientContext`
241248
:returns: Validated ClientContext object or None.
242249
:raises TypeError: if client_context is not a ClientContext or a dict.
243250
"""
244251
if client_context is not None:
245252
if isinstance(client_context, dict):
246-
client_context = ClientContext(client_context)
247-
elif not isinstance(client_context, ClientContext):
253+
client_context = RequestOptions.ClientContext(client_context)
254+
elif not isinstance(client_context, RequestOptions.ClientContext):
248255
raise TypeError("client_context must be a ClientContext or a dict")
249256
return client_context
250257

@@ -256,7 +263,7 @@ def _merge_request_options(request_options, client_context):
256263
or :class:`dict` or None
257264
:param request_options: The current RequestOptions that is intended for use.
258265
259-
:type client_context: :class:`~google.cloud.spanner_v1.types.ClientContext`
266+
:type client_context: :class:`~google.cloud.spanner_v1.types.RequestOptions.ClientContext`
260267
or :class:`dict` or None
261268
:param client_context:
262269
The ClientContext to merge into request_options.

noxfile.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
18-
# The source of truth for this file is `.librarian/generator-input`
19-
2017

2118
# Generated by synthtool. DO NOT EDIT!
2219

0 commit comments

Comments
 (0)