From 79f240b79fc15ce4ba291b2344cd509f8522f92c Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Tue, 3 Mar 2020 09:40:07 -0600 Subject: [PATCH] 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 --- futurist/periodics.py | 16 +++++++++++++--- .../prettytable-optional-2c9198a9250427b6.yaml | 7 +++++++ requirements.txt | 1 - test-requirements.txt | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/prettytable-optional-2c9198a9250427b6.yaml diff --git a/futurist/periodics.py b/futurist/periodics.py index 6b8980b..eb04af7 100644 --- a/futurist/periodics.py +++ b/futurist/periodics.py @@ -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)): diff --git a/releasenotes/notes/prettytable-optional-2c9198a9250427b6.yaml b/releasenotes/notes/prettytable-optional-2c9198a9250427b6.yaml new file mode 100644 index 0000000..6b50ffc --- /dev/null +++ b/releasenotes/notes/prettytable-optional-2c9198a9250427b6.yaml @@ -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. diff --git a/requirements.txt b/requirements.txt index 9387b04..a072ac0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/test-requirements.txt b/test-requirements.txt index 8e848c3..59345ba 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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