Merge "Handle move of ABCs to collections.abc"

This commit is contained in:
Zuul 2019-09-10 16:43:52 +00:00 committed by Gerrit Code Review
commit 63a28d40b2
7 changed files with 71 additions and 14 deletions

View File

@ -52,6 +52,15 @@ from horizon.utils import settings as utils_settings
DEFAULT_PANEL_GROUP = 'default' DEFAULT_PANEL_GROUP = 'default'
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
# Python 3.8 removes the ability to import the abstract base classes from
# 'collections', but 'collections.abc' is not present in Python 2.7
# TODO(stephenfin): Remove when we drop support for Python 2.7
# pylint: disable=ungrouped-imports
if hasattr(collections, 'abc'):
from collections.abc import Iterable
else:
from collections import Iterable
def _decorate_urlconf(urlpatterns, decorator, *args, **kwargs): def _decorate_urlconf(urlpatterns, decorator, *args, **kwargs):
for pattern in urlpatterns: for pattern in urlpatterns:
@ -591,7 +600,7 @@ class Dashboard(Registry, HorizonComponent):
default_created = False default_created = False
for panel_set in self.panels: for panel_set in self.panels:
# Instantiate PanelGroup classes. # Instantiate PanelGroup classes.
if not isinstance(panel_set, collections.Iterable) and \ if not isinstance(panel_set, Iterable) and \
issubclass(panel_set, PanelGroup): issubclass(panel_set, PanelGroup):
panel_group = panel_set(self) panel_group = panel_set(self)
# Check for nested tuples, and convert them to PanelGroups # Check for nested tuples, and convert them to PanelGroups

View File

@ -48,6 +48,15 @@ from horizon.tables.actions import LinkAction
from horizon.utils import html from horizon.utils import html
from horizon.utils import settings as utils_settings from horizon.utils import settings as utils_settings
# Python 3.8 removes the ability to import the abstract base classes from
# 'collections', but 'collections.abc' is not present in Python 2.7
# TODO(stephenfin): Remove when we drop support for Python 2.7
# pylint: disable=ungrouped-imports
if hasattr(collections, 'abc'):
from collections.abc import Mapping
else:
from collections import Mapping
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
PALETTE = termcolors.PALETTES[termcolors.DEFAULT_PALETTE] PALETTE = termcolors.PALETTES[termcolors.DEFAULT_PALETTE]
@ -406,8 +415,7 @@ class Column(html.HTMLElement):
if callable(self.transform): if callable(self.transform):
data = self.transform(datum) data = self.transform(datum)
# Dict lookups # Dict lookups
elif isinstance(datum, collections.Mapping) and \ elif isinstance(datum, Mapping) and self.transform in datum:
self.transform in datum:
data = datum.get(self.transform) data = datum.get(self.transform)
else: else:
# Basic object lookups # Basic object lookups

View File

@ -45,6 +45,15 @@ from django.contrib.staticfiles.testing \
from horizon import middleware from horizon import middleware
# Python 3.8 removes the ability to import the abstract base classes from
# 'collections', but 'collections.abc' is not present in Python 2.7
# TODO(stephenfin): Remove when we drop support for Python 2.7
# pylint: disable=ungrouped-imports
if hasattr(collections, 'abc'):
from collections.abc import Mapping
else:
from collections import Mapping
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -335,8 +344,8 @@ class update_settings(django_test_utils.override_settings):
if keep_dict: if keep_dict:
for key, new_value in kwargs.items(): for key, new_value in kwargs.items():
value = getattr(settings, key, None) value = getattr(settings, key, None)
if (isinstance(new_value, collections.Mapping) and if (isinstance(new_value, Mapping) and
isinstance(value, collections.Mapping)): isinstance(value, Mapping)):
copied = copy.copy(value) copied = copy.copy(value)
copied.update(new_value) copied.update(new_value)
kwargs[key] = copied kwargs[key] = copied

View File

@ -16,7 +16,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from collections import Sequence import collections
import functools import functools
from django.conf import settings from django.conf import settings
@ -25,6 +25,15 @@ import six
from horizon import exceptions from horizon import exceptions
# Python 3.8 removes the ability to import the abstract base classes from
# 'collections', but 'collections.abc' is not present in Python 2.7
# TODO(stephenfin): Remove when we drop support for Python 2.7
# pylint: disable=ungrouped-imports
if hasattr(collections, 'abc'):
from collections.abc import Sequence
else:
from collections import Sequence
__all__ = ('APIResourceWrapper', 'APIDictWrapper', __all__ = ('APIResourceWrapper', 'APIDictWrapper',
'get_service_from_catalog', 'url_for',) 'get_service_from_catalog', 'url_for',)

