Skip to content

Commit

Permalink
feat: avoid importing grpc when explicitly disabled (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sanche committed Jan 27, 2022
1 parent e1506fa commit 818213e
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions google/cloud/logging_v2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@
import os
import sys

try:
from google.cloud.logging_v2 import _gapic
except ImportError: # pragma: NO COVER
_HAVE_GRPC = False
_gapic = None
else:
_HAVE_GRPC = True

import google.api_core.client_options
from google.cloud.client import ClientWithProject
Expand All @@ -48,6 +41,19 @@


_DISABLE_GRPC = os.getenv(DISABLE_GRPC, False)
_HAVE_GRPC = False

try:
if not _DISABLE_GRPC:
# only import if DISABLE_GRPC is not set
from google.cloud.logging_v2 import _gapic

_HAVE_GRPC = True
except ImportError: # pragma: NO COVER
# could not import gapic library. Fall back to HTTP mode
_HAVE_GRPC = False
_gapic = None

_USE_GRPC = _HAVE_GRPC and not _DISABLE_GRPC

_GAE_RESOURCE_TYPE = "gae_app"
Expand Down

0 comments on commit 818213e

Please sign in to comment.