Skip to content

Commit ab570ef

Browse files
feat: avoid importing grpc when explicitly disabled (#416)
1 parent eed5396 commit ab570ef

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

google/cloud/logging_v2/client.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@
1818
import os
1919
import sys
2020

21-
try:
22-
from google.cloud.logging_v2 import _gapic
23-
except ImportError: # pragma: NO COVER
24-
_HAVE_GRPC = False
25-
_gapic = None
26-
else:
27-
_HAVE_GRPC = True
2821

2922
import google.api_core.client_options
3023
from google.cloud.client import ClientWithProject
@@ -48,6 +41,19 @@
4841

4942

5043
_DISABLE_GRPC = os.getenv(DISABLE_GRPC, False)
44+
_HAVE_GRPC = False
45+
46+
try:
47+
if not _DISABLE_GRPC:
48+
# only import if DISABLE_GRPC is not set
49+
from google.cloud.logging_v2 import _gapic
50+
51+
_HAVE_GRPC = True
52+
except ImportError: # pragma: NO COVER
53+
# could not import gapic library. Fall back to HTTP mode
54+
_HAVE_GRPC = False
55+
_gapic = None
56+
5157
_USE_GRPC = _HAVE_GRPC and not _DISABLE_GRPC
5258

5359
_GAE_RESOURCE_TYPE = "gae_app"

0 commit comments

Comments
 (0)