Browse Source

Merge "Handle move of ABCs to collections.abc"

tags/16.0.0.0b2
Zuul 5 months ago
parent
commit
63a28d40b2
7 changed files with 71 additions and 14 deletions
  1. +10
    -1
      horizon/base.py
  2. +10
    -2
      horizon/tables/base.py
  3. +11
    -2
      horizon/test/helpers.py
  4. +10
    -1
      openstack_dashboard/api/base.py
  5. +10
    -1
      openstack_dashboard/api/glance.py
  6. +10
    -6
      openstack_dashboard/api/neutron.py
  7. +10
    -1
      openstack_dashboard/test/integration_tests/decorators.py

+ 10
- 1
horizon/base.py View File

@@ -52,6 +52,15 @@ from horizon.utils import settings as utils_settings
DEFAULT_PANEL_GROUP = 'default'
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):
for pattern in urlpatterns:
@@ -591,7 +600,7 @@ class Dashboard(Registry, HorizonComponent):
default_created = False
for panel_set in self.panels:
# Instantiate PanelGroup classes.
if not isinstance(panel_set, collections.Iterable) and \
if not isinstance(panel_set, Iterable) and \
issubclass(panel_set, PanelGroup):
panel_group = panel_set(self)
# Check for nested tuples, and convert them to PanelGroups

+ 10
- 2
horizon/tables/base.py View File

@@ -48,6 +48,15 @@ from horizon.tables.actions import LinkAction
from horizon.utils import html
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__)
PALETTE = termcolors.PALETTES[termcolors.DEFAULT_PALETTE]
@@ -406,8 +415,7 @@ class Column(html.HTMLElement):
if callable(self.transform):
data = self.transform(datum)
# Dict lookups
elif isinstance(datum, collections.Mapping) and \
self.transform in datum:
elif isinstance(datum, Mapping) and self.transform in datum:
data = datum.get(self.transform)
else:
# Basic object lookups

+ 11
- 2
horizon/test/helpers.py View File

@@ -45,6 +45,15 @@ from django.contrib.staticfiles.testing \

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__)

@@ -335,8 +344,8 @@ class update_settings(django_test_utils.override_settings):
if keep_dict:
for key, new_value in kwargs.items():
value = getattr(settings, key, None)
if (isinstance(new_value, collections.Mapping) and
isinstance(value, collections.Mapping)):
if (isinstance(new_value, Mapping) and
isinstance(value, Mapping)):
copied = copy.copy(value)
copied.update(new_value)
kwargs[key] = copied

+ 10
- 1
openstack_dashboard/api/base.py View File

@@ -16,7 +16,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from collections import Sequence
import collections
import functools

from django.conf import settings
@@ -25,6 +25,15 @@ import six

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',
'get_service_from_catalog', 'url_for',)

+ 10
- 1
openstack_dashboard/api/glance.py View File

@@ -39,6 +39,15 @@ from horizon.utils.memoized import memoized
from openstack_dashboard.api import base
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__)
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,
# the properties are included in the apiresource dict, so
# just return that dict.
if not isinstance(self._apiresource, collections.Iterable):
if not isinstance(self._apiresource, Iterable):
return self._apiresource.to_dict()
image_dict = super(Image, self).to_dict()
image_dict['is_public'] = self.is_public

+ 10
- 6
openstack_dashboard/api/neutron.py 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 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__)

@@ -854,14 +863,9 @@ def list_resources_with_long_filters(list_method,
# filter_values) and do not consider other filter conditions
# 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):
filter_values = [filter_values]
elif not isinstance(filter_values, collections.Sequence):
elif not isinstance(filter_values, Sequence):
filter_values = list(filter_values)

# Length of each query filter is:

+ 10
- 1
openstack_dashboard/test/integration_tests/decorators.py View File

@@ -18,6 +18,15 @@ import testtools

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):
return method.startswith('test_')
@@ -156,7 +165,7 @@ def skip_because(**kwargs):
def actual_decoration(obj):
skip_method = _get_skip_method(obj)
bugs = kwargs.get("bugs")
if bugs and isinstance(bugs, collections.Iterable):
if bugs and isinstance(bugs, Iterable):
for bug in bugs:
if not bug.isdigit():
raise ValueError("bug must be a valid bug number")

Loading…
Cancel
Save