Skip to content

Commit

Permalink
Make the use of pkg_resources optional
Browse files Browse the repository at this point in the history
As it's only to enhance the logging, we'll just log the version of
argo_ams_library if the module is available. pkg_resources is
distributed with setuptools, which is commonly installed, but we don't
want to add any dependencies for this "nice to have" functionality.
  • Loading branch information
tofu-rocketry committed Aug 2, 2022
1 parent 0ed8766 commit 46756d1
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ssm/ssm2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"""
from __future__ import print_function

import pkg_resources

from ssm import crypto
from ssm.message_directory import MessageDirectory

Expand All @@ -28,6 +26,13 @@
QueueSimple = None
Queue = None

try:
import pkg_resources
except ImportError:
# pkg_resources is distributed with setuptools, but as it's only used to enhance
# the logging, it can be optional.
pkg_resources = None

import stomp
from stomp.exception import ConnectFailedException

Expand Down Expand Up @@ -551,7 +556,9 @@ def handle_connect(self):
connect to each in turn until successful.
"""
if self._protocol == Ssm2.AMS_MESSAGING:
log.info("Using AMS version %s", pkg_resources.get_distribution('argo_ams_library').version)
if pkg_resources is not None:
# We only log the version if pkg_resources is available.
log.info("Using AMS version %s", pkg_resources.get_distribution('argo_ams_library').version)

log.info("Will connect to %s", self._brokers[0])

Expand Down

0 comments on commit 46756d1

Please sign in to comment.