Make PrettyTable optional

PrettyTable as a depend can have a tendency to conflict with other
things that want to use it, which is a shame for a general purpose
library like futurist. Make it optional to reduce the transitive
dependency burden for consumers.

Change-Id: Ie976f7f4e544f273fccf0cf579b82b659cbd48d1
This commit is contained in:
Monty Taylor 2020-03-03 09:40:07 -06:00
parent 0c5e44839c
commit 79f240b79f
4 changed files with 21 additions and 4 deletions

View File

@ -25,7 +25,10 @@ import random
import threading
from concurrent import futures
import prettytable
try:
import prettytable
except ImportError:
prettytable = None
import six
import futurist
@ -748,10 +751,17 @@ class PeriodicWorker(object):
cols = list(_DEFAULT_COLS)
for c in ['Runs in', 'Active', 'Periodicity']:
cols.remove(c)
self._log.debug("Stopped running %s callbacks:\n%s",
len(self._works), self.pformat(columns=cols))
self._log.debug(
"Stopped running %s callbacks:\n%s",
len(self._works),
self.pformat(columns=cols) if prettytable
else "statistics not available, PrettyTable missing"
)
def pformat(self, columns=_DEFAULT_COLS):
if prettytable is None:
raise ImportError(
"PrettyTable is required to use the pformat method")
# Convert to a list to ensure we maintain the same order when used
# further in this function (since order will matter)...
if not isinstance(columns, (list, tuple)):

View File

@ -0,0 +1,7 @@
---
upgrade:
- |
The ``PrettyTable`` dependency has been made optional, as it
is only used in the `Periodics.pformat` method. If the use
of that method is important, users should depend on
``PrettyTable`` directly.

View File

@ -4,4 +4,3 @@
pbr!=2.1.0,>=2.0.0 # Apache-2.0
six>=1.10.0 # MIT
PrettyTable<0.8,>=0.7.1 # BSD

View File

@ -14,3 +14,4 @@ oslotest>=3.2.0 # Apache-2.0
stestr>=2.0.0 # Apache-2.0
testscenarios>=0.4 # Apache-2.0/BSD
testtools>=2.2.0 # MIT
PrettyTable<0.8,>=0.7.1 # BSD