Skip to content

Commit 6a0fabc

Browse files
committed
mass rewrite of string formatting to use f-strings everywhere
performed by running "pyupgrade --py36-plus" and committing the results
1 parent 4340bf3 commit 6a0fabc

File tree

109 files changed

+917
-917
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+917
-917
lines changed

docs/genrelnotes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def generate(from_version, to_version):
5050
'''
5151
Generate notes for Meson build next release.
5252
'''
53-
ofilename = 'Release-notes-for-{}.md'.format(to_version)
53+
ofilename = f'Release-notes-for-{to_version}.md'
5454
with open(ofilename, 'w') as ofile:
5555
ofile.write(RELNOTE_TEMPLATE.format(to_version, to_version))
5656
for snippetfile in glob('snippets/*.md'):

ghwt.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def list_projects():
4343
def unpack(sproj, branch):
4444
tmpdir = os.path.join(spdir, sproj + '_ghwt')
4545
shutil.rmtree(tmpdir, ignore_errors=True)
46-
subprocess.check_call(['git', 'clone', '-b', branch, 'https://github.com/mesonbuild/{}.git'.format(sproj), tmpdir])
46+
subprocess.check_call(['git', 'clone', '-b', branch, f'https://github.com/mesonbuild/{sproj}.git', tmpdir])
4747
usfile = os.path.join(tmpdir, 'upstream.wrap')
4848
assert(os.path.isfile(usfile))
4949
config = configparser.ConfigParser(interpolation=None)
@@ -52,7 +52,7 @@ def unpack(sproj, branch):
5252
if 'directory' in config['wrap-file']:
5353
outdir = os.path.join(spdir, config['wrap-file']['directory'])
5454
if os.path.isdir(outdir):
55-
print('Subproject is already there. To update, nuke the {} dir and reinstall.'.format(outdir))
55+
print(f'Subproject is already there. To update, nuke the {outdir} dir and reinstall.')
5656
shutil.rmtree(tmpdir)
5757
return 1
5858
us_url = config['wrap-file']['source_url']
@@ -85,7 +85,7 @@ def install(sproj, requested_branch=None):
8585
if not os.path.isdir(spdir):
8686
print('Run this in your source root and make sure there is a subprojects directory in it.')
8787
return 1
88-
blist = gh_get('https://api.github.com/repos/mesonbuild/{}/branches'.format(sproj))
88+
blist = gh_get(f'https://api.github.com/repos/mesonbuild/{sproj}/branches')
8989
blist = [b['name'] for b in blist]
9090
blist = [b for b in blist if b != 'master']
9191
blist.sort()

