MCPcopy Index your code
hub / github.com/Kaggle/docker-python / monkeypatch_client

Function monkeypatch_client

patches/kaggle_gcp.py:206–229  ·  view source on GitHub ↗
(client_klass, kaggle_kernel_credentials)

Source from the content-addressed store, hash-verified

204 logging.info("aiplatform.init patched")
205
206def monkeypatch_client(client_klass, kaggle_kernel_credentials):
207 client_init = client_klass.__init__
208 def patched_init(self, *args, **kwargs):
209 specified_credentials = kwargs.get('credentials')
210 if specified_credentials is None:
211 logging.info("No credentials specified, using KaggleKernelCredentials.")
212 # Some GCP services demand the billing and target project must be the same.
213 # To avoid using default service account based credential as caller credential
214 # user need to provide ClientOptions with quota_project_id:
215 # srv.Client(client_options=client_options.ClientOptions(quota_project_id="YOUR PROJECT"))
216 client_options=kwargs.get('client_options')
217 if client_options != None and client_options.quota_project_id != None:
218 kwargs['credentials'] = KaggleKernelWithProjetCredentials(
219 parentCredential = kaggle_kernel_credentials,
220 quota_project_id = client_options.quota_project_id)
221 else:
222 kwargs['credentials'] = kaggle_kernel_credentials
223
224 kwargs['client_info'] = set_kaggle_user_agent(kwargs.get('client_info'))
225 return client_init(self, *args, **kwargs)
226
227 if (not has_been_monkeypatched(client_klass.__init__)):
228 client_klass.__init__ = patched_init
229 logging.info(f"Client patched: {client_klass}")
230
231def set_kaggle_user_agent(client_info: ClientInfo):
232 # Add kaggle client user agent in order to attribute usage.

Callers 6

init_gcsFunction · 0.85
init_translation_v2Function · 0.85
init_translation_v3Function · 0.85
init_natural_languageFunction · 0.85
init_video_intelligenceFunction · 0.85
init_visionFunction · 0.85

Calls 1

has_been_monkeypatchedFunction · 0.85

Tested by

no test coverage detected