Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 48EE5C001DC for ; Wed, 19 Jul 2023 23:54:36 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 41A598680F; Thu, 20 Jul 2023 01:51:15 +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="alvUSfu3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3C028867CF; Thu, 20 Jul 2023 01:50:26 +0200 (CEST) Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) (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 0FDC5867B3 for ; Thu, 20 Jul 2023 01:50:18 +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-io1-xd34.google.com with SMTP id ca18e2360f4ac-78666f06691so9350039f.0 for ; Wed, 19 Jul 2023 16:50:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1689810616; x=1690415416; 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=HAGHv8XDFGMAO2gd+nYkWIbU8UkVipfBnLeVGyx7lGY=; b=alvUSfu3tJ+MCj0ZlwmfVbyNnqSyEWSYFM4XJ0IgC8HkRlq2ALAUH8pJ8YTWG3BpBf z4mi3mxFkQVDHV27RSddOJgKNEBw0OGGenXLyiXygU+b+GkJOo/h5MPcBOfGkJ3v7j5q FqFrno7BAU4JDn3JXCICDuB3vxk+np36xCyeg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689810616; x=1690415416; 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=HAGHv8XDFGMAO2gd+nYkWIbU8UkVipfBnLeVGyx7lGY=; b=XeEn/mWv3kdgdM2KL9hwzXUraNF8hemZ0r9uegNPspJV056kwxf6/MsPdWDFWNXg3F Xlm8O8+nvVj1jEGKP8DcDISwIH/A41IX4ReMe4+OxNpOtZH+x3t79f8j71nJw1J4sb9w +DD00N3sDiC9YvQ459J9tcqDRJQM/csPPJ4kc3mzv8InbOgkAF0xSDF8rpzHTXaFmA6Y khMvPAXx6vOTdEGTP4Tw5efdvw6DIWFH2qLotZeokkodMZqWE27wnXyJuaCVUV5K7BNA eXwqyz4smJF8Ilv/SArUVDMwGFNtrfHG3/TaZoI7nXBsAbXz8o6IXnVIAEuJakDroBAj fPxA== X-Gm-Message-State: ABy/qLbMVqqSFbas8I3NMisnBMg1Gry4+Kz+DOWft1wU1jX0ErU24E0V qU20SdXRYk9Xv9ESm4wmXb18N5RQt2hUqnU+xyQ= X-Google-Smtp-Source: APBJJlFCaYHWk2IXlDqGjuOQ3FUzEiwzE4+IDwnHCWJz/bRW3+GMOe/b8y4Jfe77euRn4QEZFf+8bg== X-Received: by 2002:a6b:f61a:0:b0:785:d06d:7b04 with SMTP id n26-20020a6bf61a000000b00785d06d7b04mr3760689ioh.1.1689810616576; Wed, 19 Jul 2023 16:50:16 -0700 (PDT) Received: from sjg1.lan (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id ed16-20020a056638291000b0042bb1779c18sm1551779jab.151.2023.07.19.16.50.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 16:50:16 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Mike Frysinger , Simon Glass Subject: [PATCH v4 23/83] buildman: Fix most pylint warnings in control Date: Wed, 19 Jul 2023 17:48:31 -0600 Message-ID: <20230719234953.796101-24-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230719234953.796101-1-sjg@chromium.org> References: <20230719234953.796101-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Tidy up the easier-to-fix pylint warnings in module 'control'. Signed-off-by: Simon Glass --- (no changes since v1) tools/buildman/control.py | 119 +++++++++++++++++++++--------------- tools/buildman/func_test.py | 2 +- 2 files changed, 71 insertions(+), 50 deletions(-) diff --git a/tools/buildman/control.py b/tools/buildman/control.py index fac6c45fcdd6..c4be1ad2f4ec 100644 --- a/tools/buildman/control.py +++ b/tools/buildman/control.py @@ -15,7 +15,6 @@ except ImportError: import importlib_resources import os import shutil -import subprocess import sys from buildman import boards @@ -30,6 +29,8 @@ from u_boot_pylib import terminal from u_boot_pylib import tools from u_boot_pylib.terminal import tprint +TEST_BUILDER = None + def get_plural(count): """Returns a plural 's' if count is not 1""" return 's' if count != 1 else '' @@ -43,17 +44,17 @@ def get_action_summary(is_summary, commits, selected, options): if commits: count = len(commits) count = (count + options.step - 1) // options.step - commit_str = '%d commit%s' % (count, get_plural(count)) + commit_str = f'{count} commit{get_plural(count)}' else: commit_str = 'current source' - str = '%s %s for %d boards' % ( - 'Summary of' if is_summary else 'Building', commit_str, - len(selected)) - str += ' (%d thread%s, %d job%s per thread)' % (options.threads, - get_plural(options.threads), options.jobs, get_plural(options.jobs)) - return str - -def show_actions(series, why_selected, boards_selected, builder, options, + msg = (f"{'Summary of' if is_summary else 'Building'} " + f'{commit_str} for {len(selected)} boards') + msg += (f' ({options.threads} thread{get_plural(options.threads)}, ' + f'{options.jobs} job{get_plural(options.jobs)} per thread)') + return msg + +# pylint: disable=R0913 +def show_actions(series, why_selected, boards_selected, bldr, options, board_warnings): """Display a list of actions that we would take, if not a dry run. @@ -66,7 +67,7 @@ def show_actions(series, why_selected, boards_selected, builder, options, the value would be a list of board names. boards_selected: Dict of selected boards, key is target name, value is Board object - builder: The builder that will be used to build the commits + bldr: The builder that will be used to build the commits options: Command line options object board_warnings: List of warnings obtained from board selected """ @@ -79,7 +80,7 @@ def show_actions(series, why_selected, boards_selected, builder, options, commits = None print(get_action_summary(False, commits, boards_selected, options)) - print('Build directory: %s' % builder.base_dir) + print(f'Build directory: {bldr.base_dir}') if commits: for upto in range(0, len(series.commits), options.step): commit = series.commits[upto] @@ -88,11 +89,11 @@ def show_actions(series, why_selected, boards_selected, builder, options, print() for arg in why_selected: if arg != 'all': - print(arg, ': %d boards' % len(why_selected[arg])) + print(arg, f': {len(why_selected[arg])} boards') if options.verbose: - print(' %s' % ' '.join(why_selected[arg])) - print(('Total boards to build for each commit: %d\n' % - len(why_selected['all']))) + print(f" {' '.join(why_selected[arg])}") + print('Total boards to build for each ' + f"commit: {len(why_selected['all'])}\n") if board_warnings: for warning in board_warnings: print(col.build(col.YELLOW, warning)) @@ -116,12 +117,26 @@ def show_toolchain_prefix(brds, toolchains): tc_set.add(toolchains.Select(brd.arch)) if len(tc_set) != 1: return 'Supplied boards must share one toolchain' - return False - tc = tc_set.pop() - print(tc.GetEnvArgs(toolchain.VAR_CROSS_COMPILE)) + tchain = tc_set.pop() + print(tchain.GetEnvArgs(toolchain.VAR_CROSS_COMPILE)) return None def get_allow_missing(opt_allow, opt_no_allow, num_selected, has_branch): + """Figure out whether to allow external blobs + + Uses the allow-missing setting and the provided arguments to decide whether + missing external blobs should be allowed + + Args: + opt_allow (bool): True if --allow-missing flag is set + opt_no_allow (bool): True if --no-allow-missing flag is set + num_selected (int): Number of selected board + has_branch (bool): True if a git branch (to build) has been provided + + Returns: + bool: True to allow missing external blobs, False to produce an error if + external blobs are used + """ allow_missing = False am_setting = bsettings.GetGlobalItemValue('allow-missing') if am_setting: @@ -159,7 +174,8 @@ def do_buildman(options, args, toolchains=None, make_func=None, brds=None, raise an exception instead of reporting their result. This simulates a failure in the code somewhere """ - global builder + # Used so testing can obtain the builder: pylint: disable=W0603 + global TEST_BUILDER if options.full_help: with importlib.resources.path('buildman', 'README.rst') as readme: @@ -178,22 +194,23 @@ def do_buildman(options, args, toolchains=None, make_func=None, brds=None, if options.fetch_arch: if options.fetch_arch == 'list': sorted_list = toolchains.ListArchs() - print(col.build(col.BLUE, 'Available architectures: %s\n' % - ' '.join(sorted_list))) - return 0 - else: - fetch_arch = options.fetch_arch - if fetch_arch == 'all': - fetch_arch = ','.join(toolchains.ListArchs()) - print(col.build(col.CYAN, '\nDownloading toolchains: %s' % - fetch_arch)) - for arch in fetch_arch.split(','): - print() - ret = toolchains.FetchAndInstall(arch) - if ret: - return ret + print(col.build( + col.BLUE, + f"Available architectures: {' '.join(sorted_list)}\n")) return 0 + fetch_arch = options.fetch_arch + if fetch_arch == 'all': + fetch_arch = ','.join(toolchains.ListArchs()) + print(col.build(col.CYAN, + f'\nDownloading toolchains: {fetch_arch}')) + for arch in fetch_arch.split(','): + print() + ret = toolchains.FetchAndInstall(arch) + if ret: + return ret + return 0 + if no_toolchains: toolchains.GetSettings() toolchains.Scan(options.list_tool_chains and options.verbose) @@ -218,6 +235,7 @@ def do_buildman(options, args, toolchains=None, make_func=None, brds=None, board_file = options.regen_board_list brds = boards.Boards() + if options.maintainer_check: warnings = brds.build_board_list(jobs=nr_cups)[1] if warnings: @@ -226,11 +244,13 @@ def do_buildman(options, args, toolchains=None, make_func=None, brds=None, return 2 return 0 - ok = brds.ensure_board_list(board_file, nr_cups, - force=options.regen_board_list, - quiet=not options.verbose) + okay = brds.ensure_board_list( + board_file, + options.threads or multiprocessing.cpu_count(), + force=options.regen_board_list, + quiet=not options.verbose) if options.regen_board_list: - return 0 if ok else 2 + return 0 if okay else 2 brds.read_boards(board_file) exclude = [] @@ -240,14 +260,14 @@ def do_buildman(options, args, toolchains=None, make_func=None, brds=None, if options.boards: requested_boards = [] - for b in options.boards: - requested_boards += b.split(',') + for brd in options.boards: + requested_boards += brd.split(',') else: requested_boards = None why_selected, board_warnings = brds.select_boards(args, exclude, requested_boards) selected = brds.get_selected() - if not len(selected): + if not selected: sys.exit(col.build(col.RED, 'No matching boards found')) if options.print_prefix: @@ -274,15 +294,15 @@ def do_buildman(options, args, toolchains=None, make_func=None, brds=None, if count is None: sys.exit(col.build(col.RED, msg)) elif count == 0: - sys.exit(col.build(col.RED, "Range '%s' has no commits" % - options.branch)) + sys.exit(col.build(col.RED, + f"Range '{options.branch}' has no commits")) if msg: print(col.build(col.YELLOW, msg)) count += 1 # Build upstream commit also if not count: - msg = ("No commits found to process in branch '%s': " - "set branch's upstream or use -c flag" % options.branch) + msg = (f"No commits found to process in branch '{options.branch}': " + "set branch's upstream or use -c flag") sys.exit(col.build(col.RED, msg)) if options.work_in_output: if len(selected) != 1: @@ -381,6 +401,7 @@ def do_buildman(options, args, toolchains=None, make_func=None, brds=None, adjust_cfg=adjust_cfg, allow_missing=allow_missing, no_lto=options.no_lto, reproducible_builds=options.reproducible_builds) + TEST_BUILDER = builder builder.force_config_on_failure = not options.quick if make_func: builder.do_make = make_func @@ -401,8 +422,8 @@ def do_buildman(options, args, toolchains=None, make_func=None, brds=None, if series: commits = series.commits # Number the commits for test purposes - for commit in range(len(commits)): - commits[commit].sequence = commit + for i, commit in enumerate(commits): + commit.sequence = i else: commits = None @@ -425,8 +446,8 @@ def do_buildman(options, args, toolchains=None, make_func=None, brds=None, commits, board_selected, options.keep_outputs, options.verbose) if excs: return 102 - elif fail: + if fail: return 100 - elif warned and not options.ignore_warnings: + if warned and not options.ignore_warnings: return 101 return 0 diff --git a/tools/buildman/func_test.py b/tools/buildman/func_test.py index 57d2ebce3ad3..85222b9f9bc2 100644 --- a/tools/buildman/func_test.py +++ b/tools/buildman/func_test.py @@ -260,7 +260,7 @@ class TestFunctional(unittest.TestCase): make_func=self._HandleMake, brds=brds, clean_dir=clean_dir, test_thread_exceptions=test_thread_exceptions) if get_builder: - self._builder = control.builder + self._builder = control.TEST_BUILDER return result def testFullHelp(self): -- 2.41.0.487.g6d72f3e995-goog