python: Remove Python 2.7 compatibility code

We don't support Python 2.7 anymore. Remove glue code like the six
dependency and "from __future__" imports from gem5's standard library.

Change-Id: I71834c325f86ff0329b222be87794ead96081f05
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/39584
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Gabe Black <gabe.black@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
This commit is contained in:
Andreas Sandberg
2021-01-21 17:09:38 +00:00
parent 36ab8ef4e7
commit 4b9c46caa5
28 changed files with 32 additions and 133 deletions

View File

@@ -24,9 +24,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
from __future__ import absolute_import
# Simple importer that allows python to import data from a dict of
# code objects. The keys are the module path, and the items are the
# filename and bytecode of the file.

View File

@@ -38,13 +38,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
from __future__ import absolute_import
from six import add_metaclass
import six
if six.PY3:
long = int
import sys
from types import FunctionType, MethodType, ModuleType
from functools import wraps
@@ -1178,8 +1171,7 @@ class SimObjectCliWrapper(object):
# The SimObject class is the root of the special hierarchy. Most of
# the code in this class deals with the configuration hierarchy itself
# (parent/child node relationships).
@add_metaclass(MetaSimObject)
class SimObject(object):
class SimObject(object, metaclass=MetaSimObject):
# Specify metaclass. Any class inheriting from SimObject will
# get this metaclass.
type = 'SimObject'

View File

@@ -24,9 +24,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
from __future__ import absolute_import
# Import useful subpackages of M5, but *only* when run as an m5
# script. This is mostly to keep backward compatibility with existing
# scripts while allowing new SCons code to operate properly.

View File

@@ -36,8 +36,5 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
from __future__ import absolute_import
from _m5.core import setOutputDir
from _m5.loader import setInterpDir

View File

@@ -24,8 +24,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
from collections import Mapping
import _m5.debug

View File

@@ -38,8 +38,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
import m5
import _m5.event

View File

@@ -35,5 +35,3 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
from __future__ import absolute_import

View File

@@ -36,9 +36,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
from __future__ import absolute_import
import inspect
import _m5

View File

@@ -36,8 +36,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
import code
import datetime
import os

View File

@@ -24,9 +24,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
from __future__ import absolute_import
from m5.internal import params
from m5.SimObject import *

View File

@@ -24,9 +24,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
from __future__ import absolute_import
import optparse
import sys

View File

