Python 3.10 support: collections.abc (#20441)
This commit is contained in:
parent
f781403615
commit
40a40e0265
19 changed files with 140 additions and 42 deletions
5
lib/spack/external/_pytest/assertion/util.py
vendored
5
lib/spack/external/_pytest/assertion/util.py
vendored
|
@ -5,8 +5,11 @@
|
|||
import _pytest._code
|
||||
import py
|
||||
try:
|
||||
from collections import Sequence
|
||||
from collections.abc import Sequence
|
||||
except ImportError:
|
||||
try:
|
||||
from collections import Sequence
|
||||
except ImportError:
|
||||
Sequence = list
|
||||
|
||||
|
||||
|
|
5
lib/spack/external/_pytest/main.py
vendored
5
lib/spack/external/_pytest/main.py
vendored
|
@ -10,8 +10,11 @@
|
|||
import _pytest._code
|
||||
import py
|
||||
try:
|
||||
from collections import MutableMapping as MappingMixin
|
||||
from collections.abc import MutableMapping as MappingMixin
|
||||
except ImportError:
|
||||
try:
|
||||
from collections import MutableMapping as MappingMixin
|
||||
except ImportError:
|
||||
from UserDict import DictMixin as MappingMixin
|
||||
|
||||
from _pytest.config import directory_arg, UsageError, hookimpl
|
||||
|
|
3
lib/spack/external/_pytest/python_api.py
vendored
3
lib/spack/external/_pytest/python_api.py
vendored
|
@ -398,6 +398,9 @@ def approx(expected, rel=None, abs=None, nan_ok=False):
|
|||
__ https://docs.python.org/3/reference/datamodel.html#object.__ge__
|
||||
"""
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
from collections.abc import Mapping, Sequence
|
||||
else:
|
||||
from collections import Mapping, Sequence
|
||||
from _pytest.compat import STRING_TYPES as String
|
||||
|
||||
|
|
6
lib/spack/external/jinja2/runtime.py
vendored
6
lib/spack/external/jinja2/runtime.py
vendored
|
@ -315,9 +315,13 @@ def __repr__(self):
|
|||
|
||||
# register the context as mapping if possible
|
||||
try:
|
||||
from collections import Mapping
|
||||
from collections.abc import Mapping
|
||||
Mapping.register(Context)
|
||||
except ImportError:
|
||||
try:
|
||||
from collections import Mapping
|
||||
Mapping.register(Context)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
|
|
12
lib/spack/external/jinja2/sandbox.py
vendored
12
lib/spack/external/jinja2/sandbox.py
vendored
|
@ -14,7 +14,7 @@
|
|||
"""
|
||||
import types
|
||||
import operator
|
||||
from collections import Mapping
|
||||
import sys
|
||||
from jinja2.environment import Environment
|
||||
from jinja2.exceptions import SecurityError
|
||||
from jinja2._compat import string_types, PY2
|
||||
|
@ -23,6 +23,11 @@
|
|||
from markupsafe import EscapeFormatter
|
||||
from string import Formatter
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
from collections.abc import Mapping
|
||||
else:
|
||||
from collections import Mapping
|
||||
|
||||
|
||||
#: maximum number of items a range may produce
|
||||
MAX_RANGE = 100000
|
||||
|
@ -79,7 +84,10 @@
|
|||
pass
|
||||
|
||||
#: register Python 2.6 abstract base classes
|
||||
from collections import MutableSet, MutableMapping, MutableSequence
|
||||
if sys.version_info >= (3, 3):
|
||||
from collections.abc import MutableSet, MutableMapping, MutableSequence
|
||||
else:
|
||||
from collections import MutableSet, MutableMapping, MutableSequence
|
||||
_mutable_set_types += (MutableSet,)
|
||||
_mutable_mapping_types += (MutableMapping,)
|
||||
_mutable_sequence_types += (MutableSequence,)
|
||||
|
|
7
lib/spack/external/jinja2/tests.py
vendored
7
lib/spack/external/jinja2/tests.py
vendored
|
@ -10,11 +10,16 @@
|
|||
"""
|
||||
import operator
|
||||
import re
|
||||
from collections import Mapping
|
||||
import sys
|
||||
from jinja2.runtime import Undefined
|
||||
from jinja2._compat import text_type, string_types, integer_types
|
||||
import decimal
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
from collections.abc import Mapping
|
||||
else:
|
||||
from collections import Mapping
|
||||
|
||||
number_re = re.compile(r'^-?\d+(\.\d+)?$')
|
||||
regex_type = type(number_re)
|
||||
|
||||
|
|
6
lib/spack/external/jinja2/utils.py
vendored
6
lib/spack/external/jinja2/utils.py
vendored
|
@ -482,9 +482,13 @@ def __reversed__(self):
|
|||
|
||||
# register the LRU cache as mutable mapping if possible
|
||||
try:
|
||||
from collections import MutableMapping
|
||||
from collections.abc import MutableMapping
|
||||
MutableMapping.register(LRUCache)
|
||||
except ImportError:
|
||||
try:
|
||||
from collections import MutableMapping
|
||||
MutableMapping.register(LRUCache)
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
|
|
7
lib/spack/external/markupsafe/__init__.py
vendored
7
lib/spack/external/markupsafe/__init__.py
vendored
|
@ -10,10 +10,15 @@
|
|||
"""
|
||||
import re
|
||||
import string
|
||||
from collections import Mapping
|
||||
import sys
|
||||
from markupsafe._compat import text_type, string_types, int_types, \
|
||||
unichr, iteritems, PY2
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
from collections.abc import Mapping
|
||||
else:
|
||||
from collections import Mapping
|
||||
|
||||
__version__ = "1.0"
|
||||
|
||||
__all__ = ['Markup', 'soft_unicode', 'escape', 'escape_silent']
|
||||
|
|
7
lib/spack/external/ruamel/yaml/comments.py
vendored
7
lib/spack/external/ruamel/yaml/comments.py
vendored
|
@ -9,7 +9,12 @@
|
|||
a separate base
|
||||
"""
|
||||
|
||||
from collections import MutableSet
|
||||
import sys
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
from collections.abc import MutableSet
|
||||
else:
|
||||
from collections import MutableSet
|
||||
|
||||
__all__ = ["CommentedSeq", "CommentedMap", "CommentedOrderedMap",
|
||||
"CommentedSet", 'comment_attrib', 'merge_attrib']
|
||||
|
|
3
lib/spack/external/ruamel/yaml/compat.py
vendored
3
lib/spack/external/ruamel/yaml/compat.py
vendored
|
@ -11,6 +11,9 @@
|
|||
try:
|
||||
from ruamel.ordereddict import ordereddict
|
||||
except:
|
||||
try:
|
||||
from collections.abc import OrderedDict
|
||||
except ImportError:
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
|
|
19
lib/spack/external/ruamel/yaml/constructor.py
vendored
19
lib/spack/external/ruamel/yaml/constructor.py
vendored
|
@ -3,7 +3,6 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
|
||||
import collections
|
||||
import datetime
|
||||
import base64
|
||||
import binascii
|
||||
|
@ -26,6 +25,12 @@
|
|||
from ruamel.yaml.scalarstring import * # NOQA
|
||||
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
from collections.abc import Hashable
|
||||
else:
|
||||
from collections import Hashable
|
||||
|
||||
|
||||
__all__ = ['BaseConstructor', 'SafeConstructor', 'Constructor',
|
||||
'ConstructorError', 'RoundTripConstructor']
|
||||
|
||||
|
@ -163,7 +168,7 @@ def construct_mapping(self, node, deep=False):
|
|||
# keys can be list -> deep
|
||||
key = self.construct_object(key_node, deep=True)
|
||||
# lists are not hashable, but tuples are
|
||||
if not isinstance(key, collections.Hashable):
|
||||
if not isinstance(key, Hashable):
|
||||
if isinstance(key, list):
|
||||
key = tuple(key)
|
||||
if PY2:
|
||||
|
@ -175,7 +180,7 @@ def construct_mapping(self, node, deep=False):
|
|||
"found unacceptable key (%s)" %
|
||||
exc, key_node.start_mark)
|
||||
else:
|
||||
if not isinstance(key, collections.Hashable):
|
||||
if not isinstance(key, Hashable):
|
||||
raise ConstructorError(
|
||||
"while constructing a mapping", node.start_mark,
|
||||
"found unhashable key", key_node.start_mark)
|
||||
|
@ -959,7 +964,7 @@ def construct_mapping(self, node, maptyp, deep=False):
|
|||
# keys can be list -> deep
|
||||
key = self.construct_object(key_node, deep=True)
|
||||
# lists are not hashable, but tuples are
|
||||
if not isinstance(key, collections.Hashable):
|
||||
if not isinstance(key, Hashable):
|
||||
if isinstance(key, list):
|
||||
key = tuple(key)
|
||||
if PY2:
|
||||
|
@ -971,7 +976,7 @@ def construct_mapping(self, node, maptyp, deep=False):
|
|||
"found unacceptable key (%s)" %
|
||||
exc, key_node.start_mark)
|
||||
else:
|
||||
if not isinstance(key, collections.Hashable):
|
||||
if not isinstance(key, Hashable):
|
||||
raise ConstructorError(
|
||||
"while constructing a mapping", node.start_mark,
|
||||
"found unhashable key", key_node.start_mark)
|
||||
|
@ -1003,7 +1008,7 @@ def construct_setting(self, node, typ, deep=False):
|
|||
# keys can be list -> deep
|
||||
key = self.construct_object(key_node, deep=True)
|
||||
# lists are not hashable, but tuples are
|
||||
if not isinstance(key, collections.Hashable):
|
||||
if not isinstance(key, Hashable):
|
||||
if isinstance(key, list):
|
||||
key = tuple(key)
|
||||
if PY2:
|
||||
|
@ -1015,7 +1020,7 @@ def construct_setting(self, node, typ, deep=False):
|
|||
"found unacceptable key (%s)" %
|
||||
exc, key_node.start_mark)
|
||||
else:
|
||||
if not isinstance(key, collections.Hashable):
|
||||
if not isinstance(key, Hashable):
|
||||
raise ConstructorError(
|
||||
"while constructing a mapping", node.start_mark,
|
||||
"found unhashable key", key_node.start_mark)
|
||||
|
|
|
@ -23,6 +23,12 @@
|
|||
from llnl.util.lang import dedupe, memoized
|
||||
from spack.util.executable import Executable
|
||||
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
from collections.abc import Sequence # novm
|
||||
else:
|
||||
from collections import Sequence
|
||||
|
||||
__all__ = [
|
||||
'FileFilter',
|
||||
'FileList',
|
||||
|
@ -1106,7 +1112,7 @@ def find(root, files, recursive=True):
|
|||
|
||||
Parameters:
|
||||
root (str): The root directory to start searching from
|
||||
files (str or collections.Sequence): Library name(s) to search for
|
||||
files (str or Sequence): Library name(s) to search for
|
||||
recurse (bool, optional): if False search only root folder,
|
||||
if True descends top-down from the root. Defaults to True.
|
||||
|
||||
|
@ -1169,7 +1175,7 @@ def _find_non_recursive(root, search_files):
|
|||
# Utilities for libraries and headers
|
||||
|
||||
|
||||
class FileList(collections.Sequence):
|
||||
class FileList(Sequence):
|
||||
"""Sequence of absolute paths to files.
|
||||
|
||||
Provides a few convenience methods to manipulate file paths.
|
||||
|
@ -1412,7 +1418,7 @@ def find_headers(headers, root, recursive=False):
|
|||
"""
|
||||
if isinstance(headers, six.string_types):
|
||||
headers = [headers]
|
||||
elif not isinstance(headers, collections.Sequence):
|
||||
elif not isinstance(headers, Sequence):
|
||||
message = '{0} expects a string or sequence of strings as the '
|
||||
message += 'first argument [got {1} instead]'
|
||||
message = message.format(find_headers.__name__, type(headers))
|
||||
|
@ -1567,7 +1573,7 @@ def find_system_libraries(libraries, shared=True):
|
|||
"""
|
||||
if isinstance(libraries, six.string_types):
|
||||
libraries = [libraries]
|
||||
elif not isinstance(libraries, collections.Sequence):
|
||||
elif not isinstance(libraries, Sequence):
|
||||
message = '{0} expects a string or sequence of strings as the '
|
||||
message += 'first argument [got {1} instead]'
|
||||
message = message.format(find_system_libraries.__name__,
|
||||
|
@ -1621,7 +1627,7 @@ def find_libraries(libraries, root, shared=True, recursive=False):
|
|||
"""
|
||||
if isinstance(libraries, six.string_types):
|
||||
libraries = [libraries]
|
||||
elif not isinstance(libraries, collections.Sequence):
|
||||
elif not isinstance(libraries, Sequence):
|
||||
message = '{0} expects a string or sequence of strings as the '
|
||||
message += 'first argument [got {1} instead]'
|
||||
message = message.format(find_libraries.__name__, type(libraries))
|
||||
|
|
|
@ -9,13 +9,18 @@
|
|||
import os
|
||||
import re
|
||||
import functools
|
||||
import collections
|
||||
import inspect
|
||||
from datetime import datetime, timedelta
|
||||
from six import string_types
|
||||
import sys
|
||||
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
from collections.abc import Hashable, MutableMapping # novm
|
||||
else:
|
||||
from collections import Hashable, MutableMapping
|
||||
|
||||
|
||||
# Ignore emacs backups when listing modules
|
||||
ignore_modules = [r'^\.#', '~$']
|
||||
|
||||
|
@ -189,7 +194,7 @@ def memoized(func):
|
|||
|
||||
@functools.wraps(func)
|
||||
def _memoized_function(*args):
|
||||
if not isinstance(args, collections.Hashable):
|
||||
if not isinstance(args, Hashable):
|
||||
# Not hashable, so just call the function.
|
||||
return func(*args)
|
||||
|
||||
|
@ -264,7 +269,7 @@ def setter(name, value):
|
|||
|
||||
|
||||
@key_ordering
|
||||
class HashableMap(collections.MutableMapping):
|
||||
class HashableMap(MutableMapping):
|
||||
"""This is a hashable, comparable dictionary. Hash is performed on
|
||||
a tuple of the values in the dictionary."""
|
||||
|
||||
|
|
|
@ -28,10 +28,11 @@ class OpenMpi(Package):
|
|||
|
||||
"""
|
||||
|
||||
import collections
|
||||
import functools
|
||||
import os.path
|
||||
import re
|
||||
import sys
|
||||
|
||||
from six import string_types
|
||||
from typing import Set, List # novm
|
||||
|
||||
|
@ -48,6 +49,13 @@ class OpenMpi(Package):
|
|||
from spack.resource import Resource
|
||||
from spack.version import Version, VersionChecksumError
|
||||
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
from collections.abc import Sequence # novm
|
||||
else:
|
||||
from collections import Sequence
|
||||
|
||||
|
||||
__all__ = []
|
||||
|
||||
#: These are variant names used by Spack internally; packages can't use them
|
||||
|
@ -203,7 +211,7 @@ class Foo(Package):
|
|||
|
||||
if isinstance(dicts, string_types):
|
||||
dicts = (dicts, )
|
||||
if not isinstance(dicts, collections.Sequence):
|
||||
if not isinstance(dicts, Sequence):
|
||||
message = "dicts arg must be list, tuple, or string. Found {0}"
|
||||
raise TypeError(message.format(type(dicts)))
|
||||
# Add the dictionary names if not already there
|
||||
|
@ -244,7 +252,7 @@ def remove_directives(arg):
|
|||
|
||||
# ...so if it is not a sequence make it so
|
||||
values = result
|
||||
if not isinstance(values, collections.Sequence):
|
||||
if not isinstance(values, Sequence):
|
||||
values = (values, )
|
||||
|
||||
DirectiveMeta._directives_to_be_executed.extend(values)
|
||||
|
|
|
@ -40,6 +40,12 @@
|
|||
import spack.version
|
||||
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
from collections.abc import Sequence # novm
|
||||
else:
|
||||
from collections import Sequence
|
||||
|
||||
|
||||
class Timer(object):
|
||||
"""Simple timer for timing phases of a solve"""
|
||||
def __init__(self):
|
||||
|
@ -64,7 +70,7 @@ def write(self, out=sys.stdout):
|
|||
def issequence(obj):
|
||||
if isinstance(obj, string_types):
|
||||
return False
|
||||
return isinstance(obj, (collections.Sequence, types.GeneratorType))
|
||||
return isinstance(obj, (Sequence, types.GeneratorType))
|
||||
|
||||
|
||||
def listify(args):
|
||||
|
|
|
@ -116,6 +116,13 @@
|
|||
import spack.variant as vt
|
||||
import spack.version as vn
|
||||
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
from collections.abc import Mapping # novm
|
||||
else:
|
||||
from collections import Mapping
|
||||
|
||||
|
||||
__all__ = [
|
||||
'Spec',
|
||||
'parse',
|
||||
|
@ -2120,7 +2127,7 @@ def validate_detection(self):
|
|||
# which likely means the spec was created with Spec.from_detection
|
||||
msg = ('cannot validate "{0}" since it was not created '
|
||||
'using Spec.from_detection'.format(self))
|
||||
assert isinstance(self.extra_attributes, collections.Mapping), msg
|
||||
assert isinstance(self.extra_attributes, Mapping), msg
|
||||
|
||||
# Validate the spec calling a package specific method
|
||||
validate_fn = getattr(
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
import ast
|
||||
import inspect
|
||||
import os
|
||||
|
||||
from collections import Iterable, Mapping
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -29,6 +28,12 @@
|
|||
from spack.util.mock_package import MockPackageMultiRepo
|
||||
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
from collections.abc import Iterable, Mapping # novm
|
||||
else:
|
||||
from collections import Iterable, Mapping
|
||||
|
||||
|
||||
def check_yaml_round_trip(spec):
|
||||
yaml_text = spec.to_yaml()
|
||||
spec_from_yaml = Spec.from_yaml(yaml_text)
|
||||
|
|
|
@ -4,8 +4,14 @@
|
|||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||
|
||||
import inspect
|
||||
import collections
|
||||
import functools
|
||||
import sys
|
||||
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
from collections.abc import MutableSequence # novm
|
||||
else:
|
||||
from collections import MutableSequence
|
||||
|
||||
|
||||
class Delegate(object):
|
||||
|
@ -52,7 +58,7 @@ def composite(interface=None, method_list=None, container=list):
|
|||
# exception if it doesn't. The patched class returned by the decorator will
|
||||
# inherit from the container class to expose the interface needed to manage
|
||||
# objects composition
|
||||
if not issubclass(container, collections.MutableSequence):
|
||||
if not issubclass(container, MutableSequence):
|
||||
raise TypeError("Container must fulfill the MutableSequence contract")
|
||||
|
||||
# Check if at least one of the 'interface' or the 'method_list' arguments
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
"""
|
||||
import ctypes
|
||||
import collections
|
||||
import sys
|
||||
from typing import List # novm
|
||||
|
||||
from ordereddict_backport import OrderedDict
|
||||
|
@ -26,6 +26,13 @@
|
|||
|
||||
import spack.error
|
||||
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
from collections.abc import Mapping # novm
|
||||
else:
|
||||
from collections import Mapping
|
||||
|
||||
|
||||
# Only export load and dump
|
||||
__all__ = ['load', 'dump', 'SpackYAMLError']
|
||||
|
||||
|
@ -344,7 +351,7 @@ def sorted_dict(dict_like):
|
|||
"""
|
||||
result = syaml_dict(sorted(dict_like.items()))
|
||||
for key, value in result.items():
|
||||
if isinstance(value, collections.Mapping):
|
||||
if isinstance(value, Mapping):
|
||||
result[key] = sorted_dict(value)
|
||||
return result
|
||||
|
||||
|
|
Loading…
Reference in a new issue