aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2021-03-04 17:02:31 -0500
committerEli Schwartz <eschwartz@archlinux.org>2021-03-04 17:11:26 -0500
commit4340bf34faca7eed8076ba4c388fbe15355f2183 (patch)
tree6082548a6cb79091d1059a73e7b3b9f59657f6d9 /mesonbuild
parent76df995ba69ef5d790462856b3edbd42b28b906a (diff)
downloadmeson-4340bf34faca7eed8076ba4c388fbe15355f2183.zip
meson-4340bf34faca7eed8076ba4c388fbe15355f2183.tar.gz
meson-4340bf34faca7eed8076ba4c388fbe15355f2183.tar.bz2
various python neatness cleanups
All changes were created by running "pyupgrade --py3-only --keep-percent-format" and committing the results. I have not touched string formatting for now. - use set literals - simplify .format() parameter naming - remove __future__ - remove default "r" mode for open() - use OSError rather than compatibility aliases - remove stray parentheses in function(generator) scopes
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/backend/backends.py2
-rw-r--r--mesonbuild/build.py42
-rw-r--r--mesonbuild/compilers/compilers.py18
-rw-r--r--mesonbuild/compilers/cuda.py4
-rw-r--r--mesonbuild/compilers/d.py24
-rw-r--r--mesonbuild/compilers/mixins/clike.py6
-rw-r--r--mesonbuild/coredata.py4
-rw-r--r--mesonbuild/dependencies/cuda.py2
-rw-r--r--mesonbuild/dependencies/hdf5.py2
-rw-r--r--mesonbuild/environment.py4
-rw-r--r--mesonbuild/interpreter.py20
-rw-r--r--mesonbuild/linkers.py6
-rw-r--r--mesonbuild/mconf.py2
-rw-r--r--mesonbuild/mintro.py2
-rw-r--r--mesonbuild/mlog.py4
-rw-r--r--mesonbuild/modules/cmake.py4
-rw-r--r--mesonbuild/modules/dlang.py2
-rw-r--r--mesonbuild/modules/fs.py2
-rw-r--r--mesonbuild/modules/keyval.py2
-rw-r--r--mesonbuild/modules/python.py6
-rw-r--r--mesonbuild/mtest.py12
-rw-r--r--mesonbuild/optinterpreter.py2
-rw-r--r--mesonbuild/rewriter.py4
-rw-r--r--mesonbuild/scripts/meson_exe.py2
-rw-r--r--mesonbuild/scripts/symbolextractor.py2
-rw-r--r--mesonbuild/wrap/wrap.py2
26 files changed, 91 insertions, 91 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index b663736..2e1f081 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -505,7 +505,7 @@ class Backend:
data = bytes(str(es.env) + str(es.cmd_args) + str(es.workdir) + str(capture),
encoding='utf-8')
digest = hashlib.sha1(data).hexdigest()
- scratch_file = 'meson_exe_{0}_{1}.dat'.format(basename, digest)
+ scratch_file = 'meson_exe_{}_{}.dat'.format(basename, digest)
exe_data = os.path.join(self.environment.get_scratch_dir(), scratch_file)
with open(exe_data, 'wb') as f:
pickle.dump(es, f)
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 10d6e3c..77dfdaa 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -43,9 +43,9 @@ if T.TYPE_CHECKING:
from .mesonlib import FileMode, FileOrString
from .mesonlib.backend import Backend
-pch_kwargs = set(['c_pch', 'cpp_pch'])
+pch_kwargs = {'c_pch', 'cpp_pch'}
-lang_arg_kwargs = set([
+lang_arg_kwargs = {
'c_args',
'cpp_args',
'cuda_args',
@@ -61,13 +61,13 @@ lang_arg_kwargs = set([
'rust_args',
'vala_args',
'cs_args',
-])
+}
-vala_kwargs = set(['vala_header', 'vala_gir', 'vala_vapi'])
-rust_kwargs = set(['rust_crate_type'])
-cs_kwargs = set(['resources', 'cs_args'])
+vala_kwargs = {'vala_header', 'vala_gir', 'vala_vapi'}
+rust_kwargs = {'rust_crate_type'}
+cs_kwargs = {'resources', 'cs_args'}
-buildtarget_kwargs = set([
+buildtarget_kwargs = {
'build_by_default',
'build_rpath',
'dependencies',
@@ -92,7 +92,7 @@ buildtarget_kwargs = set([
'gnu_symbol_visibility',
'link_language',
'win_subsystem',
-])
+}
known_build_target_kwargs = (
buildtarget_kwargs |
@@ -1723,8 +1723,8 @@ class Executable(BuildTarget):
if not isinstance(kwargs.get('implib', False), bool):
implib_basename = kwargs['implib']
if m.is_windows() or m.is_cygwin():
- self.vs_import_filename = '{0}.lib'.format(implib_basename)
- self.gcc_import_filename = 'lib{0}.a'.format(implib_basename)
+ self.vs_import_filename = '{}.lib'.format(implib_basename)
+ self.gcc_import_filename = 'lib{}.a'.format(implib_basename)
if self.get_using_msvc():
self.import_filename = self.vs_import_filename
else:
@@ -1787,7 +1787,7 @@ class StaticLibrary(BuildTarget):
self.rust_crate_type = 'rlib'
# Don't let configuration proceed with a non-static crate type
elif self.rust_crate_type not in ['rlib', 'staticlib']:
- raise InvalidArguments('Crate type "{0}" invalid for static libraries; must be "rlib" or "staticlib"'.format(self.rust_crate_type))
+ raise InvalidArguments('Crate type "{}" invalid for static libraries; must be "rlib" or "staticlib"'.format(self.rust_crate_type))
# By default a static library is named libfoo.a even on Windows because
# MSVC does not have a consistent convention for what static libraries
# are called. The MSVC CRT uses libfoo.lib syntax but nothing else uses
@@ -1828,7 +1828,7 @@ class StaticLibrary(BuildTarget):
if isinstance(rust_crate_type, str):
self.rust_crate_type = rust_crate_type
else:
- raise InvalidArguments('Invalid rust_crate_type "{0}": must be a string.'.format(rust_crate_type))
+ raise InvalidArguments('Invalid rust_crate_type "{}": must be a string.'.format(rust_crate_type))
def is_linkable_target(self):
return True
@@ -1859,7 +1859,7 @@ class SharedLibrary(BuildTarget):
self.rust_crate_type = 'dylib'
# Don't let configuration proceed with a non-dynamic crate type
elif self.rust_crate_type not in ['dylib', 'cdylib']:
- raise InvalidArguments('Crate type "{0}" invalid for dynamic libraries; must be "dylib" or "cdylib"'.format(self.rust_crate_type))
+ raise InvalidArguments('Crate type "{}" invalid for dynamic libraries; must be "dylib" or "cdylib"'.format(self.rust_crate_type))
if not hasattr(self, 'prefix'):
self.prefix = None
if not hasattr(self, 'suffix'):
@@ -1919,13 +1919,13 @@ class SharedLibrary(BuildTarget):
# For all other targets/platforms import_filename stays None
elif env.machines[self.for_machine].is_windows():
suffix = 'dll'
- self.vs_import_filename = '{0}{1}.lib'.format(self.prefix if self.prefix is not None else '', self.name)
- self.gcc_import_filename = '{0}{1}.dll.a'.format(self.prefix if self.prefix is not None else 'lib', self.name)
+ self.vs_import_filename = '{}{}.lib'.format(self.prefix if self.prefix is not None else '', self.name)
+ self.gcc_import_filename = '{}{}.dll.a'.format(self.prefix if self.prefix is not None else 'lib', self.name)
if self.uses_rust():
# Shared library is of the form foo.dll
prefix = ''
# Import library is called foo.dll.lib
- self.import_filename = '{0}.dll.lib'.format(self.name)
+ self.import_filename = '{}.dll.lib'.format(self.name)
create_debug_file = True
elif self.get_using_msvc():
# Shared library is of the form foo.dll
@@ -1946,7 +1946,7 @@ class SharedLibrary(BuildTarget):
self.filename_tpl = '{0.prefix}{0.name}.{0.suffix}'
elif env.machines[self.for_machine].is_cygwin():
suffix = 'dll'
- self.gcc_import_filename = '{0}{1}.dll.a'.format(self.prefix if self.prefix is not None else 'lib', self.name)
+ self.gcc_import_filename = '{}{}.dll.a'.format(self.prefix if self.prefix is not None else 'lib', self.name)
# Shared library is of the form cygfoo.dll
# (ld --dll-search-prefix=cyg is the default)
prefix = 'cyg'
@@ -2045,7 +2045,7 @@ class SharedLibrary(BuildTarget):
if not isinstance(self.ltversion, str):
raise InvalidArguments('Shared library version needs to be a string, not ' + type(self.ltversion).__name__)
if not re.fullmatch(r'[0-9]+(\.[0-9]+){0,2}', self.ltversion):
- raise InvalidArguments('Invalid Shared library version "{0}". Must be of the form X.Y.Z where all three are numbers. Y and Z are optional.'.format(self.ltversion))
+ raise InvalidArguments('Invalid Shared library version "{}". Must be of the form X.Y.Z where all three are numbers. Y and Z are optional.'.format(self.ltversion))
# Try to extract/deduce the soversion
if 'soversion' in kwargs:
self.soversion = kwargs['soversion']
@@ -2092,7 +2092,7 @@ class SharedLibrary(BuildTarget):
if isinstance(rust_crate_type, str):
self.rust_crate_type = rust_crate_type
else:
- raise InvalidArguments('Invalid rust_crate_type "{0}": must be a string.'.format(rust_crate_type))
+ raise InvalidArguments('Invalid rust_crate_type "{}": must be a string.'.format(rust_crate_type))
def get_import_filename(self):
"""
@@ -2199,7 +2199,7 @@ class CommandBase:
return final_cmd
class CustomTarget(Target, CommandBase):
- known_kwargs = set([
+ known_kwargs = {
'input',
'output',
'command',
@@ -2216,7 +2216,7 @@ class CustomTarget(Target, CommandBase):
'override_options',
'console',
'env',
- ])
+ }
def __init__(self, name: str, subdir: str, subproject: str, kwargs: T.Dict[str, T.Any],
absolute_paths: bool = False, backend: T.Optional['Backend'] = None):
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index a37e4da..56c97f4 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -762,7 +762,7 @@ class Compiler(metaclass=abc.ABCMeta):
contents = code
elif isinstance(code, mesonlib.File):
srcname = code.fname
- with open(code.fname, 'r') as f:
+ with open(code.fname) as f:
contents = f.read()
# Construct the compiler command-line
@@ -1009,16 +1009,16 @@ class Compiler(metaclass=abc.ABCMeta):
return []
def get_crt_compile_args(self, crt_val: str, buildtype: str) -> T.List[str]:
- raise EnvironmentError('This compiler does not support Windows CRT selection')
+ raise OSError('This compiler does not support Windows CRT selection')
def get_crt_link_args(self, crt_val: str, buildtype: str) -> T.List[str]:
- raise EnvironmentError('This compiler does not support Windows CRT selection')
+ raise OSError('This compiler does not support Windows CRT selection')
def get_compile_only_args(self) -> T.List[str]:
return []
def get_preprocess_only_args(self) -> T.List[str]:
- raise EnvironmentError('This compiler does not have a preprocessor')
+ raise OSError('This compiler does not have a preprocessor')
def get_default_include_dirs(self) -> T.List[str]:
return []
@@ -1095,7 +1095,7 @@ class Compiler(metaclass=abc.ABCMeta):
return objfile + '.' + self.get_depfile_suffix()
def get_depfile_suffix(self) -> str:
- raise EnvironmentError('{} does not implement get_depfile_suffix'.format(self.id))
+ raise OSError('{} does not implement get_depfile_suffix'.format(self.id))
def get_no_stdinc_args(self) -> T.List[str]:
"""Arguments to turn off default inclusion of standard libraries."""
@@ -1112,13 +1112,13 @@ class Compiler(metaclass=abc.ABCMeta):
pass
def get_module_incdir_args(self) -> T.Tuple[str, ...]:
- raise EnvironmentError('{} does not implement get_module_incdir_args'.format(self.id))
+ raise OSError('{} does not implement get_module_incdir_args'.format(self.id))
def get_module_outdir_args(self, path: str) -> T.List[str]:
- raise EnvironmentError('{} does not implement get_module_outdir_args'.format(self.id))
+ raise OSError('{} does not implement get_module_outdir_args'.format(self.id))
def module_name_to_filename(self, module_name: str) -> str:
- raise EnvironmentError('{} does not implement module_name_to_filename'.format(self.id))
+ raise OSError('{} does not implement module_name_to_filename'.format(self.id))
def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]:
"""Arguments to pass the compiler and/or linker for checks.
@@ -1212,7 +1212,7 @@ class Compiler(metaclass=abc.ABCMeta):
def get_feature_args(self, kwargs: T.Dict[str, T.Any], build_to_src: str) -> T.List[str]:
"""Used by D for extra language features."""
# TODO: using a TypeDict here would improve this
- raise EnvironmentError('{} does not implement get_feature_args'.format(self.id))
+ raise OSError('{} does not implement get_feature_args'.format(self.id))
def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.List[str]:
raise EnvironmentException('{} does not know how to do prelinking.'.format(self.id))
diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py
index 733e362..a55975a 100644
--- a/mesonbuild/compilers/cuda.py
+++ b/mesonbuild/compilers/cuda.py
@@ -514,7 +514,7 @@ class CudaCompiler(Compiler):
mlog.debug(stde)
mlog.debug('-----')
if pc.returncode != 0:
- raise EnvironmentException('Compiler {0} can not compile programs.'.format(self.name_string()))
+ raise EnvironmentException('Compiler {} can not compile programs.'.format(self.name_string()))
# Run sanity check (if possible)
if self.is_cross:
@@ -533,7 +533,7 @@ class CudaCompiler(Compiler):
mlog.debug('-----')
pe.wait()
if pe.returncode != 0:
- raise EnvironmentException('Executables created by {0} compiler {1} are not runnable.'.format(self.language, self.name_string()))
+ raise EnvironmentException('Executables created by {} compiler {} are not runnable.'.format(self.language, self.name_string()))
# Interpret the result of the sanity test.
# As mentioned above, it is not only a sanity test but also a GPU
diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py
index ef261fd..b16aca8 100644
--- a/mesonbuild/compilers/d.py
+++ b/mesonbuild/compilers/d.py
@@ -183,10 +183,10 @@ class DmdLikeCompilerMixin(CompilerMixinBase):
if int(d) > debug_level:
debug_level = int(d)
else:
- res.append('{0}={1}'.format(debug_arg, d))
+ res.append('{}={}'.format(debug_arg, d))
if debug_level >= 0:
- res.append('{0}={1}'.format(debug_arg, debug_level))
+ res.append('{}={}'.format(debug_arg, debug_level))
if 'versions' in kwargs:
version_level = -1
@@ -207,10 +207,10 @@ class DmdLikeCompilerMixin(CompilerMixinBase):
if int(v) > version_level:
version_level = int(v)
else:
- res.append('{0}={1}'.format(version_arg, v))
+ res.append('{}={}'.format(version_arg, v))
if version_level >= 0:
- res.append('{0}={1}'.format(version_arg, version_level))
+ res.append('{}={}'.format(version_arg, version_level))
if 'import_dirs' in kwargs:
import_dirs = kwargs.pop('import_dirs')
@@ -230,8 +230,8 @@ class DmdLikeCompilerMixin(CompilerMixinBase):
else:
expdir = basedir
srctreedir = os.path.join(build_to_src, expdir)
- res.append('{0}{1}'.format(import_dir_arg, srctreedir))
- res.append('{0}{1}'.format(import_dir_arg, bldtreedir))
+ res.append('{}{}'.format(import_dir_arg, srctreedir))
+ res.append('{}{}'.format(import_dir_arg, bldtreedir))
if kwargs:
raise EnvironmentException('Unknown D compiler feature(s) selected: %s' % ', '.join(kwargs.keys()))
@@ -560,10 +560,10 @@ class DCompiler(Compiler):
if int(d) > debug_level:
debug_level = int(d)
else:
- res.append('{0}={1}'.format(debug_arg, d))
+ res.append('{}={}'.format(debug_arg, d))
if debug_level >= 0:
- res.append('{0}={1}'.format(debug_arg, debug_level))
+ res.append('{}={}'.format(debug_arg, debug_level))
if 'versions' in kwargs:
version_level = -1
@@ -584,10 +584,10 @@ class DCompiler(Compiler):
if int(v) > version_level:
version_level = int(v)
else:
- res.append('{0}={1}'.format(version_arg, v))
+ res.append('{}={}'.format(version_arg, v))
if version_level >= 0:
- res.append('{0}={1}'.format(version_arg, version_level))
+ res.append('{}={}'.format(version_arg, version_level))
if 'import_dirs' in kwargs:
import_dirs = kwargs.pop('import_dirs')
@@ -607,8 +607,8 @@ class DCompiler(Compiler):
else:
expdir = basedir
srctreedir = os.path.join(build_to_src, expdir)
- res.append('{0}{1}'.format(import_dir_arg, srctreedir))
- res.append('{0}{1}'.format(import_dir_arg, bldtreedir))
+ res.append('{}{}'.format(import_dir_arg, srctreedir))
+ res.append('{}{}'.format(import_dir_arg, bldtreedir))
if kwargs:
raise EnvironmentException('Unknown D compiler feature(s) selected: %s' % ', '.join(kwargs.keys()))
diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py
index ad3bfae..ad0e257 100644
--- a/mesonbuild/compilers/mixins/clike.py
+++ b/mesonbuild/compilers/mixins/clike.py
@@ -321,7 +321,7 @@ class CLikeCompiler(Compiler):
mlog.debug(stde)
mlog.debug('-----')
if pc.returncode != 0:
- raise mesonlib.EnvironmentException('Compiler {0} can not compile programs.'.format(self.name_string()))
+ raise mesonlib.EnvironmentException('Compiler {} can not compile programs.'.format(self.name_string()))
# Run sanity check
if self.is_cross:
if self.exe_wrapper is None:
@@ -337,7 +337,7 @@ class CLikeCompiler(Compiler):
raise mesonlib.EnvironmentException('Could not invoke sanity test executable: %s.' % str(e))
pe.wait()
if pe.returncode != 0:
- raise mesonlib.EnvironmentException('Executables created by {0} compiler {1} are not runnable.'.format(self.language, self.name_string()))
+ raise mesonlib.EnvironmentException('Executables created by {} compiler {} are not runnable.'.format(self.language, self.name_string()))
def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
code = 'int main(void) { int class=0; return class; }\n'
@@ -810,7 +810,7 @@ class CLikeCompiler(Compiler):
if val is not None:
if isinstance(val, bool):
return val, False
- raise mesonlib.EnvironmentException('Cross variable {0} is not a boolean.'.format(varname))
+ raise mesonlib.EnvironmentException('Cross variable {} is not a boolean.'.format(varname))
# TODO: we really need a protocol for this,
#
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 3d74139..99646ca 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -235,7 +235,7 @@ class UserArrayOption(UserOption[T.List[str]]):
mlog.deprecation(msg)
for i in newvalue:
if not isinstance(i, str):
- raise MesonException('String array element "{0}" is not a string.'.format(str(newvalue)))
+ raise MesonException('String array element "{}" is not a string.'.format(str(newvalue)))
if self.choices:
bad = [x for x in newvalue if x not in self.choices]
if bad:
@@ -434,7 +434,7 @@ class CoreData:
# the contents of that file into the meson private (scratch)
# directory so that it can be re-read when wiping/reconfiguring
copy = os.path.join(scratch_dir, '{}.{}.ini'.format(uuid.uuid4(), ftype))
- with open(f, 'r') as rf:
+ with open(f) as rf:
with open(copy, 'w') as wf:
wf.write(rf.read())
real.append(copy)
diff --git a/mesonbuild/dependencies/cuda.py b/mesonbuild/dependencies/cuda.py
index 20f6569..6d17b90 100644
--- a/mesonbuild/dependencies/cuda.py
+++ b/mesonbuild/dependencies/cuda.py
@@ -130,7 +130,7 @@ class CudaDependency(ExternalDependency):
def _default_path_env_var(self):
env_vars = ['CUDA_PATH'] if self._is_windows() else ['CUDA_PATH', 'CUDA_HOME', 'CUDA_ROOT']
env_vars = [var for var in env_vars if var in os.environ]
- user_defaults = set([os.environ[var] for var in env_vars])
+ user_defaults = {os.environ[var] for var in env_vars}
if len(user_defaults) > 1:
mlog.warning('Environment variables {} point to conflicting toolkit locations ({}). Toolkit selection might produce unexpected results.'.format(', '.join(env_vars), ', '.join(user_defaults)))
return env_vars[0] if env_vars else None
diff --git a/mesonbuild/dependencies/hdf5.py b/mesonbuild/dependencies/hdf5.py
index 5ac60bb..7c35a02 100644
--- a/mesonbuild/dependencies/hdf5.py
+++ b/mesonbuild/dependencies/hdf5.py
@@ -167,7 +167,7 @@ def hdf5_factory(env: 'Environment', for_machine: 'MachineChoice',
universal_newlines=True)
if ret.returncode == 0:
for pkg in ret.stdout.split('\n'):
- if pkg.startswith(('hdf5')):
+ if pkg.startswith('hdf5'):
pkgconfig_files.add(pkg.split(' ', 1)[0])
for pkg in pkgconfig_files:
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 756dd81..4d9d592 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -1020,7 +1020,7 @@ class Environment:
if exceptions:
errmsg += '\nThe following exception(s) were encountered:'
for (c, e) in exceptions.items():
- errmsg += '\nRunning "{0}" gave "{1}"'.format(c, e)
+ errmsg += '\nRunning "{}" gave "{}"'.format(c, e)
raise EnvironmentException(errmsg)
@staticmethod
@@ -1208,7 +1208,7 @@ class Environment:
compiler = [compiler]
compiler_name = os.path.basename(compiler[0])
- if not set(['cl', 'cl.exe', 'clang-cl', 'clang-cl.exe']).isdisjoint(compiler):
+ if not {'cl', 'cl.exe', 'clang-cl', 'clang-cl.exe'}.isdisjoint(compiler):
# Watcom C provides it's own cl.exe clone that mimics an older
# version of Microsoft's compiler. Since Watcom's cl.exe is
# just a wrapper, we skip using it if we detect its presence
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 2cc4f44..1a861fb 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1039,25 +1039,25 @@ class SubprojectHolder(InterpreterObject, ObjectHolder[T.Optional['Interpreter']
if len(args) == 2:
return args[1]
- raise InvalidArguments('Requested variable "{0}" not found.'.format(varname))
+ raise InvalidArguments('Requested variable "{}" not found.'.format(varname))
-header_permitted_kwargs = set([
+header_permitted_kwargs = {
'required',
'prefix',
'no_builtin_args',
'include_directories',
'args',
'dependencies',
-])
+}
-find_library_permitted_kwargs = set([
+find_library_permitted_kwargs = {
'has_headers',
'required',
'dirs',
'static',
-])
+}
-find_library_permitted_kwargs |= set(['header_' + k for k in header_permitted_kwargs])
+find_library_permitted_kwargs |= {'header_' + k for k in header_permitted_kwargs}
class CompilerHolder(InterpreterObject):
def __init__(self, compiler: 'Compiler', env: 'Environment', subproject: str):
@@ -1585,7 +1585,7 @@ class CompilerHolder(InterpreterObject):
raise InterpreterException('Prefix argument of has_header_symbol must be a string.')
disabled, required, feature = extract_required_kwarg(kwargs, self.subproject, default=False)
if disabled:
- mlog.log('Header <{0}> has symbol'.format(hname), mlog.bold(symbol, True), 'skipped: feature', mlog.bold(feature), 'disabled')
+ mlog.log('Header <{}> has symbol'.format(hname), mlog.bold(symbol, True), 'skipped: feature', mlog.bold(feature), 'disabled')
return False
extra_args = functools.partial(self.determine_args, kwargs)
deps, msg = self.determine_dependencies(kwargs)
@@ -1599,7 +1599,7 @@ class CompilerHolder(InterpreterObject):
else:
h = mlog.red('NO')
cached = mlog.blue('(cached)') if cached else ''
- mlog.log('Header <{0}> has symbol'.format(hname), mlog.bold(symbol, True), msg, h, cached)
+ mlog.log('Header <{}> has symbol'.format(hname), mlog.bold(symbol, True), msg, h, cached)
return haz
def notfound_library(self, libname):
@@ -4346,7 +4346,7 @@ This will become a hard error in the future.''' % kwargs['input'], location=self
def func_configure_file(self, node, args, kwargs):
if 'output' not in kwargs:
raise InterpreterException('Required keyword argument "output" not defined.')
- actions = set(['configuration', 'command', 'copy']).intersection(kwargs.keys())
+ actions = {'configuration', 'command', 'copy'}.intersection(kwargs.keys())
if len(actions) == 0:
raise InterpreterException('Must specify an action with one of these '
'keyword arguments: \'configuration\', '
@@ -4483,7 +4483,7 @@ This will become a hard error in the future.''' % kwargs['input'], location=self
mesonlib.replace_if_different(ofile_abs, dst_tmp)
if depfile:
mlog.log('Reading depfile:', mlog.bold(depfile))
- with open(depfile, 'r') as f:
+ with open(depfile) as f:
df = DepFile(f.readlines())
deps = df.get_all_dependencies(ofile_fname)
for dep in deps:
diff --git a/mesonbuild/linkers.py b/mesonbuild/linkers.py
index d8d2e65..f4c6dca 100644
--- a/mesonbuild/linkers.py
+++ b/mesonbuild/linkers.py
@@ -838,7 +838,7 @@ class CcrxDynamicLinker(DynamicLinker):
return ['-output={}'.format(outputname)]
def get_search_args(self, dirname: str) -> 'T.NoReturn':
- raise EnvironmentError('rlink.exe does not have a search dir argument')
+ raise OSError('rlink.exe does not have a search dir argument')
def get_allow_undefined_args(self) -> T.List[str]:
return []
@@ -878,7 +878,7 @@ class Xc16DynamicLinker(DynamicLinker):
return ['-o{}'.format(outputname)]
def get_search_args(self, dirname: str) -> 'T.NoReturn':
- raise EnvironmentError('xc16-gcc.exe does not have a search dir argument')
+ raise OSError('xc16-gcc.exe does not have a search dir argument')
def get_allow_undefined_args(self) -> T.List[str]:
return []
@@ -966,7 +966,7 @@ class C2000DynamicLinker(DynamicLinker):
return ['-z', '--output_file={}'.format(outputname)]
def get_search_args(self, dirname: str) -> 'T.NoReturn':
- raise EnvironmentError('cl2000.exe does not have a search dir argument')
+ raise OSError('cl2000.exe does not have a search dir argument')
def get_allow_undefined_args(self) -> T.List[str]:
return []
diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py
index 9b2f5b6..13530ec 100644
--- a/mesonbuild/mconf.py
+++ b/mesonbuild/mconf.py
@@ -123,7 +123,7 @@ class Conf:
def add_option(self, name, descr, value, choices):
if isinstance(value, list):
- value = '[{0}]'.format(', '.join(make_lower_case(value)))
+ value = '[{}]'.format(', '.join(make_lower_case(value)))
else:
value = make_lower_case(value)
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
index 9d8682c..f4b8e0b 100644
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -394,7 +394,7 @@ def get_info_file(infodir: str, kind: T.Optional[str] = None) -> str:
'meson-info.json' if not kind else 'intro-{}.json'.format(kind))
def load_info_file(infodir: str, kind: T.Optional[str] = None) -> T.Any:
- with open(get_info_file(infodir, kind), 'r') as fp:
+ with open(get_info_file(infodir, kind)) as fp:
return json.load(fp)
def run(options: argparse.Namespace) -> int:
diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py
index 20794df..dbc48a1 100644
--- a/mesonbuild/mlog.py
+++ b/mesonbuild/mlog.py
@@ -142,10 +142,10 @@ class AnsiText:
self.args = args
def __len__(self) -> int:
- return sum((len(x) for x in self.args))
+ return sum(len(x) for x in self.args)
def __str__(self) -> str:
- return ''.join((str(x) for x in self.args))
+ return ''.join(str(x) for x in self.args)
def bold(text: str, quoted: bool = False) -> AnsiDecorator:
diff --git a/mesonbuild/modules/cmake.py b/mesonbuild/modules/cmake.py
index dc45e71..18dc2f5 100644
--- a/mesonbuild/modules/cmake.py
+++ b/mesonbuild/modules/cmake.py
@@ -235,7 +235,7 @@ class CmakeModule(ExtensionModule):
cmakebin = dependencies.ExternalProgram('cmake', silent=False)
p, stdout, stderr = mesonlib.Popen_safe(cmakebin.get_command() + ['--system-information', '-G', 'Ninja'])[0:3]
if p.returncode != 0:
- mlog.log('error retrieving cmake information: returnCode={0} stdout={1} stderr={2}'.format(p.returncode, stdout, stderr))
+ mlog.log('error retrieving cmake information: returnCode={} stdout={} stderr={}'.format(p.returncode, stdout, stderr))
return False
match = re.search('\nCMAKE_ROOT \\"([^"]+)"\n', stdout.strip())
@@ -295,7 +295,7 @@ class CmakeModule(ExtensionModule):
package_init += PACKAGE_INIT_SET_AND_CHECK
try:
- with open(infile, "r") as fin:
+ with open(infile) as fin:
data = fin.readlines()
except Exception as e:
raise mesonlib.MesonException('Could not read input file %s: %s' % (infile, str(e)))
diff --git a/mesonbuild/modules/dlang.py b/mesonbuild/modules/dlang.py
index d4f62e4..55ff304 100644
--- a/mesonbuild/modules/dlang.py
+++ b/mesonbuild/modules/dlang.py
@@ -70,7 +70,7 @@ class DlangModule(ExtensionModule):
config_path = os.path.join(args[1], 'dub.json')
if os.path.exists(config_path):
- with open(config_path, 'r', encoding='utf8') as ofile:
+ with open(config_path, encoding='utf8') as ofile:
try:
config = json.load(ofile)
except ValueError:
diff --git a/mesonbuild/modules/fs.py b/mesonbuild/modules/fs.py
index 7de8cf7..fd1e99b 100644
--- a/mesonbuild/modules/fs.py
+++ b/mesonbuild/modules/fs.py
@@ -211,7 +211,7 @@ class FSModule(ExtensionModule):
if path_is_in_root(Path(path), Path(build_dir), resolve=True):
raise MesonException('path must not be in the build tree')
try:
- with open(path, 'r', encoding=encoding) as f:
+ with open(path, encoding=encoding) as f:
data = f.read()
except UnicodeDecodeError:
raise MesonException(f'decoding failed for {path}')
diff --git a/mesonbuild/modules/keyval.py b/mesonbuild/modules/keyval.py
index 3da2992..8e1a89f 100644
--- a/mesonbuild/modules/keyval.py
+++ b/mesonbuild/modules/keyval.py
@@ -42,7 +42,7 @@ class KeyvalModule(ExtensionModule):
except ValueError:
continue
result[name.strip()] = val.strip()
- except IOError as e:
+ except OSError as e:
raise mesonlib.MesonException('Failed to load {}: {}'.format(path_to_config, e))
return result
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
index cfe2244..d05c72a 100644
--- a/mesonbuild/modules/python.py
+++ b/mesonbuild/modules/python.py
@@ -36,9 +36,9 @@ from ..dependencies.base import (
NonExistingExternalProgram, NotFoundDependency
)
-mod_kwargs = set(['subdir'])
+mod_kwargs = {'subdir'}
mod_kwargs.update(known_shmod_kwargs)
-mod_kwargs -= set(['name_prefix', 'name_suffix'])
+mod_kwargs -= {'name_prefix', 'name_suffix'}
class PythonDependency(ExternalDependency):
@@ -544,7 +544,7 @@ class PythonModule(ExtensionModule):
for mod in want_modules:
p, out, err = mesonlib.Popen_safe(
python.command +
- ['-c', 'import {0}'.format(mod)])
+ ['-c', 'import {}'.format(mod)])
if p.returncode != 0:
missing_modules.append(mod)
else:
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py
index af5ad6d..ac4f515 100644
--- a/mesonbuild/mtest.py
+++ b/mesonbuild/mtest.py
@@ -902,8 +902,8 @@ class TestRun:
return returncode_to_status(self.returncode)
if self.results:
# running or succeeded
- passed = sum((x.result.is_ok() for x in self.results))
- ran = sum((x.result is not TestResult.SKIP for x in self.results))
+ passed = sum(x.result.is_ok() for x in self.results)
+ ran = sum(x.result is not TestResult.SKIP for x in self.results)
if passed == ran:
return '{} subtests passed'.format(passed)
else:
@@ -928,7 +928,7 @@ class TestRun:
return None
test_only_env = set(self.env.items()) - set(os.environ.items())
return env_tuple_to_str(test_only_env) + \
- ' '.join((sh_quote(x) for x in self.cmd))
+ ' '.join(sh_quote(x) for x in self.cmd)
def complete_skip(self, message: str) -> None:
self.starttime = time.time()
@@ -1634,13 +1634,13 @@ class TestHarness:
os.chdir(self.options.wd)
runners = [] # type: T.List[SingleTestRunner]
for i in range(self.options.repeat):
- runners.extend((self.get_test_runner(test) for test in tests))
+ runners.extend(self.get_test_runner(test) for test in tests)
if i == 0:
self.duration_max_len = max([len(str(int(runner.timeout or 99)))
for runner in runners])
# Disable the progress report if it gets in the way
- self.need_console = any((runner.console_mode is not ConsoleUser.LOGGER
- for runner in runners))
+ self.need_console = any(runner.console_mode is not ConsoleUser.LOGGER
+ for runner in runners)
self.test_count = len(runners)
self.run_tests(runners)
diff --git a/mesonbuild/optinterpreter.py b/mesonbuild/optinterpreter.py
index dc8c3ce..6043691 100644
--- a/mesonbuild/optinterpreter.py
+++ b/mesonbuild/optinterpreter.py
@@ -142,7 +142,7 @@ class OptionInterpreter:
def process(self, option_file: str) -> None:
try:
- with open(option_file, 'r', encoding='utf8') as f:
+ with open(option_file, encoding='utf8') as f:
ast = mparser.Parser(f.read(), option_file).parse()
except mesonlib.MesonException as me:
me.file = option_file
diff --git a/mesonbuild/rewriter.py b/mesonbuild/rewriter.py
index 9cd9ad0..8585833 100644
--- a/mesonbuild/rewriter.py
+++ b/mesonbuild/rewriter.py
@@ -820,7 +820,7 @@ class Rewriter:
if not os.path.exists(fpath):
with open(fpath, 'w'):
pass
- with open(fpath, 'r') as fp:
+ with open(fpath) as fp:
fdata = fp.read()
# Generate line offsets numbers
@@ -923,7 +923,7 @@ def generate_def_opts(options) -> T.List[dict]:
def generate_cmd(options) -> T.List[dict]:
if os.path.exists(options.json):
- with open(options.json, 'r') as fp:
+ with open(options.json) as fp:
return json.load(fp)
else:
return json.loads(options.json)
diff --git a/mesonbuild/scripts/meson_exe.py b/mesonbuild/scripts/meson_exe.py
index 27db144..d44280f 100644
--- a/mesonbuild/scripts/meson_exe.py
+++ b/mesonbuild/scripts/meson_exe.py
@@ -82,7 +82,7 @@ def run_exe(exe: ExecutableSerialisation, extra_env: T.Optional[dict] = None) ->
try:
with open(exe.capture, 'rb') as cur:
skip_write = cur.read() == stdout
- except IOError:
+ except OSError:
pass
if not skip_write:
with open(exe.capture, 'wb') as output:
diff --git a/mesonbuild/scripts/symbolextractor.py b/mesonbuild/scripts/symbolextractor.py
index 30065cc..e80d9c2fac 100644
--- a/mesonbuild/scripts/symbolextractor.py
+++ b/mesonbuild/scripts/symbolextractor.py
@@ -43,7 +43,7 @@ def dummy_syms(outfilename: str) -> None:
def write_if_changed(text: str, outfilename: str) -> None:
try:
- with open(outfilename, 'r') as f:
+ with open(outfilename) as f:
oldtext = f.read()
if text == oldtext:
return
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py
index 7ec8b50..ca201de 100644
--- a/mesonbuild/wrap/wrap.py
+++ b/mesonbuild/wrap/wrap.py
@@ -442,7 +442,7 @@ class Resolver:
def is_git_full_commit_id(self, revno: str) -> bool:
result = False
if len(revno) in (40, 64): # 40 for sha1, 64 for upcoming sha256
- result = all((ch in '0123456789AaBbCcDdEeFf' for ch in revno))
+ result = all(ch in '0123456789AaBbCcDdEeFf' for ch in revno)
return result
def get_hg(self) -> None: