diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2021-06-06 12:17:59 -0400 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2021-06-07 16:51:47 -0400 |
commit | 2c71b63e77dd41ffc180a210fe9b226cef2d62cb (patch) | |
tree | 4800dbb3a30aeca069872c71851b26dc7663c915 /mesonbuild/backend | |
parent | 40e8a67a837c4184ef02fa90eae05ef39f4b2199 (diff) | |
download | meson-2c71b63e77dd41ffc180a210fe9b226cef2d62cb.zip meson-2c71b63e77dd41ffc180a210fe9b226cef2d62cb.tar.gz meson-2c71b63e77dd41ffc180a210fe9b226cef2d62cb.tar.bz2 |
more f-strings everywhere
pyupgrade didn't catch many .format() methods which were too complex
(e.g. multiline or applied to templates rather than string literals)
Diffstat (limited to 'mesonbuild/backend')
-rw-r--r-- | mesonbuild/backend/backends.py | 22 | ||||
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 49 |
2 files changed, 33 insertions, 38 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 484e4cc..1f663b5 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -235,13 +235,13 @@ class Backend: self.environment.get_source_dir()) def generate(self) -> None: - raise RuntimeError('generate is not implemented in {}'.format(type(self).__name__)) + raise RuntimeError(f'generate is not implemented in {type(self).__name__}') def get_target_filename(self, t, *, warn_multi_output: bool = True): if isinstance(t, build.CustomTarget): if warn_multi_output and len(t.get_outputs()) != 1: - mlog.warning('custom_target {!r} has more than one output! ' - 'Using the first one.'.format(t.name)) + mlog.warning(f'custom_target {t.name!r} has more than one output! ' + 'Using the first one.') filename = t.get_outputs()[0] elif isinstance(t, build.CustomTargetIndex): filename = t.get_outputs()[0] @@ -753,7 +753,7 @@ class Backend: pch_file = os.path.join(self.build_dir, pch_rel_to_build) os.makedirs(os.path.dirname(pch_file), exist_ok=True) - content = '#include "{}"'.format(os.path.basename(pch_header)) + content = f'#include "{os.path.basename(pch_header)}"' pch_file_tmp = pch_file + '.tmp' with open(pch_file_tmp, 'w') as f: f.write(content) @@ -1245,8 +1245,8 @@ class Backend: i = i.replace('@CURRENT_SOURCE_DIR@', os.path.join(source_root, target.subdir)) if '@DEPFILE@' in i: if target.depfile is None: - msg = 'Custom target {!r} has @DEPFILE@ but no depfile ' \ - 'keyword argument.'.format(target.name) + msg = f'Custom target {target.name!r} has @DEPFILE@ but no depfile ' \ + 'keyword argument.' raise MesonException(msg) dfilename = os.path.join(outdir, target.depfile) i = i.replace('@DEPFILE@', dfilename) @@ -1257,8 +1257,8 @@ class Backend: pdir = self.get_target_private_dir(target) i = i.replace('@PRIVATE_DIR@', pdir) else: - err_msg = 'Argument {0} is of unknown type {1}' - raise RuntimeError(err_msg.format(str(i), str(type(i)))) + err_msg = f'Argument {i} is of unknown type {type(i)}' + raise RuntimeError(err_msg) cmd.append(i) # Substitute the rest of the template strings values = mesonlib.get_filenames_templates_dict(inputs, outputs) @@ -1449,8 +1449,8 @@ class Backend: outdir = os.path.join(incroot, h.get_install_subdir()) for f in h.get_sources(): if not isinstance(f, File): - msg = 'Invalid header type {!r} can\'t be installed' - raise MesonException(msg.format(f)) + msg = f'Invalid header type {f!r} can\'t be installed' + raise MesonException(msg) abspath = f.absolute_path(srcdir, builddir) i = InstallDataBase(abspath, outdir, h.get_custom_install_mode(), h.subproject) d.headers.append(i) @@ -1546,7 +1546,7 @@ class Backend: elif isinstance(j, (build.BuildTarget, build.CustomTarget)): compiler += j.get_outputs() else: - raise RuntimeError('Type "{}" is not supported in get_introspection_data. This is a bug'.format(type(j).__name__)) + raise RuntimeError(f'Type "{type(j).__name__}" is not supported in get_introspection_data. This is a bug') return [{ 'language': 'unknown', diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 8efb01b..33db672 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -133,11 +133,11 @@ def ninja_quote(text: str, is_build_line=False) -> str: if not quote_re.search(text): return text if '\n' in text: - errmsg = '''Ninja does not support newlines in rules. The content was: + errmsg = f'''Ninja does not support newlines in rules. The content was: -{} +{text} -Please report this error with a test case to the Meson bug tracker.'''.format(text) +Please report this error with a test case to the Meson bug tracker.''' raise MesonException(errmsg) return quote_re.sub(r'$\g<0>', text) @@ -437,8 +437,8 @@ class NinjaBackend(backends.Backend): # 'benchmark', etc, and also for RunTargets. # https://github.com/mesonbuild/meson/issues/1644 if not to_target.startswith('meson-'): - m = 'Invalid usage of create_target_alias with {!r}' - raise AssertionError(m.format(to_target)) + m = f'Invalid usage of create_target_alias with {to_target!r}' + raise AssertionError(m) from_target = to_target[len('meson-'):] elem = NinjaBuildElement(self.all_outputs, from_target, 'phony', to_target) self.add_build(elem) @@ -530,10 +530,10 @@ int dummy; num_pools = self.environment.coredata.options[OptionKey('backend_max_links')].value if num_pools > 0: - outfile.write('''pool link_pool - depth = {} + outfile.write(f'''pool link_pool + depth = {num_pools} -'''.format(num_pools)) +''') with self.detect_vs_dep_prefix(tempfilename) as outfile: self.generate_rules() @@ -776,9 +776,8 @@ int dummy; if langs_cant: langs_are = langs = ', '.join(langs_cant).upper() langs_are += ' are' if len(langs_cant) > 1 else ' is' - msg = '{} not supported in Unity builds yet, so {} ' \ - 'sources in the {!r} target will be compiled normally' \ - ''.format(langs_are, langs, target.name) + msg = f'{langs_are} not supported in Unity builds yet, so {langs} ' \ + f'sources in the {target.name!r} target will be compiled normally' mlog.log(mlog.red('FIXME'), msg) # Get a list of all generated headers that will be needed while building @@ -959,7 +958,6 @@ int dummy; (srcs, ofilenames, cmd) = self.eval_custom_target_command(target) deps = self.unwrap_dep_list(target) deps += self.get_custom_target_depend_files(target) - desc = 'Generating {0} with a custom command{1}' if target.build_always_stale: deps.append('PHONY') if target.depfile is None: @@ -990,7 +988,7 @@ int dummy; if target.console: elem.add_item('pool', 'console') elem.add_item('COMMAND', cmd) - elem.add_item('description', desc.format(target.name, cmd_type)) + elem.add_item('description', f'Generating {target.name} with a custom command{cmd_type}') self.add_build(elem) self.processed_targets.add(target.get_id()) @@ -1010,7 +1008,6 @@ int dummy; else: target_env = self.get_run_target_env(target) _, _, cmd = self.eval_custom_target_command(target) - desc = 'Running external command {}{}' meson_exe_cmd, reason = self.as_meson_exe_cmdline(target_name, target.command[0], cmd[1:], force_serialize=True, env=target_env, verbose=True) @@ -1018,7 +1015,7 @@ int dummy; internal_target_name = f'meson-{target_name}' elem = NinjaBuildElement(self.all_outputs, internal_target_name, 'CUSTOM_COMMAND', []) elem.add_item('COMMAND', meson_exe_cmd) - elem.add_item('description', desc.format(target.name, cmd_type)) + elem.add_item('description', f'Running external command {target.name}{cmd_type}') elem.add_item('pool', 'console') # Alias that runs the target defined above with the name the user specified self.create_target_alias(internal_target_name) @@ -1393,8 +1390,7 @@ int dummy; # either in the source root, or generated with configure_file and # in the build root if not isinstance(s, File): - msg = 'All sources in target {!r} must be of type ' \ - 'mesonlib.File, not {!r}'.format(t, s) + msg = f'All sources in target {t!r} must be of type mesonlib.File, not {s!r}' raise InvalidArguments(msg) f = s.rel_to_builddir(self.build_to_src) if s.endswith(('.vala', '.gs')): @@ -1433,8 +1429,8 @@ int dummy; (vala_src, vapi_src, other_src) = self.split_vala_sources(target) extra_dep_files = [] if not vala_src: - msg = 'Vala library {!r} has no Vala or Genie source files.' - raise InvalidArguments(msg.format(target.name)) + msg = f'Vala library {target.name!r} has no Vala or Genie source files.' + raise InvalidArguments(msg) valac = target.compilers['vala'] c_out_dir = self.get_target_private_dir(target) @@ -2263,8 +2259,8 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) modname = modmatch.group(1).lower() if modname in module_files: raise InvalidArguments( - 'Namespace collision: module {} defined in ' - 'two files {} and {}.'.format(modname, module_files[modname], s)) + f'Namespace collision: module {modname} defined in ' + 'two files {module_files[modname]} and {s}.') module_files[modname] = s else: submodmatch = submodre.match(line) @@ -2275,8 +2271,8 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) if submodname in submodule_files: raise InvalidArguments( - 'Namespace collision: submodule {} defined in ' - 'two files {} and {}.'.format(submodname, submodule_files[submodname], s)) + 'Namespace collision: submodule {submodname} defined in ' + 'two files {submodule_files[submodname]} and {s}.') submodule_files[submodname] = s self.fortran_deps[target.get_basename()] = {**module_files, **submodule_files} @@ -2695,9 +2691,8 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) if not pch: continue if not has_path_sep(pch[0]) or not has_path_sep(pch[-1]): - msg = 'Precompiled header of {!r} must not be in the same ' \ - 'directory as source, please put it in a subdirectory.' \ - ''.format(target.get_basename()) + msg = f'Precompiled header of {target.get_basename()!r} must not be in the same ' \ + 'directory as source, please put it in a subdirectory.' raise InvalidArguments(msg) compiler = target.compilers[lang] if isinstance(compiler, VisualStudioLikeCompiler): @@ -3331,7 +3326,7 @@ def _scan_fortran_file_deps(src: Path, srcdir: Path, dirname: Path, tdeps, compi parents = submodmatch.group(1).lower().split(':') assert len(parents) in (1, 2), ( 'submodule ancestry must be specified as' - ' ancestor:parent but Meson found {}'.format(parents)) + f' ancestor:parent but Meson found {parents}') ancestor_child = '_'.join(parents) if ancestor_child not in tdeps: |