diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2021-03-04 17:16:11 -0500 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2021-03-04 17:16:11 -0500 |
commit | 6a0fabc6472f49621260de215f128a31ae70219b (patch) | |
tree | 6a67908358a2c5e5baa215fe0201dfe213dd8a01 /mesonbuild/cmake/interpreter.py | |
parent | 4340bf34faca7eed8076ba4c388fbe15355f2183 (diff) | |
download | meson-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/cmake/interpreter.py')
-rw-r--r-- | mesonbuild/cmake/interpreter.py | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py index abb4983..cccd358 100644 --- a/mesonbuild/cmake/interpreter.py +++ b/mesonbuild/cmake/interpreter.py @@ -175,7 +175,7 @@ class OutputTargetMap: continue new_name = name[:-len(i) - 1] new_name = OutputTargetMap.rm_so_version.sub('', new_name) - candidates += ['{}.{}'.format(new_name, i)] + candidates += [f'{new_name}.{i}'] for i in candidates: keys += [self._rel_artifact_key(Path(i)), Path(i).name, self._base_artifact_key(Path(i))] return self._return_first_valid_key(keys) @@ -194,21 +194,21 @@ class OutputTargetMap: return None def _target_key(self, tgt_name: str) -> str: - return '__tgt_{}__'.format(tgt_name) + return f'__tgt_{tgt_name}__' def _rel_generated_file_key(self, fname: Path) -> T.Optional[str]: path = self._rel_path(fname) - return '__relgen_{}__'.format(path.as_posix()) if path else None + return f'__relgen_{path.as_posix()}__' if path else None def _base_generated_file_key(self, fname: Path) -> str: - return '__gen_{}__'.format(fname.name) + return f'__gen_{fname.name}__' def _rel_artifact_key(self, fname: Path) -> T.Optional[str]: path = self._rel_path(fname) - return '__relart_{}__'.format(path.as_posix()) if path else None + return f'__relart_{path.as_posix()}__' if path else None def _base_artifact_key(self, fname: Path) -> str: - return '__art_{}__'.format(fname.name) + return f'__art_{fname.name}__' class ConverterTarget: def __init__(self, target: CMakeTarget, env: 'Environment', for_machine: MachineChoice) -> None: @@ -281,7 +281,7 @@ class ConverterTarget: # Add arguments, but avoid duplicates args = i.flags - args += ['-D{}'.format(x) for x in i.defines] + args += [f'-D{x}' for x in i.defines] for lang in languages: self.compile_opts[lang] += [x for x in args if x not in self.compile_opts[lang]] @@ -296,7 +296,7 @@ class ConverterTarget: self.sources += i.sources def __repr__(self) -> str: - return '<{}: {}>'.format(self.__class__.__name__, self.name) + return f'<{self.__class__.__name__}: {self.name}>' std_regex = re.compile(r'([-]{1,2}std=|/std:v?|[-]{1,2}std:)(.*)') @@ -321,7 +321,7 @@ class ConverterTarget: once=True ) continue - self.override_options += ['{}_std={}'.format(i, std)] + self.override_options += [f'{i}_std={std}'] elif j in ['-fPIC', '-fpic', '-fPIE', '-fpie']: self.pie = True elif isinstance(ctgt, ConverterCustomTarget): @@ -393,12 +393,12 @@ class ConverterTarget: if 'RELEASE' in cfgs: cfg = 'RELEASE' - if 'IMPORTED_IMPLIB_{}'.format(cfg) in tgt.properties: - libraries += [x for x in tgt.properties['IMPORTED_IMPLIB_{}'.format(cfg)] if x] + if f'IMPORTED_IMPLIB_{cfg}' in tgt.properties: + libraries += [x for x in tgt.properties[f'IMPORTED_IMPLIB_{cfg}'] if x] elif 'IMPORTED_IMPLIB' in tgt.properties: libraries += [x for x in tgt.properties['IMPORTED_IMPLIB'] if x] - elif 'IMPORTED_LOCATION_{}'.format(cfg) in tgt.properties: - libraries += [x for x in tgt.properties['IMPORTED_LOCATION_{}'.format(cfg)] if x] + elif f'IMPORTED_LOCATION_{cfg}' in tgt.properties: + libraries += [x for x in tgt.properties[f'IMPORTED_LOCATION_{cfg}'] if x] elif 'IMPORTED_LOCATION' in tgt.properties: libraries += [x for x in tgt.properties['IMPORTED_LOCATION'] if x] @@ -408,8 +408,8 @@ class ConverterTarget: if 'INTERFACE_LINK_LIBRARIES' in tgt.properties: otherDeps += [x for x in tgt.properties['INTERFACE_LINK_LIBRARIES'] if x] - if 'IMPORTED_LINK_DEPENDENT_LIBRARIES_{}'.format(cfg) in tgt.properties: - otherDeps += [x for x in tgt.properties['IMPORTED_LINK_DEPENDENT_LIBRARIES_{}'.format(cfg)] if x] + if f'IMPORTED_LINK_DEPENDENT_LIBRARIES_{cfg}' in tgt.properties: + otherDeps += [x for x in tgt.properties[f'IMPORTED_LINK_DEPENDENT_LIBRARIES_{cfg}'] if x] elif 'IMPORTED_LINK_DEPENDENT_LIBRARIES' in tgt.properties: otherDeps += [x for x in tgt.properties['IMPORTED_LINK_DEPENDENT_LIBRARIES'] if x] @@ -445,7 +445,7 @@ class ConverterTarget: supported = list(header_suffixes) + list(obj_suffixes) for i in self.languages: supported += list(lang_suffixes[i]) - supported = ['.{}'.format(x) for x in supported] + supported = [f'.{x}' for x in supported] self.sources = [x for x in self.sources if any([x.name.endswith(y) for y in supported])] self.generated_raw = [x for x in self.generated_raw if any([x.name.endswith(y) for y in supported])] @@ -560,7 +560,7 @@ class ConverterTarget: candidates = [j] # type: T.List[str] if not any([j.endswith('.' + x) for x in exts]): mlog.warning('Object files do not contain source file extensions, thus falling back to guessing them.', once=True) - candidates += ['{}.{}'.format(j, x) for x in exts] + candidates += [f'{j}.{x}' for x in exts] if any([x in source_files for x in candidates]): if linker_workaround: self._append_objlib_sources(i) @@ -632,7 +632,7 @@ class ConverterTarget: return target_type_map.get(self.type.upper()) def log(self) -> None: - mlog.log('Target', mlog.bold(self.name), '({})'.format(self.cmake_name)) + mlog.log('Target', mlog.bold(self.name), f'({self.cmake_name})') mlog.log(' -- artifacts: ', mlog.bold(str(self.artifacts))) mlog.log(' -- full_name: ', mlog.bold(self.full_name)) mlog.log(' -- type: ', mlog.bold(self.type)) @@ -664,7 +664,7 @@ class CustomTargetReference: if self.valid(): return '<{}: {} [{}]>'.format(self.__class__.__name__, self.ctgt.name, self.ctgt.outputs[self.index]) else: - return '<{}: INVALID REFERENCE>'.format(self.__class__.__name__) + return f'<{self.__class__.__name__}: INVALID REFERENCE>' def valid(self) -> bool: return self.ctgt is not None and self.index >= 0 @@ -681,7 +681,7 @@ class ConverterCustomTarget: assert target.current_src_dir is not None self.name = target.name if not self.name: - self.name = 'custom_tgt_{}'.format(ConverterCustomTarget.tgt_counter) + self.name = f'custom_tgt_{ConverterCustomTarget.tgt_counter}' ConverterCustomTarget.tgt_counter += 1 self.cmake_name = str(self.name) self.original_outputs = list(target.outputs) @@ -702,7 +702,7 @@ class ConverterCustomTarget: self.name = _sanitize_cmake_name(self.name) def __repr__(self) -> str: - return '<{}: {} {}>'.format(self.__class__.__name__, self.name, self.outputs) + return f'<{self.__class__.__name__}: {self.name} {self.outputs}>' def postprocess(self, output_target_map: OutputTargetMap, root_src_dir: Path, all_outputs: T.List[str], trace: CMakeTraceParser) -> None: # Default the working directory to ${CMAKE_CURRENT_BINARY_DIR} @@ -730,7 +730,7 @@ class ConverterCustomTarget: for i in self.outputs: if i in all_outputs: old = str(i) - i = 'c{}_{}'.format(ConverterCustomTarget.out_counter, i) + i = f'c{ConverterCustomTarget.out_counter}_{i}' ConverterCustomTarget.out_counter += 1 self.conflict_map[old] = i all_outputs += [i] @@ -760,7 +760,7 @@ class ConverterCustomTarget: if trace_tgt.type == 'EXECUTABLE' and 'IMPORTED_LOCATION' in trace_tgt.properties: cmd += trace_tgt.properties['IMPORTED_LOCATION'] continue - mlog.debug('CMake: Found invalid CMake target "{}" --> ignoring \n{}'.format(j, trace_tgt)) + mlog.debug(f'CMake: Found invalid CMake target "{j}" --> ignoring \n{trace_tgt}') # Fallthrough on error cmd += [j] @@ -829,7 +829,7 @@ class ConverterCustomTarget: return None def log(self) -> None: - mlog.log('Custom Target', mlog.bold(self.name), '({})'.format(self.cmake_name)) + mlog.log('Custom Target', mlog.bold(self.name), f'({self.cmake_name})') mlog.log(' -- command: ', mlog.bold(str(self.command))) mlog.log(' -- outputs: ', mlog.bold(str(self.outputs))) mlog.log(' -- conflict_map: ', mlog.bold(str(self.conflict_map))) @@ -901,10 +901,10 @@ class CMakeInterpreter: generator = backend_generator_map[self.backend_name] cmake_args = [] cmake_args += ['-G', generator] - cmake_args += ['-DCMAKE_INSTALL_PREFIX={}'.format(self.install_prefix)] + cmake_args += [f'-DCMAKE_INSTALL_PREFIX={self.install_prefix}'] cmake_args += extra_cmake_options trace_args = self.trace.trace_args() - cmcmp_args = ['-DCMAKE_POLICY_WARNING_{}=OFF'.format(x) for x in disable_policy_warnings] + cmcmp_args = [f'-DCMAKE_POLICY_WARNING_{x}=OFF' for x in disable_policy_warnings] if version_compare(cmake_exe.version(), '>=3.14'): self.cmake_api = CMakeAPI.FILE @@ -1217,14 +1217,14 @@ class CMakeInterpreter: # Determine the meson function to use for the build target tgt_func = tgt.meson_func() if not tgt_func: - raise CMakeException('Unknown target type "{}"'.format(tgt.type)) + raise CMakeException(f'Unknown target type "{tgt.type}"') # Determine the variable names - inc_var = '{}_inc'.format(tgt.name) - dir_var = '{}_dir'.format(tgt.name) - sys_var = '{}_sys'.format(tgt.name) - src_var = '{}_src'.format(tgt.name) - dep_var = '{}_dep'.format(tgt.name) + inc_var = f'{tgt.name}_inc' + dir_var = f'{tgt.name}_dir' + sys_var = f'{tgt.name}_sys' + src_var = f'{tgt.name}_src' + dep_var = f'{tgt.name}_dep' tgt_var = tgt.name install_tgt = options.get_install(tgt.cmake_name, tgt.install) @@ -1246,7 +1246,7 @@ class CMakeInterpreter: # Handle compiler args for key, val in tgt.compile_opts.items(): - tgt_kwargs['{}_args'.format(key)] = options.get_compile_args(tgt.cmake_name, key, val) + tgt_kwargs[f'{key}_args'] = options.get_compile_args(tgt.cmake_name, key, val) # Handle -fPCI, etc if tgt_func == 'executable': |