Skip to content

Commit a126550

Browse files
committed
Making version work in envs where get_distribution does not.
See http://stackoverflow.com/a/28095663/1068170 for context.
1 parent 927c534 commit a126550

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

gcloud/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
"""GCloud API access in idiomatic Python."""
1616

17-
from pkg_resources import get_distribution
18-
19-
__version__ = get_distribution('gcloud').version
17+
try:
18+
import pkg_resources
19+
__version__ = pkg_resources.get_distribution('gcloud').version
20+
except (ImportError, pkg_resources.DistributionNotFound): # pragma: NO COVER
21+
__version__ = None

gcloud/connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
""" Shared implementation of connections to API servers."""
1616

17-
from pkg_resources import get_distribution
18-
1917
import httplib2
2018

19+
import gcloud
20+
2121

2222
class Connection(object):
2323
"""A generic connection to Google Cloud Platform.
@@ -32,7 +32,7 @@ class Connection(object):
3232
_EMPTY = object()
3333
"""A pointer to represent an empty value for default arguments."""
3434

35-
USER_AGENT = "gcloud-python/{0}".format(get_distribution('gcloud').version)
35+
USER_AGENT = "gcloud-python/{0}".format(gcloud.__version__)
3636
"""The user agent for gcloud-python requests."""
3737

3838
def __init__(self, credentials=None):

0 commit comments

Comments
 (0)