From patchwork Thu Aug 10 16:31:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1819958 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=hxYyxjgN; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMCDt4yn7z1yfB for ; Fri, 11 Aug 2023 02:34:22 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5EB1D86919; Thu, 10 Aug 2023 18:32:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="hxYyxjgN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8187486902; Thu, 10 Aug 2023 18:32:32 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 446798666E for ; Thu, 10 Aug 2023 18:32:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-1bbafe6fd8fso994452fac.3 for ; Thu, 10 Aug 2023 09:32:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1691685149; x=1692289949; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lFPgYzeE1ag9E33pUJatJqBI5an7VebeKfBFRhmkKHU=; b=hxYyxjgNqX2a0PrKvzdbipiwXj7ypXcJ/wWZoBmrBexI2ht/O40zdXPnMlXSHd1udl cjQDsZcEW2WiVV0OsDSmT8jQMFMKHPMYijTrzeRY+LG2jH1FC5jBrYFMY0JPi08NjhCz RtB3dJfkKnM0jcX1kXyYM6BEF6Qwf42oEsFIY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691685149; x=1692289949; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lFPgYzeE1ag9E33pUJatJqBI5an7VebeKfBFRhmkKHU=; b=BcVmQ8OvPvYiCzazwxyYxZvML006OAO3uFUcIDjyPeW+akhGLLq18kjBpgiYRwgg6a S+lTCjyobK/vc3qvle517FCCN1NmuRUBME6J2HQrtHJgaunH/Ehy8TNDXqjybQ9GmWHD uwX9hjgO39GER5YxKOi6H9b8217sQB1lJ7jqqHbNlhigkfKmbmxPC0wOAhmDC/Rk3fgI F7UKaZsi6ll45zl02LpZqUuP0atOIo7QkXE6LjlJobzA8GTumTdJxG6kDj/xHiV3sZ+J zd58gaD5Y2mkC0kJ3HB33nBzVl6UoGn+Bpq51GFQPBmNHPSMtD/lOVbVsq8CRgqVTtdk fZOA== X-Gm-Message-State: AOJu0YxVIlD1ZyE9GnStLzOnfLEndzLWXQjLOXBtpLCE+ZPYZO/wkoss tiSrnkYOZNmztmsrK0vNSwjiNvmiaHUPG5ufgrk= X-Google-Smtp-Source: AGHT+IG+lLoPTvs3DOOeZ/ePm2ejf775O8V36xusKducIoPqK31NJoVF0FBmqDhH4R3PEbXJex19vg== X-Received: by 2002:a05:6870:148f:b0:1c0:25c0:ebe5 with SMTP id k15-20020a056870148f00b001c025c0ebe5mr3736136oab.53.1691685148683; Thu, 10 Aug 2023 09:32:28 -0700 (PDT) Received: from kea.bld.corp.google.com ([2620:15c:183:200:e0a2:950d:33f0:fddc]) by smtp.gmail.com with ESMTPSA id u21-20020a02aa95000000b0042b28813816sm487309jai.14.2023.08.10.09.32.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 09:32:28 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Masahiro Yamada , Simon Glass Subject: [PATCH 11/28] moveconfig: Use f strings where possible Date: Thu, 10 Aug 2023 10:31:43 -0600 Message-ID: <20230810163212.2368374-12-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog In-Reply-To: <20230810163212.2368374-1-sjg@chromium.org> References: <20230810163212.2368374-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Avoid pylint warnings by using 'f' strings where possible. Signed-off-by: Simon Glass --- tools/moveconfig.py | 56 ++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/tools/moveconfig.py b/tools/moveconfig.py index 54ce8ef7d51..cc35c4bce9d 100755 --- a/tools/moveconfig.py +++ b/tools/moveconfig.py @@ -238,7 +238,7 @@ def read_file(fname, as_lines=True, skip_unicode=False): except UnicodeDecodeError as e: if not skip_unicode: raise - print("Failed on file %s': %s" % (fname, e)) + print(f"Failed on file '{fname}: {e}") return None def try_expand(line): @@ -254,10 +254,10 @@ def try_expand(line): val= val.strip('\"') if re.search(r'[*+-/]|<<|SZ_+|\(([^\)]+)\)', val): newval = hex(aeval(val)) - print('\tExpanded expression %s to %s' % (val, newval)) + print(f'\tExpanded expression {val} to {newval}') return cfg+'='+newval except: - print('\tFailed to expand expression in %s' % line) + print(f'\tFailed to expand expression in {line}') return line @@ -283,7 +283,7 @@ class Progress: def show(self): """Display the progress.""" - print(' %d defconfigs out of %d\r' % (self.current, self.total), end=' ') + print(f' {self.current} defconfigs out of {self.total}\r', end=' ') sys.stdout.flush() @@ -520,7 +520,7 @@ class Slot: toolchain = self.toolchains.Select(arch) except ValueError: self.log += color_text(self.args.color, COLOR_YELLOW, - "Tool chain for '%s' is missing. Do nothing.\n" % arch) + f"Tool chain for '{arch}' is missing. Do nothing.\n") self.finish(False) return env = toolchain.MakeEnvironment(False) @@ -673,7 +673,7 @@ class Slots: boards = '\n'.join(boards) + '\n' msg = 'The following boards were not processed due to error:\n' msg += boards - msg += '(the list has been saved in %s)\n' % output_file + msg += f'(the list has been saved in {output_file})\n' print(color_text(self.args.color, COLOR_LIGHT_RED, msg), file=sys.stderr) @@ -693,8 +693,9 @@ class ReferenceSource: print('Cloning git repo to a separate work directory...') subprocess.check_output(['git', 'clone', os.getcwd(), '.'], cwd=self.src_dir) - print("Checkout '%s' to build the original autoconf.mk." % \ - subprocess.check_output(['git', 'rev-parse', '--short', commit]).strip()) + rev = subprocess.check_output(['git', 'rev-parse', '--short', + commit]).strip() + print(f"Checkout '{rev}' to build the original autoconf.mk.") subprocess.check_output(['git', 'checkout', commit], stderr=subprocess.STDOUT, cwd=self.src_dir) @@ -724,8 +725,8 @@ def move_config(toolchains, args, db_queue): if args.force_sync: print('Syncing defconfigs', end=' ') elif args.build_db: - print('Building %s database' % CONFIG_DATABASE) - print('(jobs: %d)\n' % args.jobs) + print(f'Building {CONFIG_DATABASE} database') + print(f'(jobs: {args.jobs})\n') if args.git_ref: reference_src = ReferenceSource(args.git_ref) @@ -800,17 +801,17 @@ def check_imply_rule(kconf, config, imply_config): return 'cannot find sym' nodes = sym.nodes if len(nodes) != 1: - return '%d locations' % len(nodes) + return f'{len(nodes)} locations' node = nodes[0] fname, linenum = node.filename, node.linenr cwd = os.getcwd() if cwd and fname.startswith(cwd): fname = fname[len(cwd) + 1:] - file_line = ' at %s:%d' % (fname, linenum) + file_line = f' at {fname}:{linenum}' data = read_file(fname) - if data[linenum - 1] != 'config %s' % imply_config: - return None, 0, 'bad sym format %s%s' % (data[linenum], file_line) - return fname, linenum, 'adding%s' % file_line + if data[linenum - 1] != f'config {imply_config}': + return None, 0, f'bad sym format {data[linenum]}{file_line})' + return fname, linenum, f'adding{file_line}' def add_imply_rule(config, fname, linenum): """Add a new 'imply' option to a Kconfig @@ -823,15 +824,15 @@ def add_imply_rule(config, fname, linenum): Returns: Message indicating the result """ - file_line = ' at %s:%d' % (fname, linenum) + file_line = f' at {fname}:{linenum}' data = read_file(fname) linenum -= 1 for offset, line in enumerate(data[linenum:]): if line.strip().startswith('help') or not line: - data.insert(linenum + offset, '\timply %s' % config) + data.insert(linenum + offset, f'\timply {config}') write_file(fname, data) - return 'added%s' % file_line + return f'added{file_line}' return 'could not insert%s' @@ -946,15 +947,14 @@ def do_imply_config(config_list, add_imply, imply_flags, skip_added, for config in config_list: defconfigs = defconfig_db.get(config) if not defconfigs: - print('%s not found in any defconfig' % config) + print(f'{config} not found in any defconfig') continue # Get the set of defconfigs without this one (since a config cannot # imply itself) non_defconfigs = all_defconfigs - defconfigs num_defconfigs = len(defconfigs) - print('%s found in %d/%d defconfigs' % (config, num_defconfigs, - len(all_configs))) + print(f'{config} found in {num_defconfigs}/{len(all_configs)} defconfigs') # This will hold the results: key=config, value=defconfigs containing it imply_configs = {} @@ -1035,7 +1035,7 @@ def do_imply_config(config_list, add_imply, imply_flags, skip_added, fname, linenum = nodes[0].filename, nodes[0].linenr if cwd and fname.startswith(cwd): fname = fname[len(cwd) + 1:] - kconfig_info = '%s:%d' % (fname, linenum) + kconfig_info = f'{fname}:{linenum}' if skip_added: show = False else: @@ -1061,8 +1061,8 @@ def do_imply_config(config_list, add_imply, imply_flags, skip_added, add_list[fname].append(linenum) if show and kconfig_info != 'skip': - print('%5d : %-30s%-25s %s' % (num_common, iconfig.ljust(30), - kconfig_info, missing_str)) + print(f'{num_common:5d} : ' + f'{iconfig.ljust(30):-30s}{kconfig_info:-25s} {missing_str}') # Having collected a list of things to add, now we add them. We process # each file from the largest line number to the smallest so that @@ -1554,11 +1554,11 @@ doc/develop/moveconfig.rst for documentation.''' for flag in args.imply_flags.split(','): bad = flag not in IMPLY_FLAGS if bad: - print("Invalid flag '%s'" % flag) + print(f"Invalid flag '{flag}'") if flag == 'help' or bad: print("Imply flags: (separate with ',')") for name, info in IMPLY_FLAGS.items(): - print(' %-15s: %s' % (name, info[1])) + print(f' {name:-15s}: {info[1]}') parser.print_usage() sys.exit(1) imply_flags |= IMPLY_FLAGS[flag][0] @@ -1588,9 +1588,9 @@ doc/develop/moveconfig.rst for documentation.''' if args.build_db: with open(CONFIG_DATABASE, 'w', encoding='utf-8') as fd: for defconfig, configs in config_db.items(): - fd.write('%s\n' % defconfig) + fd.write(f'{defconfig}\n') for config in sorted(configs.keys()): - fd.write(' %s=%s\n' % (config, configs[config])) + fd.write(f' {config}={configs[config]}\n') fd.write('\n') if __name__ == '__main__':