Ejemplo n.º 1
0
 def monkeypatch_bq(bq_client, *args, **kwargs):
     from kaggle_gcp import get_integrations, PublicBigqueryClient, KaggleKernelCredentials
     specified_credentials = kwargs.get('credentials')
     has_bigquery = get_integrations().has_bigquery()
     # Prioritize passed in project id, but if it is missing look for env var. 
     arg_project = kwargs.get('project')
     explicit_project_id = arg_project or os.environ.get(environment_vars.PROJECT)
     # This is a hack to get around the bug in google-cloud library.
     # Remove these two lines once this is resolved:
     # https://github.com/googleapis/google-cloud-python/issues/8108
     if explicit_project_id:
         Log.info(f"Explicit project set to {explicit_project_id}")
         kwargs['project'] = explicit_project_id
     if explicit_project_id is None and specified_credentials is None and not has_bigquery:
         msg = "Using Kaggle's public dataset BigQuery integration."
         Log.info(msg)
         print(msg)
         return PublicBigqueryClient(*args, **kwargs)
     else:
         if specified_credentials is None:
             Log.info("No credentials specified, using KaggleKernelCredentials.")
             kwargs['credentials'] = KaggleKernelCredentials()
             if (not has_bigquery):
                 Log.info("No bigquery integration found, creating client anyways.")
                 print('Please ensure you have selected a BigQuery '
                     'account in the Kernels Settings sidebar.')
         if explicit_project_id is None:
             Log.info("No project specified while using the unmodified client.")
             print('Please ensure you specify a project id when creating the client'
                 ' in order to use your BigQuery account.')
         return bq_client(*args, **kwargs)
Ejemplo n.º 2
0
 def monkeypatch_bq(bq_client, *args, **kwargs):
     data_proxy_project = os.getenv("KAGGLE_DATA_PROXY_PROJECT")
     specified_project = kwargs.get('project')
     specified_credentials = kwargs.get('credentials')
     if specified_project is None and specified_credentials is None:
         print("Using Kaggle's public dataset BigQuery integration.")
         return PublicBigqueryClient(*args, **kwargs)
     else:
         return bq_client(*args, **kwargs)
Ejemplo n.º 3
0
    def monkeypatch_bq(bq_client, *args, **kwargs):
        data_proxy_project = os.getenv("KAGGLE_DATA_PROXY_PROJECT")
        specified_project = kwargs.get('project')
        specified_credentials = kwargs.get('credentials')
        kernel_integrations = get_integrations()
        if specified_project is None and specified_credentials is None and not kernel_integrations.has_bigquery():
            print("Using Kaggle's public dataset BigQuery integration.")
            return PublicBigqueryClient(*args, **kwargs)

        else:
            if specified_credentials is None:
                kwargs['credentials'] = KaggleKernelCredentials()
            return bq_client(*args, **kwargs)
Ejemplo n.º 4
0
    def monkeypatch_bq(bq_client, *args, **kwargs):
        specified_project = kwargs.get('project')
        specified_credentials = kwargs.get('credentials')
        has_bigquery = get_integrations().has_bigquery()
        if specified_project is None and specified_credentials is None and not has_bigquery:
            print("Using Kaggle's public dataset BigQuery integration.")
            return PublicBigqueryClient(*args, **kwargs)

        else:
            if specified_credentials is None:
                kwargs['credentials'] = KaggleKernelCredentials()
                if (not has_bigquery):
                    print('Please ensure you have selected a BigQuery '
                          'account in the Kernels Settings sidebar.')
            return bq_client(*args, **kwargs)
Ejemplo n.º 5
0
    def monkeypatch_bq(bq_client, *args, **kwargs):
        specified_credentials = kwargs.get('credentials')
        has_bigquery = get_integrations().has_bigquery()
        # Prioritize passed in project id, but if it is missing look for env var. 
        arg_project = kwargs.get('project')
        explicit_project_id = arg_project or os.environ.get(environment_vars.PROJECT)
        # This is a hack to get around the bug in google-cloud library.
        # Remove these two lines once this is resolved:
        # https://github.com/googleapis/google-cloud-python/issues/8108
        if explicit_project_id:
            kwargs['project'] = explicit_project_id
        if explicit_project_id is None and specified_credentials is None and not has_bigquery:
            print("Using Kaggle's public dataset BigQuery integration.")
            return PublicBigqueryClient(*args, **kwargs)

        else:
            if specified_credentials is None:
                kwargs['credentials'] = KaggleKernelCredentials()
                if (not has_bigquery):
                    print('Please ensure you have selected a BigQuery '
                          'account in the Kernels Settings sidebar.')
            return bq_client(*args, **kwargs)
Ejemplo n.º 6
0
 def test_proxy_using_library(self):
     env = EnvironmentVarGuard()
     env.unset('KAGGLE_BQ_USER_JWT')
     with env:
         client = PublicBigqueryClient()
         self._test_proxy(client, should_use_proxy=True)
Ejemplo n.º 7
0
 def test_proxy_using_library(self):
     env = EnvironmentVarGuard()
     env.unset('KAGGLE_USER_SECRETS_TOKEN')
     with env:
         client = PublicBigqueryClient()
         self._test_proxy(client)