diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py index 34e3e0998..b6ec45012 100644 --- a/mesonbuild/ast/introspection.py +++ b/mesonbuild/ast/introspection.py @@ -173,9 +173,9 @@ class IntrospectionInterpreter(AstInterpreter): arg_node = curr.args elif isinstance(curr, IdNode): # Try to resolve the ID and append the node to the queue - id = curr.value - if id in self.assignments and self.assignments[id]: - tmp_node = self.assignments[id][0] + var_name = curr.value + if var_name in self.assignments and self.assignments[var_name]: + tmp_node = self.assignments[var_name][0] if isinstance(tmp_node, (ArrayNode, IdNode, FunctionNode)): srcqueue += [tmp_node] elif isinstance(curr, ArithmeticNode): diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 9a6fdadac..04838c719 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -406,9 +406,9 @@ int dummy; } } ''' - id = target.get_id() + tid = target.get_id() lang = comp.get_language() - tgt = self.introspection_data[id] + tgt = self.introspection_data[tid] # Find an existing entry or create a new one id_hash = (lang, tuple(parameters)) src_block = tgt.get(id_hash, None) diff --git a/mesonbuild/compilers/cs.py b/mesonbuild/compilers/cs.py index cd67da0a1..c6355f28f 100644 --- a/mesonbuild/compilers/cs.py +++ b/mesonbuild/compilers/cs.py @@ -28,10 +28,10 @@ cs_optimization_args = {'0': [], } class CsCompiler(Compiler): - def __init__(self, exelist, version, id, runner=None): + def __init__(self, exelist, version, comp_id, runner=None): self.language = 'cs' super().__init__(exelist, version) - self.id = id + self.id = comp_id self.is_cross = False self.runner = runner diff --git a/mesonbuild/dependencies/ui.py b/mesonbuild/dependencies/ui.py index ce1ca6834..b473ac8da 100644 --- a/mesonbuild/dependencies/ui.py +++ b/mesonbuild/dependencies/ui.py @@ -298,8 +298,8 @@ class QtBaseDependency(ExternalDependency): # the Qt + m_name there is not a symlink, it's a file mod_private_dir = qt_inc_dir mod_private_inc = _qt_get_private_includes(mod_private_dir, m_name, m.version) - for dir in mod_private_inc: - self.compile_args.append('-I' + dir) + for directory in mod_private_inc: + self.compile_args.append('-I' + directory) self.link_args += m.get_link_args() if 'Core' in modules: @@ -402,8 +402,8 @@ class QtBaseDependency(ExternalDependency): if self.private_headers: priv_inc = self.get_private_includes(mincdir, module) - for dir in priv_inc: - self.compile_args.append('-I' + dir) + for directory in priv_inc: + self.compile_args.append('-I' + directory) libfile = self.clib_compiler.find_library(self.qtpkgname + module + modules_lib_suffix, self.env, libdir) diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index 721994601..d5e60fd1e 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -722,11 +722,11 @@ def has_path_sep(name, sep='/\\'): return True return False -def do_replacement(regex, line, format, confdata): +def do_replacement(regex, line, variable_format, confdata): missing_variables = set() start_tag = '@' backslash_tag = '\\@' - if format == 'cmake': + if variable_format == 'cmake': start_tag = '${' backslash_tag = '\\${' @@ -779,7 +779,7 @@ def do_mesondefine(line, confdata): raise MesonException('#mesondefine argument "%s" is of unknown type.' % varname) -def do_conf_file(src, dst, confdata, format, encoding='utf-8'): +def do_conf_file(src, dst, confdata, variable_format, encoding='utf-8'): try: with open(src, encoding=encoding, newline='') as f: data = f.readlines() @@ -787,15 +787,15 @@ def do_conf_file(src, dst, confdata, format, encoding='utf-8'): raise MesonException('Could not read input file %s: %s' % (src, str(e))) # Only allow (a-z, A-Z, 0-9, _, -) as valid characters for a define # Also allow escaping '@' with '\@' - if format in ['meson', 'cmake@']: + if variable_format in ['meson', 'cmake@']: regex = re.compile(r'(?:\\\\)+(?=\\?@)|\\@|@([-a-zA-Z0-9_]+)@') - elif format == 'cmake': + elif variable_format == 'cmake': regex = re.compile(r'(?:\\\\)+(?=\\?\$)|\\\${|\${([-a-zA-Z0-9_]+)}') else: - raise MesonException('Format "{}" not handled'.format(format)) + raise MesonException('Format "{}" not handled'.format(variable_format)) search_token = '#mesondefine' - if format != 'meson': + if variable_format != 'meson': search_token = '#cmakedefine' result = [] @@ -808,7 +808,7 @@ def do_conf_file(src, dst, confdata, format, encoding='utf-8'): confdata_useless = False line = do_mesondefine(line, confdata) else: - line, missing = do_replacement(regex, line, format, confdata) + line, missing = do_replacement(regex, line, variable_format, confdata) missing_variables.update(missing) if missing: confdata_useless = False diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index 4326c2042..c94f1bf9d 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -41,41 +41,41 @@ class CommandLineParser: self.subparsers = self.parser.add_subparsers(title='Commands', description='If no command is specified it defaults to setup command.') self.add_command('setup', msetup.add_arguments, msetup.run, - help='Configure the project') + help_msg='Configure the project') self.add_command('configure', mconf.add_arguments, mconf.run, - help='Change project options',) + help_msg='Change project options',) self.add_command('install', minstall.add_arguments, minstall.run, - help='Install the project') + help_msg='Install the project') self.add_command('introspect', mintro.add_arguments, mintro.run, - help='Introspect project') + help_msg='Introspect project') self.add_command('init', minit.add_arguments, minit.run, - help='Create a new project') + help_msg='Create a new project') self.add_command('test', mtest.add_arguments, mtest.run, - help='Run tests') + help_msg='Run tests') self.add_command('wrap', wraptool.add_arguments, wraptool.run, - help='Wrap tools') + help_msg='Wrap tools') self.add_command('subprojects', msubprojects.add_arguments, msubprojects.run, - help='Manage subprojects') + help_msg='Manage subprojects') self.add_command('help', self.add_help_arguments, self.run_help_command, - help='Print help of a subcommand') + help_msg='Print help of a subcommand') self.add_command('rewrite', lambda parser: rewriter.add_arguments(parser, self.formater), rewriter.run, - help='Modify the project definition') + help_msg='Modify the project definition') # Hidden commands self.add_command('runpython', self.add_runpython_arguments, self.run_runpython_command, - help=argparse.SUPPRESS) + help_msg=argparse.SUPPRESS) self.add_command('unstable-coredata', munstable_coredata.add_arguments, munstable_coredata.run, - help=argparse.SUPPRESS) + help_msg=argparse.SUPPRESS) - def add_command(self, name, add_arguments_func, run_func, help, aliases=None): + def add_command(self, name, add_arguments_func, run_func, help_msg, aliases=None): aliases = aliases or [] # FIXME: Cannot have hidden subparser: # https://bugs.python.org/issue22848 - if help == argparse.SUPPRESS: + if help_msg == argparse.SUPPRESS: p = argparse.ArgumentParser(prog='meson ' + name, formatter_class=self.formater) self.hidden_commands.append(name) else: - p = self.subparsers.add_parser(name, help=help, aliases=aliases, formatter_class=self.formater) + p = self.subparsers.add_parser(name, help=help_msg, aliases=aliases, formatter_class=self.formater) add_arguments_func(p) p.set_defaults(run_func=run_func) for i in [name] + aliases: diff --git a/mesonbuild/minstall.py b/mesonbuild/minstall.py index 04aba2fa7..ed82c3791 100644 --- a/mesonbuild/minstall.py +++ b/mesonbuild/minstall.py @@ -65,7 +65,7 @@ class DirMaker: def __enter__(self): return self - def __exit__(self, type, value, traceback): + def __exit__(self, exception_type, value, traceback): self.dirs.reverse() for d in self.dirs: append_to_log(self.lf, d) diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index e8ee6c826..21212829a 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -234,14 +234,14 @@ def exception(e: Exception, prefix: AnsiDecorator = red('ERROR:')) -> None: # Format a list for logging purposes as a string. It separates # all but the last item with commas, and the last with 'and'. -def format_list(list_: typing.List[str]) -> str: - l = len(list_) +def format_list(input_list: typing.List[str]) -> str: + l = len(input_list) if l > 2: - return ' and '.join([', '.join(list_[:-1]), list_[-1]]) + return ' and '.join([', '.join(input_list[:-1]), input_list[-1]]) elif l == 2: - return ' and '.join(list_) + return ' and '.join(input_list) elif l == 1: - return list_[0] + return input_list[0] else: return '' diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py index a0ebe0eea..04941eaba 100644 --- a/mesonbuild/modules/python.py +++ b/mesonbuild/modules/python.py @@ -477,9 +477,9 @@ class PythonModule(ExtensionModule): ver = {'python2': '-2', 'python3': '-3'}[name_or_path] cmd = ['py', ver, '-c', "import sysconfig; print(sysconfig.get_config_var('BINDIR'))"] _, stdout, _ = mesonlib.Popen_safe(cmd) - dir = stdout.strip() - if os.path.exists(dir): - return os.path.join(dir, 'python') + directory = stdout.strip() + if os.path.exists(directory): + return os.path.join(directory, 'python') else: return None diff --git a/mesonbuild/modules/windows.py b/mesonbuild/modules/windows.py index e8d266e54..87a83fe26 100644 --- a/mesonbuild/modules/windows.py +++ b/mesonbuild/modules/windows.py @@ -59,7 +59,7 @@ class WindowsModule(ExtensionModule): if not rescomp.found(): raise MesonException('Could not find Windows resource compiler') - for (arg, match, type) in [ + for (arg, match, rc_type) in [ ('/?', '^.*Microsoft.*Resource Compiler.*$', ResourceCompilerType.rc), ('--version', '^.*GNU windres.*$', ResourceCompilerType.windres), ]: @@ -67,7 +67,7 @@ class WindowsModule(ExtensionModule): m = re.search(match, o, re.MULTILINE) if m: mlog.log('Windows resource compiler: %s' % m.group()) - self._rescomp = (rescomp, type) + self._rescomp = (rescomp, rc_type) break else: raise MesonException('Could not determine type of Windows resource compiler') diff --git a/mesonbuild/munstable_coredata.py b/mesonbuild/munstable_coredata.py index aaf652300..795722254 100644 --- a/mesonbuild/munstable_coredata.py +++ b/mesonbuild/munstable_coredata.py @@ -51,7 +51,7 @@ def run(options): 'change the working directory to it.') return 1 - all = options.all + all_backends = options.all print('This is a dump of the internal unstable cache of meson. This is for debugging only.') print('Do NOT parse, this will change from version to version in incompatible ways') @@ -64,18 +64,18 @@ def run(options): # use `meson configure` to view these pass elif k in ['install_guid', 'test_guid', 'regen_guid']: - if all or backend.startswith('vs'): + if all_backends or backend.startswith('vs'): print(k + ': ' + v) elif k == 'target_guids': - if all or backend.startswith('vs'): + if all_backends or backend.startswith('vs'): print(k + ':') dump_guids(v) elif k in ['lang_guids']: - if all or backend.startswith('vs') or backend == 'xcode': + if all_backends or backend.startswith('vs') or backend == 'xcode': print(k + ':') dump_guids(v) elif k == 'meson_command': - if all or backend.startswith('vs'): + if all_backends or backend.startswith('vs'): print('Meson command used in build file regeneration: ' + ' '.join(v)) elif k == 'pkgconf_envvar': print('Last seen PKGCONFIG enviroment variable value: ' + v) diff --git a/run_unittests.py b/run_unittests.py index ab7ad0446..0cc1531db 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -2681,9 +2681,9 @@ int main(int argc, char **argv) { if ninja is None: raise unittest.SkipTest('This test currently requires ninja. Fix this once "meson build" works.') for lang in ('c', 'cpp'): - for type in ('executable', 'library'): + for target_type in ('executable', 'library'): with tempfile.TemporaryDirectory() as tmpdir: - self._run(self.meson_command + ['init', '--language', lang, '--type', type], + self._run(self.meson_command + ['init', '--language', lang, '--type', target_type], workdir=tmpdir) self._run(self.setup_command + ['--backend=ninja', 'builddir'], workdir=tmpdir) diff --git a/setup.cfg b/setup.cfg index 7a94d8535..d81878675 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,4 +28,6 @@ ignore = E722 # W504: line break after binary operator W504 + # A003: builtin class attribute + A003 max-line-length = 120 diff --git a/sideci.yml b/sideci.yml index 38eb811d1..af654574d 100644 --- a/sideci.yml +++ b/sideci.yml @@ -3,3 +3,4 @@ linter: version: 3 plugins: - flake8-blind-except + - flake8-builtins