diff --git a/mesonbuild/arglist.py b/mesonbuild/arglist.py index 54d7157e2ccf..085c8a0379a4 100644 --- a/mesonbuild/arglist.py +++ b/mesonbuild/arglist.py @@ -257,7 +257,7 @@ def extend_preserving_lflags(self, iterable: T.Iterable[str]) -> None: normal_flags = [] lflags = [] for i in iterable: - if i not in self.always_dedup_args and (i.startswith('-l') or i.startswith('-L')): + if i not in self.always_dedup_args and (i.startswith(('-l', '-L'))): lflags.append(i) else: normal_flags.append(i) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 65f6ea1958af..670539e5aeb4 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1470,7 +1470,7 @@ def generate_cs_resource_tasks(self, target): rel_sourcefile = os.path.join(self.build_to_src, target.subdir, r) if r.endswith('.resources'): a = '-resource:' + rel_sourcefile - elif r.endswith('.txt') or r.endswith('.resx'): + elif r.endswith(('.txt', '.resx')): ofilebase = os.path.splitext(os.path.basename(r))[0] + '.resources' ofilename = os.path.join(self.get_target_private_dir(target), ofilebase) elem = NinjaBuildElement(self.all_outputs, ofilename, "CUSTOM_COMMAND", rel_sourcefile) diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index a12963cdee06..058987aec1f2 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -947,7 +947,7 @@ def split_link_args(args): other.append(arg) # It's ok if we miss libraries with non-standard extensions here. # They will go into the general link arguments. - elif arg.endswith('.lib') or arg.endswith('.a'): + elif arg.endswith(('.lib', '.a')): # De-dup if arg not in libs: libs.append(arg) diff --git a/mesonbuild/backend/xcodebackend.py b/mesonbuild/backend/xcodebackend.py index 5a0e77bd0f43..24ca814e6512 100644 --- a/mesonbuild/backend/xcodebackend.py +++ b/mesonbuild/backend/xcodebackend.py @@ -1658,7 +1658,7 @@ def generate_single_build_target(self, objects_dict, target_name, target) -> Non outputs = self.generator_outputs[target_name, generator_id] generator_id += 1 for o_abs in outputs: - if o_abs.endswith('.o') or o_abs.endswith('.obj'): + if o_abs.endswith(('.o', '.obj')): ldargs += [r'\"' + o_abs + r'\"'] else: if isinstance(o, build.CustomTarget): @@ -1750,7 +1750,7 @@ def generate_single_build_target(self, objects_dict, target_name, target) -> Non # file. Since Xcode itself already discourages precompiled headers in favor of modules we don't try much harder here. pchs = target.get_pch('c') + target.get_pch('cpp') + target.get_pch('objc') + target.get_pch('objcpp') # Make sure to use headers (other backends require implementation files like *.c *.cpp, etc; these should not be used here) - pchs = [pch for pch in pchs if pch.endswith('.h') or pch.endswith('.hh') or pch.endswith('hpp')] + pchs = [pch for pch in pchs if pch.endswith(('.h', '.hh', 'hpp'))] if pchs: if len(pchs) > 1: mlog.warning(f'Unsupported Xcode configuration: More than 1 precompiled header found "{pchs!s}". Target "{target.name}" might not compile correctly.') diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index d8b252a94668..036b5191e8d1 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -301,7 +301,7 @@ def _translate_args_to_nongnu(cls, args: T.List[str], info: MachineInfo, link_id if suffix in link_flags_with_arg: link_expect_arg = True - if suffix.startswith('-') or suffix.startswith('@'): + if suffix.startswith(('-', '@')): # this is not search path dcargs.append(arg) continue @@ -312,7 +312,7 @@ def _translate_args_to_nongnu(cls, args: T.List[str], info: MachineInfo, link_id continue # Make sure static library files are passed properly to the linker. - if arg.endswith('.a') or arg.endswith('.lib'): + if arg.endswith(('.a', '.lib')): if len(suffix) > 0 and not suffix.startswith('-'): dcargs.append('-L=' + suffix) continue diff --git a/mesonbuild/compilers/mixins/visualstudio.py b/mesonbuild/compilers/mixins/visualstudio.py index 4ec22a0f28d0..42b2aa1c88da 100644 --- a/mesonbuild/compilers/mixins/visualstudio.py +++ b/mesonbuild/compilers/mixins/visualstudio.py @@ -253,9 +253,7 @@ def unix_args_to_native(cls, args: T.List[str]) -> T.List[str]: continue # cl.exe does not allow specifying both, so remove /utf-8 that we # added automatically in the case the user overrides it manually. - elif (i.startswith('/source-charset:') - or i.startswith('/execution-charset:') - or i == '/validate-charset-'): + elif (i.startswith(('/source-charset:', '/execution-charset:')) or i == '/validate-charset-'): try: result.remove('/utf-8') except ValueError: diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 83e83e728727..cefb56a1aae4 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -359,7 +359,7 @@ def sanitize_prefix(self, prefix: str) -> str: prefix = os.path.expanduser(prefix) if not os.path.isabs(prefix): raise MesonException(f'prefix value {prefix!r} must be an absolute path') - if prefix.endswith('/') or prefix.endswith('\\'): + if prefix.endswith(('/', '\\')): # On Windows we need to preserve the trailing slash if the # string is of type 'C:\' because 'C:' is not an absolute path. if len(prefix) == 3 and prefix[1] == ':': diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 08e81f0d79d5..d745d0194fd5 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -141,7 +141,7 @@ def get_compile_args(self) -> T.List[str]: if self.include_type == 'system': converted = [] for i in self.compile_args: - if i.startswith('-I') or i.startswith('/I'): + if i.startswith(('-I', '/I')): converted += ['-isystem' + i[2:]] else: converted += [i] diff --git a/mesonbuild/dependencies/cmake.py b/mesonbuild/dependencies/cmake.py index 61963b0aa060..fe737ad05e5c 100644 --- a/mesonbuild/dependencies/cmake.py +++ b/mesonbuild/dependencies/cmake.py @@ -300,9 +300,9 @@ def search_lib_dirs(path: str) -> bool: # Check PATH system_env: T.List[str] = [] for i in os.environ.get('PATH', '').split(os.pathsep): - if i.endswith('/bin') or i.endswith('\\bin'): + if i.endswith(('/bin', '\\bin')): i = i[:-4] - if i.endswith('/sbin') or i.endswith('\\sbin'): + if i.endswith(('/sbin', '\\sbin')): i = i[:-5] system_env += [i] diff --git a/mesonbuild/dependencies/dub.py b/mesonbuild/dependencies/dub.py index 0d25c31352ec..53dc37ecb089 100644 --- a/mesonbuild/dependencies/dub.py +++ b/mesonbuild/dependencies/dub.py @@ -256,7 +256,7 @@ def find_package_target(pkg: T.Dict[str, str]) -> bool: for file in bs['sourceFiles']: # sourceFiles may contain static libraries - if file.endswith('.lib') or file.endswith('.a'): + if file.endswith(('.lib', '.a')): self.link_args.append(file) for flag in bs['lflags']: diff --git a/mesonbuild/dependencies/qt.py b/mesonbuild/dependencies/qt.py index 1b60deb8afd2..b3f4e17b7270 100644 --- a/mesonbuild/dependencies/qt.py +++ b/mesonbuild/dependencies/qt.py @@ -208,7 +208,7 @@ def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]): debug_lib_name = self.qtpkgname + 'Core' + _get_modules_lib_suffix(self.version, self.env.machines[self.for_machine], True) is_debug = False for arg in self.get_link_args(): - if arg == f'-l{debug_lib_name}' or arg.endswith(f'{debug_lib_name}.lib') or arg.endswith(f'{debug_lib_name}.a'): + if arg == f'-l{debug_lib_name}' or arg.endswith((f'{debug_lib_name}.lib', f'{debug_lib_name}.a')): is_debug = True break libdir = self.get_variable(pkgconfig='libdir') diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index cc17377a649b..189844bd7fc3 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -98,11 +98,7 @@ def filter_args(args: T.List[str]) -> T.List[str]: """ result = [] for f in args: - if f.startswith('-D') \ - or f.startswith('-f') \ - or f.startswith('-I') \ - or f == '-pthread' \ - or (f.startswith('-W') and not f == '-Wall'): + if f.startswith(('-D', '-f', '-I')) or f == '-pthread' or f.startswith('-W') and not f == '-Wall': result.append(f) return result diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index c26516215b6b..04826b23daf4 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -345,7 +345,7 @@ def detect_cpu_family(compilers: CompilersDict) -> str: elif trial.startswith('aarch64'): # This can be `aarch64_be` trial = 'aarch64' - elif trial.startswith('arm') or trial.startswith('earm'): + elif trial.startswith(('arm', 'earm')): trial = 'arm' elif trial.startswith(('powerpc64', 'ppc64')): trial = 'ppc64' @@ -409,7 +409,7 @@ def detect_cpu(compilers: CompilersDict) -> str: # Same check as above for cpu_family if any_compiler_has_define(compilers, '__i386__'): trial = 'i686' # All 64 bit cpus have at least this level of x86 support. - elif trial.startswith('aarch64') or trial.startswith('arm64'): + elif trial.startswith(('aarch64', 'arm64')): # Same check as above for cpu_family if any_compiler_has_define(compilers, '__arm__'): trial = 'arm' diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 95d85ac07ebf..8bb18f9b2180 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -2963,7 +2963,7 @@ def _warn_about_builtin_args(self, args: T.List[str]) -> None: elif arg in {'-fsanitize', '/fsanitize'} or arg.startswith(('-fsanitize=', '/fsanitize=')): mlog.warning(f'Consider using the built-in option for sanitizers instead of using "{arg}".', location=self.current_node) - elif arg.startswith('-std=') or arg.startswith('/std:'): + elif arg.startswith(('-std=', '/std:')): mlog.warning(f'Consider using the built-in option for language standard version instead of using "{arg}".', location=self.current_node) diff --git a/mesonbuild/minstall.py b/mesonbuild/minstall.py index e5901c45ae85..c2c69fe45eac 100644 --- a/mesonbuild/minstall.py +++ b/mesonbuild/minstall.py @@ -267,7 +267,7 @@ def check_for_stampfile(fname: str) -> str: whose names are not known at configure time. Check if this is the case and return the real file instead.''' - if fname.endswith('.so') or fname.endswith('.dll'): + if fname.endswith(('.so', '.dll')): if os.stat(fname).st_size == 0: (base, suffix) = os.path.splitext(fname) files = glob(base + '-*' + suffix) @@ -276,7 +276,7 @@ def check_for_stampfile(fname: str) -> str: sys.exit(1) if len(files) == 1: return files[0] - elif fname.endswith('.a') or fname.endswith('.lib'): + elif fname.endswith(('.a', '.lib')): if os.stat(fname).st_size == 0: (base, suffix) = os.path.splitext(fname) files = glob(base + '-*' + '.rlib') diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py index 574bcb51f654..a19264273056 100644 --- a/mesonbuild/utils/universal.py +++ b/mesonbuild/utils/universal.py @@ -371,7 +371,7 @@ def perms_s_to_bits(cls, perms_s: T.Optional[str]) -> int: See https://github.com/mesonbuild/meson/pull/8747 for the discussions.""" class File(HoldableObject): def __init__(self, is_built: bool, subdir: str, fname: str): - if fname.endswith(".C") or fname.endswith(".H"): + if fname.endswith(('.C', '.H')): mlog.warning(dot_C_dot_H_warning, once=True) self.is_built = is_built self.subdir = subdir diff --git a/test cases/common/208 link custom/custom_stlib.py b/test cases/common/208 link custom/custom_stlib.py index 6a090f3db92d..351decdcdedd 100755 --- a/test cases/common/208 link custom/custom_stlib.py +++ b/test cases/common/208 link custom/custom_stlib.py @@ -72,7 +72,7 @@ def generate_lib(outfile, private_dir, compiler_array): c_file = private_dir / 'flob.c' c_file.write_text(contents) for i in compiler_array: - if (i.endswith('cl') or i.endswith('cl.exe')) and 'clang-cl' not in i: + if (i.endswith(('cl', 'cl.exe'))) and 'clang-cl' not in i: return generate_lib_msvc(outfile, c_file, private_dir, compiler_array) return generate_lib_gnulike(outfile, c_file, private_dir, compiler_array) diff --git a/test cases/common/209 link custom_i single from multiple/generate_conflicting_stlibs.py b/test cases/common/209 link custom_i single from multiple/generate_conflicting_stlibs.py index 42d6631ddf2e..0bfc46ddaf2d 100644 --- a/test cases/common/209 link custom_i single from multiple/generate_conflicting_stlibs.py +++ b/test cases/common/209 link custom_i single from multiple/generate_conflicting_stlibs.py @@ -72,7 +72,7 @@ def generate_lib(outfiles, private_dir, compiler_array): cl_found = False for cl_arg in compiler_array: - if (cl_arg.endswith('cl') or cl_arg.endswith('cl.exe')) and 'clang-cl' not in cl_arg: + if (cl_arg.endswith(('cl', 'cl.exe'))) and 'clang-cl' not in cl_arg: ret = generate_lib_msvc(outfile, c_file, private_dir, compiler_array) if ret > 0: return ret diff --git a/test cases/common/210 link custom_i multiple from multiple/generate_stlibs.py b/test cases/common/210 link custom_i multiple from multiple/generate_stlibs.py index 5292006c597d..91571e597a79 100644 --- a/test cases/common/210 link custom_i multiple from multiple/generate_stlibs.py +++ b/test cases/common/210 link custom_i multiple from multiple/generate_stlibs.py @@ -74,7 +74,7 @@ def generate_lib(outfiles, private_dir, compiler_array): cl_found = False for cl_arg in compiler_array: - if (cl_arg.endswith('cl') or cl_arg.endswith('cl.exe')) and 'clang-cl' not in cl_arg: + if (cl_arg.endswith(('cl', 'cl.exe'))) and 'clang-cl' not in cl_arg: ret = generate_lib_msvc(outfile, c_file, private_dir, compiler_array) if ret > 0: return ret