View File

@ -39,6 +39,15 @@ from horizon.utils.memoized import memoized
from openstack_dashboard.api import base from openstack_dashboard.api import base
from openstack_dashboard.contrib.developer.profiler import api as profiler from openstack_dashboard.contrib.developer.profiler import api as profiler
# Python 3.8 removes the ability to import the abstract base classes from
# 'collections', but 'collections.abc' is not present in Python 2.7
# TODO(stephenfin): Remove when we drop support for Python 2.7
# pylint: disable=ungrouped-imports
if hasattr(collections, 'abc'):
from collections.abc import Iterable
else:
from collections import Iterable
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
VERSIONS = base.APIVersionManager("image", preferred_version=2) VERSIONS = base.APIVersionManager("image", preferred_version=2)
@ -125,7 +134,7 @@ class Image(base.APIResourceWrapper):
# for v2), self._apiresource is not iterable. In that case, # for v2), self._apiresource is not iterable. In that case,
# the properties are included in the apiresource dict, so # the properties are included in the apiresource dict, so
# just return that dict. # just return that dict.
if not isinstance(self._apiresource, collections.Iterable): if not isinstance(self._apiresource, Iterable):
return self._apiresource.to_dict() return self._apiresource.to_dict()
image_dict = super(Image, self).to_dict() image_dict = super(Image, self).to_dict()
image_dict['is_public'] = self.is_public image_dict['is_public'] = self.is_public

View File

@ -40,6 +40,15 @@ from openstack_dashboard.api import nova
from openstack_dashboard.contrib.developer.profiler import api as profiler from openstack_dashboard.contrib.developer.profiler import api as profiler
from openstack_dashboard import policy from openstack_dashboard import policy
# Python 3.8 removes the ability to import the abstract base classes from
# 'collections', but 'collections.abc' is not present in Python 2.7
# TODO(stephenfin): Remove when we drop support for Python 2.7
# pylint: disable=ungrouped-imports
if hasattr(collections, 'abc'):
from collections.abc import Sequence
else:
from collections import Sequence
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -854,14 +863,9 @@ def list_resources_with_long_filters(list_method,
# filter_values) and do not consider other filter conditions # filter_values) and do not consider other filter conditions
# which may be specified in **params. # which may be specified in **params.
# NOTE(pas-ha) this will produce a deprecation warning in Py37
# and will not work in Py38, and six.moves also does not support it
# (see https://github.com/benjaminp/six/issues/155).
# TODO(pas-ha) replace with collections.abc.Sequence
# after dropping py27 support in U release
if isinstance(filter_values, six.string_types): if isinstance(filter_values, six.string_types):
filter_values = [filter_values] filter_values = [filter_values]
elif not isinstance(filter_values, collections.Sequence): elif not isinstance(filter_values, Sequence):
filter_values = list(filter_values) filter_values = list(filter_values)
# Length of each query filter is: # Length of each query filter is:

View File

@ -18,6 +18,15 @@ import testtools
from openstack_dashboard.test.integration_tests import config from openstack_dashboard.test.integration_tests import config
# Python 3.8 removes the ability to import the abstract base classes from
# 'collections', but 'collections.abc' is not present in Python 2.7
# TODO(stephenfin): Remove when we drop support for Python 2.7
# pylint: disable=ungrouped-imports
if hasattr(collections, 'abc'):
from collections.abc import Iterable
else:
from collections import Iterable
def _is_test_method_name(method): def _is_test_method_name(method):
return method.startswith('test_') return method.startswith('test_')
@ -156,7 +165,7 @@ def skip_because(**kwargs):
def actual_decoration(obj): def actual_decoration(obj):
skip_method = _get_skip_method(obj) skip_method = _get_skip_method(obj)
bugs = kwargs.get("bugs") bugs = kwargs.get("bugs")
if bugs and isinstance(bugs, collections.Iterable): if bugs and isinstance(bugs, Iterable):
for bug in bugs: for bug in bugs:
if not bug.isdigit(): if not bug.isdigit():
raise ValueError("bug must be a valid bug number") raise ValueError("bug must be a valid bug number")