aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mesonlib/universal.py
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2021-03-04 17:16:11 -0500
committerEli Schwartz <eschwartz@archlinux.org>2021-03-04 17:16:11 -0500
commit6a0fabc6472f49621260de215f128a31ae70219b (patch)
tree6a67908358a2c5e5baa215fe0201dfe213dd8a01 /mesonbuild/mesonlib/universal.py
parent4340bf34faca7eed8076ba4c388fbe15355f2183 (diff)
downloadmeson-6a0fabc6472f49621260de215f128a31ae70219b.zip
meson-6a0fabc6472f49621260de215f128a31ae70219b.tar.gz
meson-6a0fabc6472f49621260de215f128a31ae70219b.tar.bz2
mass rewrite of string formatting to use f-strings everywhere
performed by running "pyupgrade --py36-plus" and committing the results
Diffstat (limited to 'mesonbuild/mesonlib/universal.py')
-rw-r--r--mesonbuild/mesonlib/universal.py42
1 files changed, 21 insertions, 21 deletions
diff --git a/mesonbuild/mesonlib/universal.py b/mesonbuild/mesonlib/universal.py
index 4f1b6e8..b0c50c8 100644
--- a/mesonbuild/mesonlib/universal.py
+++ b/mesonbuild/mesonlib/universal.py
@@ -214,7 +214,7 @@ def set_meson_command(mainfile: str) -> None:
_meson_command = python_command + [mainfile]
# We print this value for unit tests.
if 'MESON_COMMAND_TESTS' in os.environ:
- mlog.log('meson_command is {!r}'.format(_meson_command))
+ mlog.log(f'meson_command is {_meson_command!r}')
def get_meson_command() -> T.Optional[T.List[str]]:
@@ -428,7 +428,7 @@ def get_compiler_for_source(compilers: T.Iterable['CompilerType'], src: str) ->
for comp in compilers:
if comp.can_compile(src):
return comp
- raise MesonException('No specified compiler can handle file {!s}'.format(src))
+ raise MesonException(f'No specified compiler can handle file {src!s}')
def classify_unity_sources(compilers: T.Iterable['CompilerType'], sources: T.Iterable[str]) -> T.Dict['CompilerType', T.List[str]]:
@@ -487,7 +487,7 @@ class PerMachine(T.Generic[_T]):
return unfreeze
def __repr__(self) -> str:
- return 'PerMachine({!r}, {!r})'.format(self.build, self.host)
+ return f'PerMachine({self.build!r}, {self.host!r})'
class PerThreeMachine(PerMachine[_T]):
@@ -522,7 +522,7 @@ class PerThreeMachine(PerMachine[_T]):
return self.build == self[machine]
def __repr__(self) -> str:
- return 'PerThreeMachine({!r}, {!r}, {!r})'.format(self.build, self.host, self.target)
+ return f'PerThreeMachine({self.build!r}, {self.host!r}, {self.target!r})'
class PerMachineDefaultable(PerMachine[T.Optional[_T]]):
@@ -543,7 +543,7 @@ class PerMachineDefaultable(PerMachine[T.Optional[_T]]):
return freeze
def __repr__(self) -> str:
- return 'PerMachineDefaultable({!r}, {!r})'.format(self.build, self.host)
+ return f'PerMachineDefaultable({self.build!r}, {self.host!r})'
class PerThreeMachineDefaultable(PerMachineDefaultable, PerThreeMachine[T.Optional[_T]]):
@@ -567,7 +567,7 @@ class PerThreeMachineDefaultable(PerMachineDefaultable, PerThreeMachine[T.Option
return freeze
def __repr__(self) -> str:
- return 'PerThreeMachineDefaultable({!r}, {!r}, {!r})'.format(self.build, self.host, self.target)
+ return f'PerThreeMachineDefaultable({self.build!r}, {self.host!r}, {self.target!r})'
def is_sunos() -> bool:
@@ -650,7 +650,7 @@ def darwin_get_object_archs(objpath: str) -> T.List[str]:
'''
_, stdo, stderr = Popen_safe(['lipo', '-info', objpath])
if not stdo:
- mlog.debug('lipo {}: {}'.format(objpath, stderr))
+ mlog.debug(f'lipo {objpath}: {stderr}')
return None
stdo = stdo.rsplit(': ', 1)[1]
# Convert from lipo-style archs to meson-style CPUs
@@ -704,10 +704,10 @@ class Version:
self._v = sequences3
def __str__(self) -> str:
- return '%s (V=%s)' % (self._s, str(self._v))
+ return '{} (V={})'.format(self._s, str(self._v))
def __repr__(self) -> str:
- return '<Version: {}>'.format(self._s)
+ return f'<Version: {self._s}>'
def __lt__(self, other: object) -> bool:
if isinstance(other, Version):
@@ -932,7 +932,7 @@ if is_windows():
# https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
_whitespace = ' \t\n\r'
- _find_unsafe_char = re.compile(r'[{}"]'.format(_whitespace)).search
+ _find_unsafe_char = re.compile(fr'[{_whitespace}"]').search
def quote_arg(arg: str) -> str:
if arg and not _find_unsafe_char(arg):
@@ -1073,7 +1073,7 @@ def do_define(regex: T.Pattern[str], line: str, confdata: 'ConfigurationData', v
result = v
else:
result = get_cmake_define(line, confdata)
- result = '#define %s %s\n' % (varname, result)
+ result = f'#define {varname} {result}\n'
(result, missing_variable) = do_replacement(regex, result, variable_format, confdata)
return result
else:
@@ -1087,7 +1087,7 @@ def get_variable_regex(variable_format: str = 'meson') -> T.Pattern[str]:
elif variable_format == 'cmake':
regex = re.compile(r'(?:\\\\)+(?=\\?\$)|\\\${|\${([-a-zA-Z0-9_]+)}')
else:
- raise MesonException('Format "{}" not handled'.format(variable_format))
+ raise MesonException(f'Format "{variable_format}" not handled')
return regex
def do_conf_str (data: list, confdata: 'ConfigurationData', variable_format: str,
@@ -1118,7 +1118,7 @@ def do_conf_str (data: list, confdata: 'ConfigurationData', variable_format: str
line = do_define(regex, line, confdata, variable_format)
else:
if not line_is_valid(line,variable_format):
- raise MesonException('Format "{}" mismatched'.format(variable_format))
+ raise MesonException(f'Format "{variable_format}" mismatched')
line, missing = do_replacement(regex, line, variable_format, confdata)
missing_variables.update(missing)
if missing:
@@ -1133,7 +1133,7 @@ def do_conf_file(src: str, dst: str, confdata: 'ConfigurationData', variable_for
with open(src, encoding=encoding, newline='') as f:
data = f.readlines()
except Exception as e:
- raise MesonException('Could not read input file %s: %s' % (src, str(e)))
+ raise MesonException('Could not read input file {}: {}'.format(src, str(e)))
(result, missing_variables, confdata_useless) = do_conf_str(data, confdata, variable_format, encoding)
dst_tmp = dst + '~'
@@ -1141,7 +1141,7 @@ def do_conf_file(src: str, dst: str, confdata: 'ConfigurationData', variable_for
with open(dst_tmp, 'w', encoding=encoding, newline='') as f:
f.writelines(result)
except Exception as e:
- raise MesonException('Could not write output file %s: %s' % (dst, str(e)))
+ raise MesonException('Could not write output file {}: {}'.format(dst, str(e)))
shutil.copymode(src, dst_tmp)
replace_if_different(dst, dst_tmp)
return missing_variables, confdata_useless
@@ -1181,11 +1181,11 @@ def dump_conf_header(ofilename: str, cdata: 'ConfigurationData', output_format:
ofile.write('; %s\n' % line)
if isinstance(v, bool):
if v:
- ofile.write('%sdefine %s\n\n' % (prefix, k))
+ ofile.write(f'{prefix}define {k}\n\n')
else:
- ofile.write('%sundef %s\n\n' % (prefix, k))
+ ofile.write(f'{prefix}undef {k}\n\n')
elif isinstance(v, (int, str)):
- ofile.write('%sdefine %s %s\n\n' % (prefix, k, v))
+ ofile.write(f'{prefix}define {k} {v}\n\n')
else:
raise MesonException('Unknown data type in configuration file entry: ' + k)
replace_if_different(ofilename, ofilename_tmp)
@@ -1489,7 +1489,7 @@ def get_filenames_templates_dict(inputs: T.List[str], outputs: T.List[str]) -> T
values['@INPUT@'] = inputs
for (ii, vv) in enumerate(inputs):
# Write out @INPUT0@, @INPUT1@, ...
- values['@INPUT{}@'.format(ii)] = vv
+ values[f'@INPUT{ii}@'] = vv
if len(inputs) == 1:
# Just one value, substitute @PLAINNAME@ and @BASENAME@
values['@PLAINNAME@'] = plain = os.path.basename(inputs[0])
@@ -1498,7 +1498,7 @@ def get_filenames_templates_dict(inputs: T.List[str], outputs: T.List[str]) -> T
# Gather values derived from the outputs, similar to above.
values['@OUTPUT@'] = outputs
for (ii, vv) in enumerate(outputs):
- values['@OUTPUT{}@'.format(ii)] = vv
+ values[f'@OUTPUT{ii}@'] = vv
# Outdir should be the same for all outputs
values['@OUTDIR@'] = os.path.dirname(outputs[0])
# Many external programs fail on empty arguments.
@@ -1719,7 +1719,7 @@ class ProgressBarFallback: # lgtm [py/iter-returns-non-self]
if self.total and bar_type == 'download':
print('Download size:', self.total)
if desc:
- print('{}: '.format(desc), end='')
+ print(f'{desc}: ', end='')
# Pretend to be an iterator when called as one and don't print any
# progress