chore: bump pylint to 2.17 (#41576)

* build: bump pylint to 2.17

Xref: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/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

@ -13,7 +13,7 @@ THREEWAY = "ELECTRON_USE_THREE_WAY_MERGE_FOR_PATCHES" in os.environ
def apply_patches(target): def apply_patches(target):
repo = target.get('repo') repo = target.get('repo')
if not os.path.exists(repo): if not os.path.exists(repo):
warnings.warn('repo not found: %s' % repo) warnings.warn(f'repo not found: {repo}')
return return
patch_dir = target.get('patch_dir') patch_dir = target.get('patch_dir')
git.import_patches( git.import_patches(

View file

@ -13,8 +13,8 @@ def stop():
DBusTestCase.stop_dbus(DBusTestCase.session_bus_pid) DBusTestCase.stop_dbus(DBusTestCase.session_bus_pid)
def start(): def start():
log = sys.stdout if is_verbose_mode() else open(os.devnull, 'w') with sys.stdout if is_verbose_mode() \
else open(os.devnull, 'w', encoding='utf-8') as log:
DBusTestCase.start_system_bus() DBusTestCase.start_system_bus()
DBusTestCase.spawn_server_template('logind', None, log) DBusTestCase.spawn_server_template('logind', None, log)

View file

@ -11,7 +11,7 @@ from lib import git
def export_patches(target, dry_run): def export_patches(target, dry_run):
repo = target.get('repo') repo = target.get('repo')
if not os.path.exists(repo): if not os.path.exists(repo):
warnings.warn('repo not found: %s' % repo) warnings.warn(f'repo not found: {repo}')
return return
git.export_patches( git.export_patches(
dry_run=dry_run, dry_run=dry_run,

View file

@ -29,15 +29,15 @@ def run_node_configure(target_cpu):
def read_node_config_gypi(): def read_node_config_gypi():
config_gypi = os.path.join(NODE_DIR, 'config.gypi') config_gypi = os.path.join(NODE_DIR, 'config.gypi')
with open(config_gypi, 'r') as f: with open(config_gypi, 'r', encoding='utf-8') as file_in:
content = f.read() content = file_in.read()
return ast.literal_eval(content) return ast.literal_eval(content)
def read_electron_args(): def read_electron_args():
all_gn = os.path.join(ELECTRON_DIR, 'build', 'args', 'all.gn') all_gn = os.path.join(ELECTRON_DIR, 'build', 'args', 'all.gn')
args = {} args = {}
with open(all_gn, 'r') as f: with open(all_gn, 'r', encoding='utf-8') as file_in:
for line in f: for line in file_in:
if line.startswith('#'): if line.startswith('#'):
continue continue
m = re.match('([\w_]+) = (.+)', line) m = re.match('([\w_]+) = (.+)', line)
@ -62,8 +62,8 @@ def main(target_file, target_cpu):
# Used by certain versions of node-gyp. # Used by certain versions of node-gyp.
v['build_v8_with_gn'] = 'false' v['build_v8_with_gn'] = 'false'
with open(target_file, 'w+') as f: with open(target_file, 'w+', encoding='utf-8') as file_out:
f.write(pprint.pformat(config, indent=2)) file_out.write(pprint.pformat(config, indent=2))
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(main(sys.argv[1], sys.argv[2])) sys.exit(main(sys.argv[1], sys.argv[2]))

View file

@ -4,7 +4,7 @@ import zipfile
import sys import sys
def main(zip_path, manifest_out): def main(zip_path, manifest_out):
with open(manifest_out, 'w') as manifest, \ with open(manifest_out, 'w', encoding='utf-8') as manifest, \
zipfile.ZipFile(zip_path, 'r', allowZip64=True) as z: zipfile.ZipFile(zip_path, 'r', allowZip64=True) as z:
for name in sorted(z.namelist()): for name in sorted(z.namelist()):
manifest.write(name + '\n') manifest.write(name + '\n')

View file

@ -8,7 +8,8 @@ NMV = None
if len(sys.argv) > 3: if len(sys.argv) > 3:
NMV = sys.argv[3] NMV = sys.argv[3]
with open(node_version_file, 'r') as in_file, open(out_file, 'w') as out_file: with open(node_version_file, 'r', encoding='utf-8') as in_file, \
open(out_file, 'w', encoding='utf-8') as out_file:
changed = False changed = False
contents = in_file.read() contents = in_file.read()
new_contents = re.sub( new_contents = re.sub(

View file

@ -43,7 +43,7 @@ def get_zip_name(name, version, suffix=''):
arch = get_target_arch() arch = get_target_arch()
if arch == 'arm': if arch == 'arm':
arch += 'v7l' 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: if suffix:
zip_name += '-' + suffix zip_name += '-' + suffix
return zip_name + '.zip' 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', 'user.email=' + committer_email]
root_args += ['-c', 'commit.gpgsign=false'] root_args += ['-c', 'commit.gpgsign=false']
command = ['git'] + root_args + ['am'] + args command = ['git'] + root_args + ['am'] + args
proc = subprocess.Popen( with subprocess.Popen(command, stdin=subprocess.PIPE) as proc:
command,
stdin=subprocess.PIPE)
proc.communicate(patch_data.encode('utf-8')) proc.communicate(patch_data.encode('utf-8'))
if proc.returncode != 0: if proc.returncode != 0:
raise RuntimeError("Command {} returned {}".format(command, raise RuntimeError(f"Command {command} returned {proc.returncode}")
proc.returncode))
def import_patches(repo, ref=UPSTREAM_HEAD, **kwargs): def import_patches(repo, ref=UPSTREAM_HEAD, **kwargs):
@ -229,19 +226,19 @@ def export_patches(repo, out_dir,
dry_run=False, grep=None): dry_run=False, grep=None):
if not os.path.exists(repo): if not os.path.exists(repo):
sys.stderr.write( 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 return
if patch_range is None: if patch_range is None:
patch_range, num_patches = guess_base_commit(repo, ref) patch_range, n_patches = guess_base_commit(repo, ref)
sys.stderr.write("Exporting {} patches in {} since {}\n".format( msg = f"Exporting {n_patches} patches in {repo} since {patch_range[0:7]}\n"
num_patches, repo, patch_range[0:7])) sys.stderr.write(msg)
patch_data = format_patch(repo, patch_range) patch_data = format_patch(repo, patch_range)
patches = split_patches(patch_data) patches = split_patches(patch_data)
if grep: if grep:
olen = len(patches) olen = len(patches)
patches = filter_patches(patches, grep) 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: try:
os.mkdir(out_dir) os.mkdir(out_dir)
@ -256,7 +253,8 @@ def export_patches(repo, out_dir,
for patch in patches: for patch in patches:
filename = get_file_name(patch) filename = get_file_name(patch)
filepath = posixpath.join(out_dir, filename) 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) formatted_patch = join_patch(patch)
if formatted_patch != existing_patch: if formatted_patch != existing_patch:
bad_patches.append(filename) bad_patches.append(filename)

View file

@ -65,7 +65,7 @@ class Platform:
return Platform.WINDOWS return Platform.WINDOWS
raise AssertionError( raise AssertionError(
"unexpected current platform '{}'".format(platform)) f"unexpected current platform '{platform}'")
@staticmethod @staticmethod
def get_all(): def get_all():
@ -101,19 +101,19 @@ class TestsList():
# First check that all names are present in the config. # First check that all names are present in the config.
for binary_name in binaries: for binary_name in binaries:
if binary_name not in self.tests: if binary_name not in self.tests:
raise Exception("binary {0} not found in config '{1}'".format( msg = f"binary {binary_name} not found in config '{self.config_path}'"
binary_name, self.config_path)) raise Exception(msg)
# Respect the "platform" setting. # Respect the "platform" setting.
for binary_name in binaries: for binary_name in binaries:
if not self.__platform_supports(binary_name): if not self.__platform_supports(binary_name):
raise Exception( host = Platform.get_current()
"binary {0} cannot be run on {1}, check the config".format( errmsg = f"binary {binary_name} cannot run on {host}. Check the config"
binary_name, Platform.get_current())) raise Exception(errmsg)
suite_returncode = sum( suite_returncode = sum(
[self.__run(binary, output_dir, verbosity, disabled_tests_policy) self.__run(binary, output_dir, verbosity, disabled_tests_policy)
for binary in binaries]) for binary in binaries)
return suite_returncode return suite_returncode
def run_all(self, output_dir=None, verbosity=Verbosity.CHATTY, def run_all(self, output_dir=None, verbosity=Verbosity.CHATTY,
@ -134,7 +134,7 @@ class TestsList():
@staticmethod @staticmethod
def __get_config_data(config_path): 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) return yaml.load(stream)
@staticmethod @staticmethod
@ -146,7 +146,7 @@ class TestsList():
if isinstance(value, str): if isinstance(value, str):
return {value: None} return {value: None}
raise AssertionError("unexpected shorthand type: {}".format(type(value))) raise AssertionError(f"unexpected shorthand type: {type(value)}")
@staticmethod @staticmethod
def __make_a_list(value): def __make_a_list(value):
@ -166,7 +166,7 @@ class TestsList():
return [list_item for key in value for list_item in value[key]] return [list_item for key in value for list_item in value[key]]
raise AssertionError( raise AssertionError(
"unexpected type for list merging: {}".format(type(value))) f"unexpected type for list merging: {type(value)}")
def __platform_supports(self, binary_name): def __platform_supports(self, binary_name):
return Platform.get_current() in self.tests[binary_name]['platforms'] return Platform.get_current() in self.tests[binary_name]['platforms']
@ -194,8 +194,7 @@ class TestsList():
for platform in platforms: for platform in platforms:
assert Platform.is_valid(platform), \ assert Platform.is_valid(platform), \
"platform '{0}' is not supported, check {1} config" \ f"Unsupported platform {platform}, check {binary_name} config"
.format(platform, binary_name)
test_data['platforms'] = platforms test_data['platforms'] = platforms
@ -231,7 +230,7 @@ class TestsList():
if output_dir is None: if output_dir is None:
return 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(): class TestBinary():
@ -248,14 +247,21 @@ class TestBinary():
gtest_output = TestBinary.__get_gtest_output(output_file_path) gtest_output = TestBinary.__get_gtest_output(output_file_path)
args = [self.binary_path, gtest_filter, gtest_output] args = [self.binary_path, gtest_filter, gtest_output]
stdout, stderr = TestBinary.__get_stdout_and_stderr(verbosity)
returncode = 0 returncode = 0
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: try:
returncode = subprocess.call(args, stdout=stdout, stderr=stderr) returncode = subprocess.call(args, stdout=stdout, stderr=stderr)
except Exception as exception: except Exception as exception:
if Verbosity.ge(verbosity, Verbosity.ERRORS): if Verbosity.ge(verbosity, Verbosity.ERRORS):
print("An error occurred while running '{}':".format(self.binary_path), print(f"An error occurred while running '{self.binary_path}':",
'\n', exception, file=sys.stderr) '\n', exception, file=sys.stderr)
returncode = 1 returncode = 1
@ -263,35 +269,18 @@ class TestBinary():
@staticmethod @staticmethod
def __get_gtest_filter(included_tests, excluded_tests): def __get_gtest_filter(included_tests, excluded_tests):
included_tests_string = TestBinary.__list_tests(included_tests) included_str = TestBinary.__list_tests(included_tests)
excluded_tests_string = TestBinary.__list_tests(excluded_tests) excluded_str = TestBinary.__list_tests(excluded_tests)
return f"--gtest_filter={included_str}-{excluded_str}"
gtest_filter = "--gtest_filter={}-{}".format(included_tests_string,
excluded_tests_string)
return gtest_filter
@staticmethod @staticmethod
def __get_gtest_output(output_file_path): def __get_gtest_output(output_file_path):
gtest_output = "" if output_file_path is None:
if output_file_path is not None: return ""
gtest_output = "--gtest_output={0}:{1}".format(TestBinary.output_format, return f"--gtest_output={TestBinary.output_format}:{output_file_path}"
output_file_path)
return gtest_output
@staticmethod @staticmethod
def __list_tests(tests): def __list_tests(tests):
if tests is None: if tests is None:
return '' return ''
return ':'.join(tests) 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(): for l in f.readlines():
line_has_correct_start = l.startswith('diff -') or l.startswith('---') line_has_correct_start = l.startswith('diff -') or l.startswith('---')
if not added_patch_location and line_has_correct_start: if not added_patch_location and line_has_correct_start:
ret.append('{}{}\n'.format(PATCH_DIR_PREFIX, patch_dir)) ret.append(f'{PATCH_DIR_PREFIX}{patch_dir}\n')
ret.append('{}{}\n'.format(PATCH_FILENAME_PREFIX, patch_filename)) ret.append(f'{PATCH_FILENAME_PREFIX}{patch_filename}\n')
added_patch_location = True added_patch_location = True
ret.append(l) ret.append(l)
return ''.join(ret) return ''.join(ret)
@ -31,8 +31,8 @@ def read_patch(patch_dir, patch_filename):
def patch_from_dir(patch_dir): def patch_from_dir(patch_dir):
"""Read a directory of patches into a format suitable for passing to """Read a directory of patches into a format suitable for passing to
'git am'""" 'git am'"""
with open(os.path.join(patch_dir, ".patches")) as f: with open(os.path.join(patch_dir, ".patches"), encoding='utf-8') as file_in:
patch_list = [l.rstrip('\n') for l in f.readlines()] patch_list = [line.rstrip('\n') for line in file_in.readlines()]
return ''.join([ return ''.join([
read_patch(patch_dir, patch_filename) read_patch(patch_dir, patch_filename)

View file

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

View file

@ -120,10 +120,10 @@ const LINTERS = [{
roots: ['script'], roots: ['script'],
test: filename => filename.endsWith('.py'), test: filename => filename.endsWith('.py'),
run: (opts, filenames) => { run: (opts, filenames) => {
const rcfile = path.join(DEPOT_TOOLS, 'pylintrc'); const rcfile = path.join(DEPOT_TOOLS, 'pylintrc-2.17');
const args = ['--rcfile=' + rcfile, ...filenames]; const args = ['--rcfile=' + rcfile, ...filenames];
const env = { PYTHONPATH: path.join(ELECTRON_ROOT, 'script'), ...process.env }; const env = { PYTHONPATH: path.join(ELECTRON_ROOT, 'script'), ...process.env };
spawnAndCheckExitCode('pylint-2.7', args, { env }); spawnAndCheckExitCode('pylint-2.17', args, { env });
} }
}, { }, {
key: 'javascript', key: 'javascript',

View file

@ -65,19 +65,19 @@ def parse_args():
# 'config' must exist and be a file. # 'config' must exist and be a file.
args.config = os.path.abspath(args.config) args.config = os.path.abspath(args.config)
if not os.path.isfile(args.config): if not os.path.isfile(args.config):
parser.error("file '{}' doesn't exist".format(args.config)) parser.error(f"file '{args.config}' doesn't exist")
# 'tests_dir' must exist and be a directory. # 'tests_dir' must exist and be a directory.
if args.tests_dir is not None: if args.tests_dir is not None:
args.tests_dir = os.path.abspath(args.tests_dir) args.tests_dir = os.path.abspath(args.tests_dir)
if not os.path.isdir(args.tests_dir): if not os.path.isdir(args.tests_dir):
parser.error("directory '{}' doesn't exist".format(args.tests_dir)) parser.error(f"directory '{args.tests_dir}' doesn't exist")
# 'output_dir' must exist and be a directory. # 'output_dir' must exist and be a directory.
if args.output_dir is not None: if args.output_dir is not None:
args.output_dir = os.path.abspath(args.output_dir) args.output_dir = os.path.abspath(args.output_dir)
if not os.path.isdir(args.output_dir): if not os.path.isdir(args.output_dir):
parser.error("directory '{}' doesn't exist".format(args.output_dir)) parser.error(f"directory '{args.output_dir}' doesn't exist")
return args return args
@ -99,7 +99,7 @@ def main():
return tests_list.run_all(args.output_dir, args.verbosity, return tests_list.run_all(args.output_dir, args.verbosity,
args.disabled_tests_policy) args.disabled_tests_policy)
raise AssertionError("unexpected command '{}'".format(args.command)) raise AssertionError(f"unexpected command '{args.command}'")
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -77,8 +77,8 @@ def set_mtimes(patches_config, mtime):
mtime_cache[file_path] = mtime mtime_cache[file_path] = mtime
for file_path in mtime_cache: for file_path, file_mtime in mtime_cache.items():
os.utime(file_path, (mtime_cache[file_path], mtime_cache[file_path])) os.utime(file_path, (file_mtime, file_mtime))
def main(): def main():
@ -131,17 +131,17 @@ def main():
if args.operation == "generate": if args.operation == "generate":
try: try:
# Cache file may exist from a previously aborted sync. Reuse it. # Cache file may exist from a previously aborted sync. Reuse it.
with open(args.cache_file, mode="r") as f: with open(args.cache_file, mode='r', encoding='utf-8') as fin:
json.load(f) # Make sure it's not an empty file json.load(fin) # Make sure it's not an empty file
print("Using existing mtime cache for patches") print("Using existing mtime cache for patches")
return 0 return 0
except Exception: except Exception:
pass pass
try: try:
with open(args.cache_file, mode="w") as f: with open(args.cache_file, mode="w", encoding='utf-8') as fin:
mtime_cache = generate_cache(json.load(args.patches_config)) mtime_cache = generate_cache(json.load(args.patches_config))
json.dump(mtime_cache, f, indent=2) json.dump(mtime_cache, fin, indent=2)
except Exception: except Exception:
print( print(
"ERROR: failed to generate mtime cache for patches", "ERROR: failed to generate mtime cache for patches",
@ -155,8 +155,8 @@ def main():
return 0 # Cache file may not exist, fail more gracefully return 0 # Cache file may not exist, fail more gracefully
try: try:
with open(args.cache_file, mode="r") as f: with open(args.cache_file, mode='r', encoding='utf-8') as file_in:
apply_mtimes(json.load(f)) apply_mtimes(json.load(file_in))
if not args.preserve_cache: if not args.preserve_cache:
os.remove(args.cache_file) os.remove(args.cache_file)

View file

@ -32,9 +32,8 @@ def get_content(retry_count = 5):
headers={"Authorization" : authToken} headers={"Authorization" : authToken}
) )
proposed_content = urlopen( with urlopen(request) as resp:
request proposed_content = resp.read()
).read()
if is_json(proposed_content): if is_json(proposed_content):
return proposed_content return proposed_content

View file

@ -29,7 +29,7 @@ def main():
] ]
if args.target_dir is None: if args.target_dir is None:
store_artifact(directory, 'headers/dist/{0}'.format(args.version), store_artifact(directory, f'headers/dist/{args.version}',
checksums) checksums)
else: else:
copy_files(checksums, args.target_dir) copy_files(checksums, args.target_dir)
@ -51,10 +51,10 @@ def parse_args():
def get_files_list(version): def get_files_list(version):
return [ return [
{ "filename": 'node-{0}.tar.gz'.format(version), "required": True }, { "filename": f'node-{version}.tar.gz', "required": True },
{ "filename": 'node-{0}-headers.tar.gz'.format(version), "required": True }, { "filename": f'node-{version}-headers.tar.gz', "required": True },
{ "filename": 'iojs-{0}.tar.gz'.format(version), "required": True }, { "filename": f'iojs-{version}.tar.gz', "required": True },
{ "filename": 'iojs-{0}-headers.tar.gz'.format(version), "required": True }, { "filename": f'iojs-{version}-headers.tar.gz', "required": True },
{ "filename": 'node.lib', "required": False }, { "filename": 'node.lib', "required": False },
{ "filename": 'x64/node.lib', "required": False }, { "filename": 'x64/node.lib', "required": False },
{ "filename": 'win-x86/iojs.lib', "required": False }, { "filename": 'win-x86/iojs.lib', "required": False },
@ -91,8 +91,8 @@ def create_checksum(algorithm, directory, filename, files):
lines.append(h.hexdigest() + ' ' + os.path.relpath(path, directory)) lines.append(h.hexdigest() + ' ' + os.path.relpath(path, directory))
checksum_file = os.path.join(directory, filename) checksum_file = os.path.join(directory, filename)
with open(checksum_file, 'w') as f: with open(checksum_file, 'w', encoding='utf-8') as fout:
f.write('\n'.join(lines) + '\n') fout.write('\n'.join(lines) + '\n')
return checksum_file return checksum_file
def copy_files(source_files, output_dir): def copy_files(source_files, output_dir):

View file

@ -45,9 +45,9 @@ def upload_node(version):
versioned_header_tar = header_tar.format(version) versioned_header_tar = header_tar.format(version)
shutil.copy2(generated_tar, os.path.join(GEN_DIR, versioned_header_tar)) shutil.copy2(generated_tar, os.path.join(GEN_DIR, versioned_header_tar))
store_artifact(GEN_DIR, 'headers/dist/{0}'.format(version), store_artifact(GEN_DIR, f'headers/dist/{version}',
glob.glob('node-*.tar.gz')) glob.glob('node-*.tar.gz'))
store_artifact(GEN_DIR, 'headers/dist/{0}'.format(version), store_artifact(GEN_DIR, f'headers/dist/{version}',
glob.glob('iojs-*.tar.gz')) glob.glob('iojs-*.tar.gz'))
if PLATFORM == 'win32': if PLATFORM == 'win32':
@ -73,13 +73,13 @@ def upload_node(version):
shutil.copy2(electron_lib, v4_node_lib) shutil.copy2(electron_lib, v4_node_lib)
# Upload the node.lib. # Upload the node.lib.
store_artifact(DIST_DIR, 'headers/dist/{0}'.format(version), [node_lib]) store_artifact(DIST_DIR, f'headers/dist/{version}', [node_lib])
# Upload the iojs.lib. # Upload the iojs.lib.
store_artifact(DIST_DIR, 'headers/dist/{0}'.format(version), [iojs_lib]) store_artifact(DIST_DIR, f'headers/dist/{version}', [iojs_lib])
# Upload the v4 node.lib. # Upload the v4 node.lib.
store_artifact(DIST_DIR, 'headers/dist/{0}'.format(version), store_artifact(DIST_DIR, f'headers/dist/{version}',
[v4_node_lib]) [v4_node_lib])

View file

@ -26,7 +26,7 @@ PRODUCT_NAME = get_electron_branding()['product_name']
SYMBOLS_DIR = os.path.join(RELEASE_DIR, 'breakpad_symbols') SYMBOLS_DIR = os.path.join(RELEASE_DIR, 'breakpad_symbols')
PDB_LIST = [ PDB_LIST = [
os.path.join(RELEASE_DIR, '{0}.exe.pdb'.format(PROJECT_NAME)) os.path.join(RELEASE_DIR, f'{PROJECT_NAME}.exe.pdb')
] ]
PDB_LIST += glob.glob(os.path.join(RELEASE_DIR, '*.dll.pdb')) PDB_LIST += glob.glob(os.path.join(RELEASE_DIR, '*.dll.pdb'))

View file

@ -53,9 +53,8 @@ def main():
build_version = get_electron_build_version() build_version = get_electron_build_version()
if not ELECTRON_VERSION.startswith(build_version): if not ELECTRON_VERSION.startswith(build_version):
error = 'Tag name ({0}) should match build version ({1})\n'.format( errmsg = f"Tag ({ELECTRON_VERSION}) should match build ({build_version})\n"
ELECTRON_VERSION, build_version) sys.stderr.write(errmsg)
sys.stderr.write(error)
sys.stderr.flush() sys.stderr.flush()
return 1 return 1
@ -344,8 +343,7 @@ def upload_electron(release, file_path, args):
# if upload_to_storage is set, skip github upload. # if upload_to_storage is set, skip github upload.
# todo (vertedinde): migrate this variable to upload_to_storage # todo (vertedinde): migrate this variable to upload_to_storage
if args.upload_to_storage: if args.upload_to_storage:
key_prefix = 'release-builds/{0}_{1}'.format(args.version, key_prefix = f'release-builds/{args.version}_{args.upload_timestamp}'
args.upload_timestamp)
store_artifact(os.path.dirname(file_path), key_prefix, [file_path]) store_artifact(os.path.dirname(file_path), key_prefix, [file_path])
upload_sha256_checksum(args.version, file_path, key_prefix) upload_sha256_checksum(args.version, file_path, key_prefix)
return return
@ -358,13 +356,13 @@ def upload_electron(release, file_path, args):
def upload_io_to_github(release, filename, filepath, version): def upload_io_to_github(release, filename, filepath, version):
print('Uploading %s to GitHub' % \ print(f'Uploading {filename} to GitHub')
(filename))
script_path = os.path.join( script_path = os.path.join(
ELECTRON_DIR, 'script', 'release', 'uploaders', 'upload-to-github.ts') ELECTRON_DIR, 'script', 'release', 'uploaders', 'upload-to-github.ts')
upload_process = subprocess.Popen([TS_NODE, script_path, filepath, filename, with subprocess.Popen([TS_NODE, script_path, filepath,
str(release['id']), version], stdout=subprocess.PIPE, filename, str(release['id']), version],
stderr=subprocess.STDOUT) stdout=subprocess.PIPE,
stderr=subprocess.STDOUT) as upload_process:
if is_verbose_mode(): if is_verbose_mode():
for c in iter(lambda: upload_process.stdout.read(1), b""): for c in iter(lambda: upload_process.stdout.read(1), b""):
sys.stdout.buffer.write(c) sys.stdout.buffer.write(c)
@ -372,16 +370,16 @@ def upload_io_to_github(release, filename, filepath, version):
def upload_sha256_checksum(version, file_path, key_prefix=None): def upload_sha256_checksum(version, file_path, key_prefix=None):
checksum_path = '{}.sha256sum'.format(file_path) checksum_path = f'{file_path}.sha256sum'
if key_prefix is None: if key_prefix is None:
key_prefix = 'checksums-scratchpad/{0}'.format(version) key_prefix = f'checksums-scratchpad/{version}'
sha256 = hashlib.sha256() sha256 = hashlib.sha256()
with open(file_path, 'rb') as f: with open(file_path, 'rb') as f:
sha256.update(f.read()) sha256.update(f.read())
filename = os.path.basename(file_path) filename = os.path.basename(file_path)
with open(checksum_path, 'w') as checksum: with open(checksum_path, 'w', encoding='utf-8') as checksum:
checksum.write('{} *{}'.format(sha256.hexdigest(), filename)) checksum.write(f'{sha256.hexdigest()} *{filename}')
store_artifact(os.path.dirname(checksum_path), key_prefix, [checksum_path]) store_artifact(os.path.dirname(checksum_path), key_prefix, [checksum_path])
@ -394,7 +392,7 @@ def get_release(version):
release_env['NODE_NO_WARNINGS'] = '1' release_env['NODE_NO_WARNINGS'] = '1'
release_info = execute(['node', script_path, version], release_env) release_info = execute(['node', script_path, version], release_env)
if is_verbose_mode(): if is_verbose_mode():
print('Release info for version: {}:\n'.format(version)) print(f'Release info for version: {version}:\n')
print(release_info) print(release_info)
release = json.loads(release_info) release = json.loads(release_info)
return release return release

View file

@ -85,8 +85,8 @@ def make_diff(diff_file, original, reformatted):
difflib.unified_diff( difflib.unified_diff(
original, original,
reformatted, reformatted,
fromfile='a/{}'.format(diff_file), fromfile=f'a/{diff_file}',
tofile='b/{}'.format(diff_file), tofile=f'b/{diff_file}',
n=3)) n=3))
@ -111,8 +111,7 @@ def run_clang_format_diff_wrapper(args, file_name):
raise raise
except Exception as e: except Exception as e:
# pylint: disable=W0707 # pylint: disable=W0707
raise UnexpectedError('{}: {}: {}'.format( raise UnexpectedError(f'{file_name}: {e.__class__.__name__}: {e}', e)
file_name, e.__class__.__name__, e), e)
def run_clang_format_diff(args, file_name): def run_clang_format_diff(args, file_name):
@ -131,25 +130,22 @@ def run_clang_format_diff(args, file_name):
print(" ".join(invocation)) print(" ".join(invocation))
return [], [] return [], []
try: try:
proc = subprocess.Popen( with subprocess.Popen(' '.join(invocation),
' '.join(invocation),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, universal_newlines=True,
shell=True) shell=True) as proc:
except OSError as exc:
# pylint: disable=W0707
raise DiffError(
"Command '{}' failed to start: {}".format(
subprocess.list2cmdline(invocation), exc
)
)
outs = list(proc.stdout.readlines()) outs = list(proc.stdout.readlines())
errs = list(proc.stderr.readlines()) errs = list(proc.stderr.readlines())
proc.wait() proc.wait()
if proc.returncode: if proc.returncode:
raise DiffError("clang-format exited with status {}: '{}'".format( code = proc.returncode
proc.returncode, file_name), errs) msg = f"clang-format exited with code {code}: '{file_name}'"
raise DiffError(msg, errs)
except OSError as exc:
# pylint: disable=raise-missing-from
cmd = subprocess.list2cmdline(invocation)
raise DiffError(f"Command '{cmd}' failed to start: {exc}")
if args.fix: if args.fix:
return None, errs return None, errs
if sys.platform == 'win32': if sys.platform == 'win32':
@ -200,7 +196,7 @@ def print_trouble(prog, message, use_colors):
error_text = 'error:' error_text = 'error:'
if use_colors: if use_colors:
error_text = bold_red(error_text) error_text = bold_red(error_text)
print("{}: {} {}".format(prog, error_text, message), file=sys.stderr) print(f"{prog}: {error_text} {message}", file=sys.stderr)
def main(): def main():
@ -212,8 +208,8 @@ def main():
default=get_buildtools_executable('clang-format')) default=get_buildtools_executable('clang-format'))
parser.add_argument( parser.add_argument(
'--extensions', '--extensions',
help='comma separated list of file extensions (default: {})'.format( help='comma-separated list of file extensions'
DEFAULT_EXTENSIONS), f' (default: {DEFAULT_EXTENSIONS})',
default=DEFAULT_EXTENSIONS) default=DEFAULT_EXTENSIONS)
parser.add_argument( parser.add_argument(
'--fix', '--fix',
@ -290,14 +286,14 @@ def main():
parse_files = [] parse_files = []
if args.changed: if args.changed:
stdout = subprocess.Popen( with subprocess.Popen(
"git diff --name-only --cached", "git diff --name-only --cached",
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
shell=True, shell=True,
universal_newlines=True universal_newlines=True
).communicate()[0].split("\n") ) as child:
for line in stdout: for line in child.communicate()[0].split("\n"):
file_name = line.rstrip() file_name = line.rstrip()
# don't check deleted files # don't check deleted files
if os.path.isfile(file_name): if os.path.isfile(file_name):
@ -324,6 +320,7 @@ def main():
njobs = min(len(files), njobs) njobs = min(len(files), njobs)
if not args.fix: if not args.fix:
# pylint: disable=consider-using-with
patch_file = tempfile.NamedTemporaryFile(delete=False, patch_file = tempfile.NamedTemporaryFile(delete=False,
prefix='electron-format-') prefix='electron-format-')
@ -333,6 +330,7 @@ def main():
it = (run_clang_format_diff_wrapper(args, file) for file in files) it = (run_clang_format_diff_wrapper(args, file) for file in files)
pool = None pool = None
else: else:
# pylint: disable=consider-using-with
pool = multiprocessing.Pool(njobs) pool = multiprocessing.Pool(njobs)
it = pool.imap_unordered( it = pool.imap_unordered(
partial(run_clang_format_diff_wrapper, args), files) partial(run_clang_format_diff_wrapper, args), files)
@ -373,8 +371,11 @@ def main():
patch_file.close() patch_file.close()
os.unlink(patch_file.name) os.unlink(patch_file.name)
else: else:
print("\nTo patch these files, run:\n$ git apply {}\n" print(
.format(patch_file.name)) 'To patch these files, run:',
f"$ git apply {patch_file.name}", sep='\n')
filename=patch_file.name
print(f"\nTo patch these files, run:\n$ git apply {filename}\n")
return retcode return retcode

View file

@ -7,6 +7,6 @@ target = sys.argv[2]
os.chdir(os.path.dirname(source)) os.chdir(os.path.dirname(source))
tarball = tarfile.open(name=os.path.basename(target), mode='w:gz') with tarfile.open(name=os.path.basename(target), mode='w:gz') as tarball:
tarball.add(os.path.relpath(source)) tarball.add(os.path.relpath(source))
tarball.close() tarball.close()

View file

@ -21,8 +21,9 @@ def main():
chromedriver_path = os.path.join( chromedriver_path = os.path.join(
args.source_root, args.build_dir, chromedriver_name[sys.platform]) args.source_root, args.build_dir, chromedriver_name[sys.platform])
proc = subprocess.Popen([chromedriver_path], with subprocess.Popen([chromedriver_path],
stdout=subprocess.PIPE, universal_newlines=True) stdout=subprocess.PIPE,
universal_newlines=True) as proc:
try: try:
output = proc.stdout.readline() output = proc.stdout.readline()
except KeyboardInterrupt: except KeyboardInterrupt:

View file

@ -24,10 +24,10 @@ def main():
electron = os.path.join(app_path, 'Contents', 'MacOS', PRODUCT_NAME) electron = os.path.join(app_path, 'Contents', 'MacOS', PRODUCT_NAME)
ffmpeg_name = 'libffmpeg.dylib' ffmpeg_name = 'libffmpeg.dylib'
ffmpeg_app_path = os.path.join(app_path, 'Contents', 'Frameworks', ffmpeg_app_path = os.path.join(app_path, 'Contents', 'Frameworks',
'{0} Framework.framework'.format(PRODUCT_NAME), f'{PRODUCT_NAME} Framework.framework',
'Libraries') 'Libraries')
elif sys.platform == 'win32': elif sys.platform == 'win32':
electron = os.path.join(app_path, '{0}.exe'.format(PROJECT_NAME)) electron = os.path.join(app_path, f'{PROJECT_NAME}.exe')
ffmpeg_app_path = app_path ffmpeg_app_path = app_path
ffmpeg_name = 'ffmpeg.dll' ffmpeg_name = 'ffmpeg.dll'
else: else:
@ -69,7 +69,7 @@ def create_app_copy(initial_app_path):
+ '-no-proprietary-codecs') + '-no-proprietary-codecs')
if sys.platform == 'darwin': if sys.platform == 'darwin':
app_name = '{0}.app'.format(PRODUCT_NAME) app_name = f'{PRODUCT_NAME}.app'
initial_app_path = os.path.join(initial_app_path, app_name) initial_app_path = os.path.join(initial_app_path, app_name)
app_path = os.path.join(app_path, app_name) app_path = os.path.join(app_path, app_name)

View file

@ -26,8 +26,9 @@ def main():
try: try:
with scoped_cwd(app_path): with scoped_cwd(app_path):
if args.snapshot_files_dir is None: if args.snapshot_files_dir is None:
with open(os.path.join(app_path, 'mksnapshot_args')) as f: snapshot_filename = os.path.join(app_path, 'mksnapshot_args')
mkargs = f.read().splitlines() with open(snapshot_filename, encoding='utf-8') as file_in:
mkargs = file_in.read().splitlines()
print('running: ' + ' '.join(mkargs + [ SNAPSHOT_SOURCE ])) print('running: ' + ' '.join(mkargs + [ SNAPSHOT_SOURCE ]))
subprocess.check_call(mkargs + [ SNAPSHOT_SOURCE ], cwd=app_path) subprocess.check_call(mkargs + [ SNAPSHOT_SOURCE ], cwd=app_path)
print('ok mksnapshot successfully created snapshot_blob.bin.') print('ok mksnapshot successfully created snapshot_blob.bin.')
@ -41,7 +42,7 @@ def main():
gen_binary = get_binary_path('v8_context_snapshot_generator', \ gen_binary = get_binary_path('v8_context_snapshot_generator', \
app_path) app_path)
genargs = [ gen_binary, \ genargs = [ gen_binary, \
'--output_file={0}'.format(context_snapshot_path) ] f'--output_file={context_snapshot_path}' ]
print('running: ' + ' '.join(genargs)) print('running: ' + ' '.join(genargs))
subprocess.check_call(genargs) subprocess.check_call(genargs)
print('ok v8_context_snapshot_generator successfully created ' \ print('ok v8_context_snapshot_generator successfully created ' \
@ -59,15 +60,15 @@ def main():
if sys.platform == 'darwin': if sys.platform == 'darwin':
bin_files = glob.glob(os.path.join(app_path, '*.bin')) bin_files = glob.glob(os.path.join(app_path, '*.bin'))
app_dir = os.path.join(app_path, '{0}.app'.format(PRODUCT_NAME)) app_dir = os.path.join(app_path, f'{PRODUCT_NAME}.app')
electron = os.path.join(app_dir, 'Contents', 'MacOS', PRODUCT_NAME) electron = os.path.join(app_dir, 'Contents', 'MacOS', PRODUCT_NAME)
bin_out_path = os.path.join(app_dir, 'Contents', 'Frameworks', bin_out_path = os.path.join(app_dir, 'Contents', 'Frameworks',
'{0} Framework.framework'.format(PROJECT_NAME), f'{PROJECT_NAME} Framework.framework',
'Resources') 'Resources')
for bin_file in bin_files: for bin_file in bin_files:
shutil.copy2(bin_file, bin_out_path) shutil.copy2(bin_file, bin_out_path)
elif sys.platform == 'win32': elif sys.platform == 'win32':
electron = os.path.join(app_path, '{0}.exe'.format(PROJECT_NAME)) electron = os.path.join(app_path, f'{PROJECT_NAME}.exe')
else: else:
electron = os.path.join(app_path, PROJECT_NAME) electron = os.path.join(app_path, PROJECT_NAME)
@ -81,7 +82,7 @@ def main():
except KeyboardInterrupt: except KeyboardInterrupt:
print('Other error') print('Other error')
returncode = 0 returncode = 0
print('Returning with error code: {0}'.format(returncode)) print(f'Returning with error code: {returncode}')
return returncode return returncode
@ -98,7 +99,7 @@ def create_app_copy(initial_app_path):
def get_binary_path(binary_name, root_path): def get_binary_path(binary_name, root_path):
if sys.platform == 'win32': if sys.platform == 'win32':
binary_path = os.path.join(root_path, '{0}.exe'.format(binary_name)) binary_path = os.path.join(root_path, f'{binary_name}.exe')
else: else:
binary_path = os.path.join(root_path, binary_name) binary_path = os.path.join(root_path, binary_name)
return binary_path return binary_path

View file

@ -4,7 +4,7 @@ import zipfile
import sys import sys
def main(zip_path, manifest_in): def main(zip_path, manifest_in):
with open(manifest_in, 'r') as manifest, \ with open(manifest_in, 'r', encoding='utf-8') as manifest, \
zipfile.ZipFile(zip_path, 'r', allowZip64=True) as z: zipfile.ZipFile(zip_path, 'r', allowZip64=True) as z:
files_in_zip = set(z.namelist()) files_in_zip = set(z.namelist())
files_in_manifest = {l.strip() for l in manifest.readlines()} files_in_manifest = {l.strip() for l in manifest.readlines()}