1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2024-10-05 18:31:12 +01:00

Remove Python 2 support

Python 2 is long dead and devlib does not support it anymore, so cleanup
old Python 2-only code.
This commit is contained in:
Douglas Raillard 2023-10-05 12:53:49 +01:00 committed by Marc Bonnici
parent 28b78a93f1
commit 6fe4bce68d
11 changed files with 16 additions and 55 deletions

View File

@ -32,17 +32,11 @@ def transform(mod):
if b'pylint:' in text[0]:
msg = 'pylint directive found on the first line of {}; please move to below copyright header'
raise RuntimeError(msg.format(mod.name))
if sys.version_info[0] == 3:
char = chr(text[0][0])
else:
char = text[0][0]
char = chr(text[0][0])
if text[0].strip() and char != '#':
msg = 'first line of {} is not a comment; is the copyright header missing?'
raise RuntimeError(msg.format(mod.name))
if sys.version_info[0] == 3:
text[0] = '# pylint: disable={}'.format(','.join(errors)).encode('utf-8')
else:
text[0] = '# pylint: disable={}'.format(','.join(errors))
text[0] = '# pylint: disable={}'.format(','.join(errors)).encode('utf-8')
mod.file_bytes = b'\n'.join(text)
# This is what *should* happen, but doesn't work.

View File

@ -25,10 +25,6 @@ from wa.framework.target.manager import TargetManager
from wa.utils.revent import ReventRecorder
if sys.version_info[0] == 3:
raw_input = input # pylint: disable=redefined-builtin
class RecordCommand(Command):
name = 'record'
@ -137,11 +133,11 @@ class RecordCommand(Command):
def record(self, revent_file, name, output_path):
msg = 'Press Enter when you are ready to record {}...'
self.logger.info(msg.format(name))
raw_input('')
input('')
self.revent_recorder.start_record(revent_file)
msg = 'Press Enter when you have finished recording {}...'
self.logger.info(msg.format(name))
raw_input('')
input('')
self.revent_recorder.stop_record()
if not os.path.isdir(output_path):

View File

@ -73,11 +73,8 @@ class ShowCommand(Command):
if which('pandoc'):
p = Popen(['pandoc', '-f', 'rst', '-t', 'man'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
if sys.version_info[0] == 3:
output, _ = p.communicate(rst_output.encode(sys.stdin.encoding))
output = output.decode(sys.stdout.encoding)
else:
output, _ = p.communicate(rst_output)
output, _ = p.communicate(rst_output.encode(sys.stdin.encoding))
output = output.decode(sys.stdout.encoding)
# Make sure to double escape back slashes
output = output.replace('\\', '\\\\\\')

View File

@ -244,10 +244,7 @@ class Http(ResourceGetter):
response.status_code,
response.reason))
return {}
if sys.version_info[0] == 3:
content = response.content.decode('utf-8')
else:
content = response.content
content = response.content.decode('utf-8')
return json.loads(content)
def download_asset(self, asset, owner_name):

View File

@ -325,10 +325,7 @@ def install(instrument, context):
if not callable(attr):
msg = 'Attribute {} not callable in {}.'
raise ValueError(msg.format(attr_name, instrument))
if sys.version_info[0] == 3:
argspec = inspect.getfullargspec(attr)
else:
argspec = inspect.getargspec(attr) # pylint: disable=deprecated-method
argspec = inspect.getfullargspec(attr)
arg_num = len(argspec.args)
# Instrument callbacks will be passed exactly two arguments: self
# (the instrument instance to which the callback is bound) and

View File

@ -57,7 +57,4 @@ def get_commit():
p.wait()
if p.returncode:
return None
if sys.version_info[0] == 3 and isinstance(std, bytes):
return std[:8].decode(sys.stdout.encoding or 'utf-8')
else:
return std[:8]
return std[:8].decode(sys.stdout.encoding or 'utf-8')

View File

@ -41,10 +41,7 @@ from functools import reduce # pylint: disable=redefined-builtin
from operator import mul
from tempfile import gettempdir, NamedTemporaryFile
from time import sleep
if sys.version_info[0] == 3:
from io import StringIO
else:
from io import BytesIO as StringIO
from io import StringIO
# pylint: disable=wrong-import-position,unused-import
from itertools import chain, cycle
from distutils.spawn import find_executable # pylint: disable=no-name-in-module, import-error

View File

@ -31,12 +31,8 @@ import numbers
import shlex
import sys
from bisect import insort
if sys.version_info[0] == 3:
from urllib.parse import quote, unquote # pylint: disable=no-name-in-module, import-error
from past.builtins import basestring # pylint: disable=redefined-builtin
long = int # pylint: disable=redefined-builtin
else:
from urllib import quote, unquote # pylint: disable=no-name-in-module
from urllib.parse import quote, unquote # pylint: disable=no-name-in-module, import-error
from past.builtins import basestring # pylint: disable=redefined-builtin
# pylint: disable=wrong-import-position
from collections import defaultdict
from collections.abc import MutableMapping
@ -710,8 +706,6 @@ class ParameterDict(dict):
prefix = 'f'
elif isinstance(obj, bool):
prefix = 'b'
elif isinstance(obj, long):
prefix = 'i'
elif isinstance(obj, int):
prefix = 'i'
elif obj is None:
@ -792,10 +786,7 @@ class ParameterDict(dict):
return (key, self._decode(value))
def iter_encoded_items(self):
if sys.version_info[0] == 3:
return dict.items(self)
else:
return dict.iteritems(self)
return dict.items(self)
def get_encoded_value(self, name):
return dict.__getitem__(self, name)

View File

@ -223,8 +223,7 @@ class JankbenchRunMonitor(threading.Thread):
ready, _, _ = select.select([proc.stdout, proc.stderr], [], [], 2)
if ready:
line = ready[0].readline()
if sys.version_info[0] == 3:
line = line.decode(sys.stdout.encoding, 'replace')
line = line.decode(sys.stdout.encoding, 'replace')
if self.regex.search(line):
self.run_ended.set()
proc.terminate()

View File

@ -256,10 +256,7 @@ class Meabo(Workload):
outfile = os.path.join(context.output_directory, 'meabo-output.txt')
with open(outfile, 'wb') as wfh:
if sys.version_info[0] == 3:
wfh.write(self.output.encode('utf-8'))
else:
wfh.write(self.output)
wfh.write(self.output.encode('utf-8'))
context.add_artifact('meabo-output', outfile, kind='raw')
cur_phase = 0

View File

@ -89,8 +89,7 @@ class PcMark(ApkUiautoWorkload):
def update_output(self, context):
expected_results = len(self.regex_matches[self.major_version])
zf = zipfile.ZipFile(os.path.join(context.output_directory, self.result_file), 'r').read('Result.xml')
if sys.version_info[0] == 3:
zf = zf.decode(sys.stdout.encoding)
zf = zf.decode(sys.stdout.encoding)
for line in zf.split('\n'):
for regex in self.regex_matches[self.major_version]:
match = regex.search(line)