Skip to content
This repository was archived by the owner on Sep 21, 2023. It is now read-only.

Commit 2c5f07d

Browse files
feat: add context manager support in client (#104)
- [ ] Regenerate this pull request now. chore: fix docstring for first attribute of protos committer: @busunkim96 PiperOrigin-RevId: 401271153 Source-Link: googleapis/googleapis@787f8c9 Source-Link: https://github.com/googleapis/googleapis-gen/commit/81decffe9fc72396a8153e756d1d67a6eecfd620 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9
1 parent 824009a commit 2c5f07d

File tree

16 files changed

+248
-8
lines changed

16 files changed

+248
-8
lines changed

google/cloud/video/transcoder_v1/services/transcoder_service/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,12 @@ async def delete_job_template(
776776
request, retry=retry, timeout=timeout, metadata=metadata,
777777
)
778778

779+
async def __aenter__(self):
780+
return self
781+
782+
async def __aexit__(self, exc_type, exc, tb):
783+
await self.transport.close()
784+
779785

780786
try:
781787
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/video/transcoder_v1/services/transcoder_service/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,7 @@ def __init__(
372372
client_cert_source_for_mtls=client_cert_source_func,
373373
quota_project_id=client_options.quota_project_id,
374374
client_info=client_info,
375-
always_use_jwt_access=(
376-
Transport == type(self).get_transport_class("grpc")
377-
or Transport == type(self).get_transport_class("grpc_asyncio")
378-
),
375+
always_use_jwt_access=True,
379376
)
380377

381378
def create_job(
@@ -979,6 +976,19 @@ def delete_job_template(
979976
request, retry=retry, timeout=timeout, metadata=metadata,
980977
)
981978

979+
def __enter__(self):
980+
return self
981+
982+
def __exit__(self, type, value, traceback):
983+
"""Releases underlying transport's resources.
984+
985+
.. warning::
986+
ONLY use as a context manager if the transport is NOT shared
987+
with other clients! Exiting the with block will CLOSE the transport
988+
and may cause errors in other clients!
989+
"""
990+
self.transport.close()
991+
982992

983993
try:
984994
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/video/transcoder_v1/services/transcoder_service/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ def _prep_wrapped_messages(self, client_info):
182182
),
183183
}
184184

185+
def close(self):
186+
"""Closes resources associated with the transport.
187+
188+
.. warning::
189+
Only call this method if the transport is NOT shared
190+
with other clients - this may cause errors in other clients!
191+
"""
192+
raise NotImplementedError()
193+
185194
@property
186195
def create_job(
187196
self,

google/cloud/video/transcoder_v1/services/transcoder_service/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,5 +437,8 @@ def delete_job_template(
437437
)
438438
return self._stubs["delete_job_template"]
439439

440+
def close(self):
441+
self.grpc_channel.close()
442+
440443

441444
__all__ = ("TranscoderServiceGrpcTransport",)

google/cloud/video/transcoder_v1/services/transcoder_service/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,5 +446,8 @@ def delete_job_template(
446446
)
447447
return self._stubs["delete_job_template"]
448448

449+
def close(self):
450+
return self.grpc_channel.close()
451+
449452

450453
__all__ = ("TranscoderServiceGrpcAsyncIOTransport",)

google/cloud/video/transcoder_v1/types/resources.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
class Job(proto.Message):
4949
r"""Transcoding job resource.
50+
5051
Attributes:
5152
name (str):
5253
The resource name of the job. Format:
@@ -123,6 +124,7 @@ class ProcessingState(proto.Enum):
123124

124125
class JobTemplate(proto.Message):
125126
r"""Transcoding job template resource.
127+
126128
Attributes:
127129
name (str):
128130
The resource name of the job template. Format:
@@ -137,6 +139,7 @@ class JobTemplate(proto.Message):
137139

138140
class JobConfig(proto.Message):
139141
r"""Job configuration
142+
140143
Attributes:
141144
inputs (Sequence[google.cloud.video.transcoder_v1.types.Input]):
142145
List of input assets stored in Cloud Storage.
@@ -182,6 +185,7 @@ class JobConfig(proto.Message):
182185

183186
class Input(proto.Message):
184187
r"""Input asset.
188+
185189
Attributes:
186190
key (str):
187191
A unique key for this input. Must be
@@ -205,6 +209,7 @@ class Input(proto.Message):
205209

206210
class Output(proto.Message):
207211
r"""Location of output file(s) in a Cloud Storage bucket.
212+
208213
Attributes:
209214
uri (str):
210215
URI for the output file(s). For example,
@@ -217,6 +222,7 @@ class Output(proto.Message):
217222

218223
class EditAtom(proto.Message):
219224
r"""Edit atom.
225+
220226
Attributes:
221227
key (str):
222228
A unique key for this atom. Must be specified
@@ -246,6 +252,7 @@ class EditAtom(proto.Message):
246252

247253
class AdBreak(proto.Message):
248254
r"""Ad break.
255+
249256
Attributes:
250257
start_time_offset (google.protobuf.duration_pb2.Duration):
251258
Start time in seconds for the ad break, relative to the
@@ -288,6 +295,7 @@ class ElementaryStream(proto.Message):
288295

289296
class MuxStream(proto.Message):
290297
r"""Multiplexing settings for output stream.
298+
291299
Attributes:
292300
key (str):
293301
A unique key for this multiplexed stream. HLS media
@@ -326,6 +334,7 @@ class MuxStream(proto.Message):
326334

327335
class Manifest(proto.Message):
328336
r"""Manifest configuration.
337+
329338
Attributes:
330339
file_name (str):
331340
The name of the generated file. The default is ``manifest``
@@ -355,6 +364,7 @@ class ManifestType(proto.Enum):
355364

356365
class PubsubDestination(proto.Message):
357366
r"""A Pub/Sub destination.
367+
358368
Attributes:
359369
topic (str):
360370
The name of the Pub/Sub topic to publish job completion
@@ -454,6 +464,7 @@ class SpriteSheet(proto.Message):
454464

455465
class Overlay(proto.Message):
456466
r"""Overlay configuration.
467+
457468
Attributes:
458469
image (google.cloud.video.transcoder_v1.types.Overlay.Image):
459470
Image overlay.
@@ -470,6 +481,7 @@ class FadeType(proto.Enum):
470481

471482
class NormalizedCoordinate(proto.Message):
472483
r"""2D normalized coordinates. Default: ``{0.0, 0.0}``
484+
473485
Attributes:
474486
x (float):
475487
Normalized x coordinate.
@@ -482,6 +494,7 @@ class NormalizedCoordinate(proto.Message):
482494

483495
class Image(proto.Message):
484496
r"""Overlaid jpeg image.
497+
485498
Attributes:
486499
uri (str):
487500
Required. URI of the JPEG image in Cloud Storage. For
@@ -507,6 +520,7 @@ class Image(proto.Message):
507520

508521
class AnimationStatic(proto.Message):
509522
r"""Display static overlay object.
523+
510524
Attributes:
511525
xy (google.cloud.video.transcoder_v1.types.Overlay.NormalizedCoordinate):
512526
Normalized coordinates based on output video resolution.
@@ -529,6 +543,7 @@ class AnimationStatic(proto.Message):
529543

530544
class AnimationFade(proto.Message):
531545
r"""Display overlay object with fade animation.
546+
532547
Attributes:
533548
fade_type (google.cloud.video.transcoder_v1.types.Overlay.FadeType):
534549
Required. Type of fade animation: ``FADE_IN`` or
@@ -576,6 +591,7 @@ class AnimationEnd(proto.Message):
576591

577592
class Animation(proto.Message):
578593
r"""Animation types.
594+
579595
Attributes:
580596
animation_static (google.cloud.video.transcoder_v1.types.Overlay.AnimationStatic):
581597
Display static overlay object.
@@ -610,6 +626,7 @@ class Animation(proto.Message):
610626

611627
class PreprocessingConfig(proto.Message):
612628
r"""Preprocessing configurations.
629+
613630
Attributes:
614631
color (google.cloud.video.transcoder_v1.types.PreprocessingConfig.Color):
615632
Color preprocessing configuration.
@@ -627,6 +644,7 @@ class PreprocessingConfig(proto.Message):
627644

628645
class Color(proto.Message):
629646
r"""Color preprocessing configuration.
647+
630648
Attributes:
631649
saturation (float):
632650
Control color saturation of the video. Enter
@@ -651,6 +669,7 @@ class Color(proto.Message):
651669

652670
class Denoise(proto.Message):
653671
r"""Denoise preprocessing configuration.
672+
654673
Attributes:
655674
strength (float):
656675
Set strength of the denoise. Enter a value
@@ -671,6 +690,7 @@ class Denoise(proto.Message):
671690

672691
class Deblock(proto.Message):
673692
r"""Deblock preprocessing configuration.
693+
674694
Attributes:
675695
strength (float):
676696
Set strength of the deblocker. Enter a value
@@ -686,6 +706,7 @@ class Deblock(proto.Message):
686706

687707
class Audio(proto.Message):
688708
r"""Audio preprocessing configuration.
709+
689710
Attributes:
690711
lufs (float):
691712
Specify audio loudness normalization in loudness units
@@ -772,6 +793,7 @@ class Pad(proto.Message):
772793

773794
class VideoStream(proto.Message):
774795
r"""Video stream resource.
796+
775797
Attributes:
776798
h264 (google.cloud.video.transcoder_v1.types.VideoStream.H264CodecSettings):
777799
H264 codec settings.
@@ -783,6 +805,7 @@ class VideoStream(proto.Message):
783805

784806
class H264CodecSettings(proto.Message):
785807
r"""H264 codec settings.
808+
786809
Attributes:
787810
width_pixels (int):
788811
The width of the video in pixels. Must be an
@@ -931,6 +954,7 @@ class H264CodecSettings(proto.Message):
931954

932955
class H265CodecSettings(proto.Message):
933956
r"""H265 codec settings.
957+
934958
Attributes:
935959
width_pixels (int):
936960
The width of the video in pixels. Must be an
@@ -1091,6 +1115,7 @@ class H265CodecSettings(proto.Message):
10911115

10921116
class Vp9CodecSettings(proto.Message):
10931117
r"""VP9 codec settings.
1118+
10941119
Attributes:
10951120
width_pixels (int):
10961121
The width of the video in pixels. Must be an
@@ -1193,6 +1218,7 @@ class Vp9CodecSettings(proto.Message):
11931218

11941219
class AudioStream(proto.Message):
11951220
r"""Audio stream resource.
1221+
11961222
Attributes:
11971223
codec (str):
11981224
The codec for this audio stream. The default is ``aac``.
@@ -1318,6 +1344,7 @@ class TextMapping(proto.Message):
13181344

13191345
class SegmentSettings(proto.Message):
13201346
r"""Segment settings for ``ts``, ``fmp4`` and ``vtt``.
1347+
13211348
Attributes:
13221349
segment_duration (google.protobuf.duration_pb2.Duration):
13231350
Duration of the segments in seconds. The default is

google/cloud/video/transcoder_v1/types/services.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
class CreateJobRequest(proto.Message):
3939
r"""Request message for ``TranscoderService.CreateJob``.
40+
4041
Attributes:
4142
parent (str):
4243
Required. The parent location to create and process this
@@ -81,6 +82,7 @@ class ListJobsRequest(proto.Message):
8182

8283
class GetJobRequest(proto.Message):
8384
r"""Request message for ``TranscoderService.GetJob``.
85+
8486
Attributes:
8587
name (str):
8688
Required. The name of the job to retrieve. Format:
@@ -92,6 +94,7 @@ class GetJobRequest(proto.Message):
9294

9395
class DeleteJobRequest(proto.Message):
9496
r"""Request message for ``TranscoderService.DeleteJob``.
97+
9598
Attributes:
9699
name (str):
97100
Required. The name of the job to delete. Format:
@@ -108,6 +111,7 @@ class DeleteJobRequest(proto.Message):
108111

109112
class ListJobsResponse(proto.Message):
110113
r"""Response message for ``TranscoderService.ListJobs``.
114+
111115
Attributes:
112116
jobs (Sequence[google.cloud.video.transcoder_v1.types.Job]):
113117
List of jobs in the specified region.
@@ -128,6 +132,7 @@ def raw_page(self):
128132

129133
class CreateJobTemplateRequest(proto.Message):
130134
r"""Request message for ``TranscoderService.CreateJobTemplate``.
135+
131136
Attributes:
132137
parent (str):
133138
Required. The parent location to create this job template.
@@ -152,6 +157,7 @@ class CreateJobTemplateRequest(proto.Message):
152157

153158
class ListJobTemplatesRequest(proto.Message):
154159
r"""Request message for ``TranscoderService.ListJobTemplates``.
160+
155161
Attributes:
156162
parent (str):
157163
Required. The parent location from which to retrieve the
@@ -180,6 +186,7 @@ class ListJobTemplatesRequest(proto.Message):
180186

181187
class GetJobTemplateRequest(proto.Message):
182188
r"""Request message for ``TranscoderService.GetJobTemplate``.
189+
183190
Attributes:
184191
name (str):
185192
Required. The name of the job template to retrieve. Format:
@@ -191,6 +198,7 @@ class GetJobTemplateRequest(proto.Message):
191198

192199
class DeleteJobTemplateRequest(proto.Message):
193200
r"""Request message for ``TranscoderService.DeleteJobTemplate``.
201+
194202
Attributes:
195203
name (str):
196204
Required. The name of the job template to delete.
@@ -207,6 +215,7 @@ class DeleteJobTemplateRequest(proto.Message):
207215

208216
class ListJobTemplatesResponse(proto.Message):
209217
r"""Response message for ``TranscoderService.ListJobTemplates``.
218+
210219
Attributes:
211220
job_templates (Sequence[google.cloud.video.transcoder_v1.types.JobTemplate]):
212221
List of job templates in the specified

google/cloud/video/transcoder_v1beta1/services/transcoder_service/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,12 @@ async def delete_job_template(
775775
request, retry=retry, timeout=timeout, metadata=metadata,
776776
)
777777

778+
async def __aenter__(self):
779+
return self
780+
781+
async def __aexit__(self, exc_type, exc, tb):
782+
await self.transport.close()
783+
778784

779785
try:
780786
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

0 commit comments

Comments
 (0)