@@ -54,12 +54,6 @@
#
#####################################################################
from __future__ import print_function
from six import with_metaclass
import six
if six.PY3:
long = int
import copy
import datetime
import re
@@ -97,7 +91,7 @@ class MetaParamValue(type):
# Dummy base class to identify types that are legitimate for SimObject
# parameters.
class ParamValue(with_metaclass(MetaParamValue, object)):
class ParamValue(object, metaclass=MetaParamValue):
cmd_line_settable = False
# Generate the code needed as a prerequisite for declaring a C++
@@ -235,7 +229,7 @@ class ParamDesc(object):
# that the value is a vector (list) of the specified type instead of a
# single value.
class VectorParamValue(with_metaclass(MetaParamValue, list)):
class VectorParamValue(list, metaclass=MetaParamValue):
def __setattr__(self, attr, value):
raise AttributeError("Not allowed to set %s on '%s'" % \
(attr, type(self).__name__))
@@ -467,9 +461,6 @@ class NumericParamValue(ParamValue):
def __float__(self):
return float(self.value)
def __long__(self):
return long(self.value)
def __int__(self):
return int(self.value)
@@ -538,11 +529,6 @@ class NumericParamValue(ParamValue):
def __lt__(self, other):
return self.value < NumericParamValue.unwrap(other)
# Python 2.7 pre __future__.division operators
# TODO: Remove these when after "import division from __future__"
__div__ = __truediv__
__idiv__ = __itruediv__
def config_value(self):
return self.value
@@ -586,7 +572,7 @@ class CheckedIntType(MetaParamValue):
# class is subclassed to generate parameter classes with specific
# bounds. Initialization of the min and max bounds is done in the
# metaclass CheckedIntType.__init__.
class CheckedInt(with_metaclass(CheckedIntType, NumericParamValue)):
class CheckedInt(NumericParamValue, metaclass=CheckedIntType):
cmd_line_settable = True
def _check(self):
@@ -597,8 +583,8 @@ class CheckedInt(with_metaclass(CheckedIntType, NumericParamValue)):
def __init__(self, value):
if isinstance(value, str):
self.value = convert.toInteger(value)
elif isinstance(value, (int, long, float, NumericParamValue)):
self.value = long(value)
elif isinstance(value, (int, float, NumericParamValue)):
self.value = int(value)
else:
raise TypeError("Can't convert object of type %s to CheckedInt" \
% type(value).__name__)
@@ -617,7 +603,7 @@ class CheckedInt(with_metaclass(CheckedIntType, NumericParamValue)):
code('#include "base/types.hh"')
def getValue(self):
return long(self.value)
return int(self.value)
class Int(CheckedInt): cxx_type = 'int'; size = 32; unsigned = False
class Unsigned(CheckedInt): cxx_type = 'unsigned'; size = 32; unsigned = True
@@ -666,7 +652,7 @@ class Float(ParamValue, float):
cmd_line_settable = True
def __init__(self, value):
if isinstance(value, (int, long, float, NumericParamValue, Float, str)):
if isinstance(value, (int, float, NumericParamValue, Float, str)):
self.value = float(value)
else:
raise TypeError("Can't convert object of type %s to Float" \
@@ -732,7 +718,7 @@ class Addr(CheckedInt):
except (TypeError, ValueError):
# Convert number to string and use long() to do automatic
# base conversion (requires base=0 for auto-conversion)
self.value = long(str(value), base=0)
self.value = int(str(value), base=0)
self._check()
def __add__(self, other):
@@ -744,8 +730,8 @@ class Addr(CheckedInt):
try:
val = convert.toMemorySize(value)
except TypeError:
val = long(value)
return "0x%x" % long(val)
val = int(value)
return "0x%x" % int(val)
class AddrRange(ParamValue):
cxx_type = 'AddrRange'
@@ -772,7 +758,7 @@ class AddrRange(ParamValue):
self.intlvMatch = int(kwargs.pop('intlvMatch'))
if 'masks' in kwargs:
self.masks = [ long(x) for x in list(kwargs.pop('masks')) ]
self.masks = [ int(x) for x in list(kwargs.pop('masks')) ]
self.intlvBits = len(self.masks)
else:
if 'intlvBits' in kwargs:
@@ -825,7 +811,7 @@ class AddrRange(ParamValue):
def size(self):
# Divide the size by the size of the interleaving slice
return (long(self.end) - long(self.start)) >> self.intlvBits
return (int(self.end) - int(self.start)) >> self.intlvBits
@classmethod
def cxx_predecls(cls, code):
@@ -875,7 +861,7 @@ class AddrRange(ParamValue):
# Go from the Python class to the wrapped C++ class
from _m5.range import AddrRange
return AddrRange(long(self.start), long(self.end),
return AddrRange(int(self.start), int(self.end),
self.masks, int(self.intlvMatch))
# Boolean parameter type. Python doesn't let you subclass bool, since
@@ -1016,7 +1002,7 @@ class IpAddress(ParamValue):
try:
self.ip = convert.toIpAddress(value)
except TypeError:
self.ip = long(value)
self.ip = int(value)
self.verifyIp()
def __call__(self, value):
@@ -1218,7 +1204,7 @@ def parse_time(value):
if isinstance(value, struct_time):
return value
if isinstance(value, (int, long)):
if isinstance(value, int):
return gmtime(value)
if isinstance(value, (datetime, date)):
@@ -1444,7 +1430,7 @@ module_init(py::module &m_internal)
# Base class for enum types.
class Enum(with_metaclass(MetaEnum, ParamValue)):
class Enum(ParamValue, metaclass=MetaEnum):
vals = []
cmd_line_settable = True
@@ -1538,7 +1524,7 @@ class TickParamValue(NumericParamValue):
return value
def getValue(self):
return long(self.value)
return int(self.value)
@classmethod
def cxx_ini_predecls(cls, code):
@@ -1583,7 +1569,7 @@ class Latency(TickParamValue):
value = self.value
else:
value = ticks.fromSeconds(self.value)
return long(value)
return int(value)
def config_value(self):
return self.getValue()
@@ -1626,7 +1612,7 @@ class Frequency(TickParamValue):
value = self.value
else:
value = ticks.fromSeconds(1.0 / self.value)
return long(value)
return int(value)
def config_value(self):
return self.getValue()
@@ -1792,7 +1778,7 @@ class MemoryBandwidth(float,ParamValue):
# make_param_value() above that lets these be assigned where a
# SimObject is required.
# only one copy of a particular node
class NullSimObject(with_metaclass(Singleton, object)):
class NullSimObject(object, metaclass=Singleton):
_name = 'Null'
def __call__(cls):
@@ -2159,7 +2145,7 @@ VectorSlavePort = VectorResponsePort
# 'Fake' ParamDesc for Port references to assign to the _pdesc slot of
# proxy objects (via set_param_desc()) so that proxy error messages
# make sense.
class PortParamDesc(with_metaclass(Singleton, object)):
class PortParamDesc(object, metaclass=Singleton):
ptype_str = 'Port'
ptype = Port

View File

@@ -42,15 +42,8 @@
#
#####################################################################
from __future__ import print_function
from __future__ import absolute_import
import six
if six.PY3:
long = int
import copy
class BaseProxy(object):
def __init__(self, search_self, search_up):
self._search_self = search_self
@@ -74,7 +67,7 @@ class BaseProxy(object):
def _gen_op(operation):
def op(self, operand):
if not (isinstance(operand, (int, long, float)) or \
if not (isinstance(operand, (int, float)) or \
isproxy(operand)):
raise TypeError(
"Proxy operand must be a constant or a proxy to a param")

View File

@@ -37,8 +37,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
import atexit
import os
import sys

View File

@@ -37,9 +37,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
from __future__ import absolute_import
import m5
import _m5.stats

View File

@@ -24,11 +24,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
import decimal
import six
if six.PY3:
long = int
import sys
from m5.util import warn
@@ -42,7 +38,7 @@ def setGlobalFrequency(ticksPerSecond):
from m5.util import convert
import _m5.core
if isinstance(ticksPerSecond, (int, long)):
if isinstance(ticksPerSecond, int):
tps = ticksPerSecond
elif isinstance(ticksPerSecond, float):
tps = ticksPerSecond

View File

@@ -24,8 +24,5 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
from __future__ import absolute_import
# Export native methods to Python
from _m5.trace import output, ignore, disable, enable

View File

@@ -37,14 +37,11 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
import os
import re
import sys
from six import string_types
from six.moves import zip_longest
from itertools import zip_longest
from . import convert
from . import jobfile
@@ -123,7 +120,7 @@ def compareVersions(v1, v2):
def make_version_list(v):
if isinstance(v, (list,tuple)):
return v
elif isinstance(v, string_types):
elif isinstance(v, str):
return list(map(lambda x: int(re.match('\d+', x).group()),
v.split('.')))
else:

View File

@@ -24,8 +24,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
__all__ = [ 'attrdict', 'multiattrdict', 'optiondict' ]
class attrdict(dict):

View File

@@ -24,9 +24,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
from six import add_metaclass
try:
import builtins
except ImportError:
@@ -112,8 +109,7 @@ class code_formatter_meta(type):
}
cls.pattern = re.compile(pat, re.VERBOSE | re.DOTALL | re.MULTILINE)
@add_metaclass(code_formatter_meta)
class code_formatter(object):
class code_formatter(object, metaclass=code_formatter_meta):
delim = r'$'
ident = r'[_A-z]\w*'
pos = r'[0-9]+'

View File

@@ -25,10 +25,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import six
if six.PY3:
long = int
# metric prefixes
atto = 1.0e-18
femto = 1.0e-15

View File

@@ -53,9 +53,6 @@
#
#####################################################################
from __future__ import print_function
from __future__ import absolute_import
import m5, os, re
from m5.SimObject import isRoot, isSimObjectVector
from m5.params import PortRef, isNullPointer

View File

@@ -35,10 +35,6 @@
#
# Author: Glenn Bergmans
import six
if six.PY3:
long = int
from m5.ext.pyfdt import pyfdt
import re
import os
@@ -56,7 +52,7 @@ class FdtPropertyWords(pyfdt.FdtPropertyWords):
words = [words]
# Make sure all values are ints (use automatic base detection if the
# type is str)
words = [long(w, base=0) if type(w) == str else long(w) for w in words]
words = [int(w, base=0) if type(w) == str else int(w) for w in words]
super(FdtPropertyWords, self).__init__(name, words)
class FdtPropertyStrings(pyfdt.FdtPropertyStrings):
@@ -122,7 +118,7 @@ class FdtState(object):
def int_to_cells(self, value, cells):
"""Helper function for: generates a list of 32 bit cells from an int,
used to split up addresses in appropriate 32 bit chunks."""
value = long(value)
value = int(value)
if (value >> (32 * cells)) != 0:
fatal("Value %d doesn't fit in %d cells" % (value, cells))

View File

@@ -25,7 +25,6 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os
from six import string_types
import ply.lex
import ply.yacc
@@ -94,7 +93,7 @@ class Grammar(object):
"'%s' object has no attribute '%s'" % (type(self), attr))
def parse_string(self, data, source='<string>', debug=None, tracking=0):
if not isinstance(data, string_types):
if not isinstance(data, str):
raise AttributeError(
"argument must be a string, was '%s'" % type(f))
@@ -113,7 +112,7 @@ class Grammar(object):
return result
def parse_file(self, f, **kwargs):
if isinstance(f, string_types):
if isinstance(f, str):
source = f
f = open(f, 'r')
elif isinstance(f, file):

View File

@@ -24,9 +24,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
from __future__ import absolute_import
import sys
class Data(object):

View File

@@ -24,8 +24,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
__all__ = [ 'multidict' ]
class multidict(object):

View File

@@ -33,14 +33,9 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import print_function
from __future__ import absolute_import
from six import add_metaclass
from abc import *
@add_metaclass(ABCMeta)
class PyBindExport(object):
class PyBindExport(object, metaclass=ABCMeta):
@abstractmethod
def export(self, code, cname):
pass

View File

@@ -26,9 +26,6 @@
#
# Author: Steve Reinhardt
from __future__ import print_function
from __future__ import absolute_import
import sys
# Intended usage example: