chore: bump pylint to 2.17 (#41576)

* build: bump pylint to 2.17

Xref: 5062345

* fix pylint consider-using-f-string warnings pt 1: use flynt for automated fixes

* fix pylint consider-using-f-string warnings pt 2: manual fixes

* fix pylint consider-using-with warnings

* fix pylint line-too-long warnings

* fix pylint unspecified-encoding warnings

* fix py lint consider-using-generator warning

* fixup! fix pylint unspecified-encoding warnings

* fix pylint line-too-long warnings
This commit is contained in:
Charles Kerr 2024-03-21 08:48:23 -05:00 committed by GitHub
parent 00da7279cb
commit 61ddb1aa07
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 193 additions and 205 deletions

View file

@ -43,7 +43,7 @@ def get_zip_name(name, version, suffix=''):
arch = get_target_arch()
if arch == 'arm':
arch += 'v7l'
zip_name = '{0}-{1}-{2}-{3}'.format(name, version, get_platform_key(), arch)
zip_name = f'{name}-{version}-{get_platform_key()}-{arch}'
if suffix:
zip_name += '-' + suffix
return zip_name + '.zip'

View file

@ -72,13 +72,10 @@ def am(repo, patch_data, threeway=False, directory=None, exclude=None,
root_args += ['-c', 'user.email=' + committer_email]
root_args += ['-c', 'commit.gpgsign=false']
command = ['git'] + root_args + ['am'] + args
proc = subprocess.Popen(
command,
stdin=subprocess.PIPE)
proc.communicate(patch_data.encode('utf-8'))
if proc.returncode != 0:
raise RuntimeError("Command {} returned {}".format(command,
proc.returncode))
with subprocess.Popen(command, stdin=subprocess.PIPE) as proc:
proc.communicate(patch_data.encode('utf-8'))
if proc.returncode != 0:
raise RuntimeError(f"Command {command} returned {proc.returncode}")
def import_patches(repo, ref=UPSTREAM_HEAD, **kwargs):
@ -229,19 +226,19 @@ def export_patches(repo, out_dir,
dry_run=False, grep=None):
if not os.path.exists(repo):
sys.stderr.write(
"Skipping patches in {} because it does not exist.\n".format(repo)
f"Skipping patches in {repo} because it does not exist.\n"
)
return
if patch_range is None:
patch_range, num_patches = guess_base_commit(repo, ref)
sys.stderr.write("Exporting {} patches in {} since {}\n".format(
num_patches, repo, patch_range[0:7]))
patch_range, n_patches = guess_base_commit(repo, ref)
msg = f"Exporting {n_patches} patches in {repo} since {patch_range[0:7]}\n"
sys.stderr.write(msg)
patch_data = format_patch(repo, patch_range)
patches = split_patches(patch_data)
if grep:
olen = len(patches)
patches = filter_patches(patches, grep)
sys.stderr.write("Exporting {} of {} patches\n".format(len(patches), olen))
sys.stderr.write(f"Exporting {len(patches)} of {olen} patches\n")
try:
os.mkdir(out_dir)
@ -256,7 +253,8 @@ def export_patches(repo, out_dir,
for patch in patches:
filename = get_file_name(patch)
filepath = posixpath.join(out_dir, filename)
existing_patch = str(io.open(filepath, 'rb').read(), 'utf-8')
with io.open(filepath, 'rb') as inp:
existing_patch = str(inp.read(), 'utf-8')
formatted_patch = join_patch(patch)
if formatted_patch != existing_patch:
bad_patches.append(filename)

View file

@ -65,7 +65,7 @@ class Platform:
return Platform.WINDOWS
raise AssertionError(
"unexpected current platform '{}'".format(platform))
f"unexpected current platform '{platform}'")
@staticmethod
def get_all():
@ -101,19 +101,19 @@ class TestsList():
# First check that all names are present in the config.
for binary_name in binaries:
if binary_name not in self.tests:
raise Exception("binary {0} not found in config '{1}'".format(
binary_name, self.config_path))
msg = f"binary {binary_name} not found in config '{self.config_path}'"
raise Exception(msg)
# Respect the "platform" setting.
for binary_name in binaries:
if not self.__platform_supports(binary_name):
raise Exception(
"binary {0} cannot be run on {1}, check the config".format(
binary_name, Platform.get_current()))
host = Platform.get_current()
errmsg = f"binary {binary_name} cannot run on {host}. Check the config"
raise Exception(errmsg)
suite_returncode = sum(
[self.__run(binary, output_dir, verbosity, disabled_tests_policy)
for binary in binaries])
self.__run(binary, output_dir, verbosity, disabled_tests_policy)
for binary in binaries)
return suite_returncode
def run_all(self, output_dir=None, verbosity=Verbosity.CHATTY,
@ -134,7 +134,7 @@ class TestsList():
@staticmethod
def __get_config_data(config_path):
with open(config_path, 'r') as stream:
with open(config_path, 'r', encoding='utf-8') as stream:
return yaml.load(stream)
@staticmethod
@ -146,7 +146,7 @@ class TestsList():
if isinstance(value, str):
return {value: None}
raise AssertionError("unexpected shorthand type: {}".format(type(value)))
raise AssertionError(f"unexpected shorthand type: {type(value)}")
@staticmethod
def __make_a_list(value):
@ -166,7 +166,7 @@ class TestsList():
return [list_item for key in value for list_item in value[key]]
raise AssertionError(
"unexpected type for list merging: {}".format(type(value)))
f"unexpected type for list merging: {type(value)}")
def __platform_supports(self, binary_name):
return Platform.get_current() in self.tests[binary_name]['platforms']
@ -194,8 +194,7 @@ class TestsList():
for platform in platforms:
assert Platform.is_valid(platform), \
"platform '{0}' is not supported, check {1} config" \
.format(platform, binary_name)
f"Unsupported platform {platform}, check {binary_name} config"
test_data['platforms'] = platforms
@ -231,7 +230,7 @@ class TestsList():
if output_dir is None:
return None
return os.path.join(output_dir, "results_{}.xml".format(binary_name))
return os.path.join(output_dir, f"results_{binary_name}.xml")
class TestBinary():
@ -248,50 +247,40 @@ class TestBinary():
gtest_output = TestBinary.__get_gtest_output(output_file_path)
args = [self.binary_path, gtest_filter, gtest_output]
stdout, stderr = TestBinary.__get_stdout_and_stderr(verbosity)
returncode = 0
try:
returncode = subprocess.call(args, stdout=stdout, stderr=stderr)
except Exception as exception:
if Verbosity.ge(verbosity, Verbosity.ERRORS):
print("An error occurred while running '{}':".format(self.binary_path),
'\n', exception, file=sys.stderr)
returncode = 1
with open(os.devnull, "w", encoding='utf-8') as devnull:
stdout = stderr = None
if Verbosity.le(verbosity, Verbosity.ERRORS):
stdout = devnull
if verbosity == Verbosity.SILENT:
stderr = devnull
try:
returncode = subprocess.call(args, stdout=stdout, stderr=stderr)
except Exception as exception:
if Verbosity.ge(verbosity, Verbosity.ERRORS):
print(f"An error occurred while running '{self.binary_path}':",
'\n', exception, file=sys.stderr)
returncode = 1
return returncode
@staticmethod
def __get_gtest_filter(included_tests, excluded_tests):
included_tests_string = TestBinary.__list_tests(included_tests)
excluded_tests_string = TestBinary.__list_tests(excluded_tests)
gtest_filter = "--gtest_filter={}-{}".format(included_tests_string,
excluded_tests_string)
return gtest_filter
included_str = TestBinary.__list_tests(included_tests)
excluded_str = TestBinary.__list_tests(excluded_tests)
return f"--gtest_filter={included_str}-{excluded_str}"
@staticmethod
def __get_gtest_output(output_file_path):
gtest_output = ""
if output_file_path is not None:
gtest_output = "--gtest_output={0}:{1}".format(TestBinary.output_format,
output_file_path)
return gtest_output
if output_file_path is None:
return ""
return f"--gtest_output={TestBinary.output_format}:{output_file_path}"
@staticmethod
def __list_tests(tests):
if tests is None:
return ''
return ':'.join(tests)
@staticmethod
def __get_stdout_and_stderr(verbosity):
stdout = stderr = None
if Verbosity.le(verbosity, Verbosity.ERRORS):
devnull = open(os.devnull, 'w')
stdout = devnull
if verbosity == Verbosity.SILENT:
stderr = devnull
return (stdout, stderr)

View file

@ -21,8 +21,8 @@ def read_patch(patch_dir, patch_filename):
for l in f.readlines():
line_has_correct_start = l.startswith('diff -') or l.startswith('---')
if not added_patch_location and line_has_correct_start:
ret.append('{}{}\n'.format(PATCH_DIR_PREFIX, patch_dir))
ret.append('{}{}\n'.format(PATCH_FILENAME_PREFIX, patch_filename))
ret.append(f'{PATCH_DIR_PREFIX}{patch_dir}\n')
ret.append(f'{PATCH_FILENAME_PREFIX}{patch_filename}\n')
added_patch_location = True
ret.append(l)
return ''.join(ret)
@ -31,8 +31,8 @@ def read_patch(patch_dir, patch_filename):
def patch_from_dir(patch_dir):
"""Read a directory of patches into a format suitable for passing to
'git am'"""
with open(os.path.join(patch_dir, ".patches")) as f:
patch_list = [l.rstrip('\n') for l in f.readlines()]
with open(os.path.join(patch_dir, ".patches"), encoding='utf-8') as file_in:
patch_list = [line.rstrip('\n') for line in file_in.readlines()]
return ''.join([
read_patch(patch_dir, patch_filename)

View file

@ -35,9 +35,8 @@ def scoped_cwd(path):
def download(text, url, path):
safe_mkdir(os.path.dirname(path))
with open(path, 'wb') as local_file:
print("Downloading %s to %s" % (url, path))
web_file = urlopen(url)
with open(path, 'wb') as local_file, urlopen(url) as web_file:
print(f"Downloading {url} to {path}")
info = web_file.info()
if hasattr(info, 'getheader'):
file_size = int(info.getheaders("Content-Length")[0])
@ -58,11 +57,11 @@ def download(text, url, path):
if not ci:
percent = downloaded_size * 100. / file_size
status = "\r%s %10d [%3.1f%%]" % (text, downloaded_size, percent)
status = f"\r{text} {downloaded_size:10d} [{percent:3.1f}%]"
print(status, end=' ')
if ci:
print("%s done." % (text))
print(f"{text} done.")
else:
print()
return path
@ -74,15 +73,16 @@ def make_zip(zip_file_path, files, dirs):
allfiles = files + dirs
execute(['zip', '-r', '-y', zip_file_path] + allfiles)
else:
zip_file = zipfile.ZipFile(zip_file_path, "w", zipfile.ZIP_DEFLATED,
allowZip64=True)
for filename in files:
zip_file.write(filename, filename)
for dirname in dirs:
for root, _, filenames in os.walk(dirname):
for f in filenames:
zip_file.write(os.path.join(root, f))
zip_file.close()
with zipfile.ZipFile(zip_file_path, "w",
zipfile.ZIP_DEFLATED,
allowZip64=True) as zip_file:
for filename in files:
zip_file.write(filename, filename)
for dirname in dirs:
for root, _, filenames in os.walk(dirname):
for f in filenames:
zip_file.write(os.path.join(root, f))
zip_file.close()
def rm_rf(path):
@ -128,8 +128,8 @@ def get_electron_branding():
SOURCE_ROOT = os.path.abspath(os.path.join(__file__, '..', '..', '..'))
branding_file_path = os.path.join(
SOURCE_ROOT, 'shell', 'app', 'BRANDING.json')
with open(branding_file_path) as f:
return json.load(f)
with open(branding_file_path, encoding='utf-8') as file_in:
return json.load(file_in)
cached_electron_version = None
@ -173,14 +173,14 @@ def get_electron_exec():
out_dir = get_out_dir()
if sys.platform == 'darwin':
return '{0}/Electron.app/Contents/MacOS/Electron'.format(out_dir)
return f'{out_dir}/Electron.app/Contents/MacOS/Electron'
if sys.platform == 'win32':
return '{0}/electron.exe'.format(out_dir)
return f'{out_dir}/electron.exe'
if sys.platform == 'linux':
return '{0}/electron'.format(out_dir)
return f'{out_dir}/electron'
raise Exception(
"get_electron_exec: unexpected platform '{0}'".format(sys.platform))
f"get_electron_exec: unexpected platform '{sys.platform}'")
def get_buildtools_executable(name):
buildtools = os.path.realpath(os.path.join(ELECTRON_DIR, '..', 'buildtools'))