mesonbuild/arglist.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def __iadd__(self, args: T.Iterable[str]) -> 'CompilerArgs':
290290
'''
291291
tmp_pre = collections.deque() # type: T.Deque[str]
292292
if not isinstance(args, collections.abc.Iterable):
293-
raise TypeError('can only concatenate Iterable[str] (not "{}") to CompilerArgs'.format(args))
293+
raise TypeError(f'can only concatenate Iterable[str] (not "{args}") to CompilerArgs')
294294
for arg in args:
295295
# If the argument can be de-duped, do it either by removing the
296296
# previous occurrence of it and adding a new one, or not adding the
@@ -331,4 +331,4 @@ def extend(self, args: T.Iterable[str]) -> None:
331331

332332
def __repr__(self) -> str:
333333
self.flush_pre_post()
334-
return 'CompilerArgs({!r}, {!r})'.format(self.compiler, self._container)
334+
return f'CompilerArgs({self.compiler!r}, {self._container!r})'

mesonbuild/ast/interpreter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def load_root_meson_file(self) -> None:
141141
def func_subdir(self, node: BaseNode, args: T.List[TYPE_nvar], kwargs: T.Dict[str, TYPE_nvar]) -> None:
142142
args = self.flatten_args(args)
143143
if len(args) != 1 or not isinstance(args[0], str):
144-
sys.stderr.write('Unable to evaluate subdir({}) in AstInterpreter --> Skipping\n'.format(args))
144+
sys.stderr.write(f'Unable to evaluate subdir({args}) in AstInterpreter --> Skipping\n')
145145
return
146146

147147
prev_subdir = self.subdir
@@ -156,7 +156,7 @@ def func_subdir(self, node: BaseNode, args: T.List[TYPE_nvar], kwargs: T.Dict[st
156156
self.visited_subdirs[symlinkless_dir] = True
157157

158158
if not os.path.isfile(absname):
159-
sys.stderr.write('Unable to find build file {} --> Skipping\n'.format(buildfilename))
159+
sys.stderr.write(f'Unable to find build file {buildfilename} --> Skipping\n')
160160
return
161161
with open(absname, encoding='utf8') as f:
162162
code = f.read()

mesonbuild/backend/backends.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def from_str(cls, string: str) -> 'TestProtocol':
6565
return cls.GTEST
6666
elif string == 'rust':
6767
return cls.RUST
68-
raise MesonException('unknown test format {}'.format(string))
68+
raise MesonException(f'unknown test format {string}')
6969

7070
def __str__(self) -> str:
7171
cls = type(self)
@@ -282,14 +282,14 @@ def get_target_filename_for_linking(self, target):
282282
return os.path.join(self.get_target_dir(target), target.get_filename())
283283
elif isinstance(target, (build.CustomTarget, build.CustomTargetIndex)):
284284
if not target.is_linkable_target():
285-
raise MesonException('Tried to link against custom target "{}", which is not linkable.'.format(target.name))
285+
raise MesonException(f'Tried to link against custom target "{target.name}", which is not linkable.')
286286
return os.path.join(self.get_target_dir(target), target.get_filename())
287287
elif isinstance(target, build.Executable):
288288
if target.import_filename:
289289
return os.path.join(self.get_target_dir(target), target.get_import_filename())
290290
else:
291291
return None
292-
raise AssertionError('BUG: Tried to link to {!r} which is not linkable'.format(target))
292+
raise AssertionError(f'BUG: Tried to link to {target!r} which is not linkable')
293293

294294
@lru_cache(maxsize=None)
295295
def get_target_dir(self, target):
@@ -335,7 +335,7 @@ def get_target_generated_dir(self, target, gensrc, src):
335335
def get_unity_source_file(self, target, suffix, number):
336336
# There is a potential conflict here, but it is unlikely that
337337
# anyone both enables unity builds and has a file called foo-unity.cpp.
338-
osrc = '{}-unity{}.{}'.format(target.name, number, suffix)
338+
osrc = f'{target.name}-unity{number}.{suffix}'
339339
return mesonlib.File.from_built_file(self.get_target_private_dir(target), osrc)
340340

341341
def generate_unity_files(self, target, unity_src):
@@ -368,7 +368,7 @@ def init_language_file(suffix, unity_file_number):
368368
ofile = init_language_file(comp.get_default_suffix(), unity_file_number)
369369
unity_file_number += 1
370370
files_in_current = 0
371-
ofile.write('#include<{}>\n'.format(src))
371+
ofile.write(f'#include<{src}>\n')
372372
files_in_current += 1
373373
if ofile:
374374
ofile.close()
@@ -505,7 +505,7 @@ def as_meson_exe_cmdline(self, tname, exe, cmd_args, workdir=None,
505505
data = bytes(str(es.env) + str(es.cmd_args) + str(es.workdir) + str(capture),
506506
encoding='utf-8')
507507
digest = hashlib.sha1(data).hexdigest()
508-
scratch_file = 'meson_exe_{}_{}.dat'.format(basename, digest)
508+
scratch_file = f'meson_exe_{basename}_{digest}.dat'
509509
exe_data = os.path.join(self.environment.get_scratch_dir(), scratch_file)
510510
with open(exe_data, 'wb') as f:
511511
pickle.dump(es, f)
@@ -575,7 +575,7 @@ def get_external_rpath_dirs(self, target):
575575
for dir in symbols_match.group(1).split(':'):
576576
# Prevent usage of --just-symbols to specify rpath
577577
if Path(dir).is_dir():
578-
raise MesonException('Invalid arg for --just-symbols, {} is a directory.'.format(dir))
578+
raise MesonException(f'Invalid arg for --just-symbols, {dir} is a directory.')
579579
return dirs
580580

581581
def rpaths_for_bundled_shared_libraries(self, target, exclude_system=True):
@@ -601,7 +601,7 @@ def rpaths_for_bundled_shared_libraries(self, target, exclude_system=True):
601601
continue
602602
if libdir.startswith(self.environment.get_source_dir()):
603603
rel_to_src = libdir[len(self.environment.get_source_dir()) + 1:]
604-
assert not os.path.isabs(rel_to_src), 'rel_to_src: {} is absolute'.format(rel_to_src)
604+
assert not os.path.isabs(rel_to_src), f'rel_to_src: {rel_to_src} is absolute'
605605
paths.append(os.path.join(self.build_to_src, rel_to_src))
606606
else:
607607
paths.append(libdir)
@@ -717,7 +717,7 @@ def get_pch_include_args(self, compiler, target):
717717
def create_msvc_pch_implementation(self, target, lang, pch_header):
718718
# We have to include the language in the file name, otherwise
719719
# pch.c and pch.cpp will both end up as pch.obj in VS backends.
720-
impl_name = 'meson_pch-{}.{}'.format(lang, lang)
720+
impl_name = f'meson_pch-{lang}.{lang}'
721721
pch_rel_to_build = os.path.join(self.get_target_private_dir(target), impl_name)
722722
# Make sure to prepend the build dir, since the working directory is
723723
# not defined. Otherwise, we might create the file in the wrong path.
@@ -833,7 +833,7 @@ def build_target_link_arguments(self, compiler, deps):
833833
args = []
834834
for d in deps:
835835
if not (d.is_linkable_target()):
836-
raise RuntimeError('Tried to link with a non-library target "{}".'.format(d.get_basename()))
836+
raise RuntimeError(f'Tried to link with a non-library target "{d.get_basename()}".')
837837
arg = self.get_target_filename_for_linking(d)
838838
if not arg:
839839
continue
@@ -1011,7 +1011,7 @@ def check_clock_skew(self, file_list):
10111011
# to the future by a minuscule amount, less than
10121012
# 0.001 seconds. I don't know why.
10131013
if delta > 0.001:
1014-
raise MesonException('Clock skew detected. File {} has a time stamp {:.4f}s in the future.'.format(absf, delta))
1014+
raise MesonException(f'Clock skew detected. File {absf} has a time stamp {delta:.4f}s in the future.')
10151015

10161016
def build_target_to_cmd_array(self, bt):
10171017
if isinstance(bt, build.BuildTarget):
@@ -1036,7 +1036,7 @@ def replace_outputs(self, args, private_dir, output_list):
10361036
m = regex.search(arg)
10371037
while m is not None:
10381038
index = int(m.group(1))
1039-
src = '@OUTPUT{}@'.format(index)
1039+
src = f'@OUTPUT{index}@'
10401040
arg = arg.replace(src, os.path.join(private_dir, output_list[index]))
10411041
m = regex.search(arg)
10421042
newargs.append(arg)
@@ -1239,7 +1239,7 @@ def run_postconf_scripts(self) -> None:
12391239

12401240
for s in self.build.postconf_scripts:
12411241
name = ' '.join(s.cmd_args)
1242-
mlog.log('Running postconf script {!r}'.format(name))
1242+
mlog.log(f'Running postconf script {name!r}')
12431243
run_exe(s, env)
12441244

12451245
def create_install_data(self) -> InstallData:

0 commit comments

Comments
 (0)