From patchwork Sun Jan 4 20:08:32 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1262 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767557350; bh=KXIwgXHqDapim5B6qOj3TFjqptT/qv9xBMAmjXeYEq0=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=ELgrLcF6DqEEBla3A+GN/07/PkAQSD5PNXSCERMxb9aWsJPH2lY1aj8o4WRuWCVIj ilDP9DzcNtVNBuppWjlwlHMvTq/HATWbFbmml2cYUv8faaUi1qjzkiPnTHdn2meRJC 8FfeIUxFko4Z4o2EVchmDyjK99CZnoqWZC+AFzQ/Pqkz+a+Pz2oFYekwkUF9oOdJsL bTVnaxDYsNY7WHD4GCiN3++rshm63hNfgCtKb4B9gpM9uv8IGph/kgoNYXrNykM4oE jngrKXTOUGeef0ONnBLi4dgVW1b3+03Kb7i5QYSooMz9I8+mGXCMtZo8Wo69xPYxD8 a5FqYyfryIFVQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C632B690D1 for ; Sun, 4 Jan 2026 13:09:10 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 3jT4zaNl6yxN for ; Sun, 4 Jan 2026 13:09:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767557350; bh=KXIwgXHqDapim5B6qOj3TFjqptT/qv9xBMAmjXeYEq0=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=ELgrLcF6DqEEBla3A+GN/07/PkAQSD5PNXSCERMxb9aWsJPH2lY1aj8o4WRuWCVIj ilDP9DzcNtVNBuppWjlwlHMvTq/HATWbFbmml2cYUv8faaUi1qjzkiPnTHdn2meRJC 8FfeIUxFko4Z4o2EVchmDyjK99CZnoqWZC+AFzQ/Pqkz+a+Pz2oFYekwkUF9oOdJsL bTVnaxDYsNY7WHD4GCiN3++rshm63hNfgCtKb4B9gpM9uv8IGph/kgoNYXrNykM4oE jngrKXTOUGeef0ONnBLi4dgVW1b3+03Kb7i5QYSooMz9I8+mGXCMtZo8Wo69xPYxD8 a5FqYyfryIFVQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B36DA690BD for ; Sun, 4 Jan 2026 13:09:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767557348; bh=pUm3j4UcUxEsfDMbV1EoAV/YZr3ekSx2mbxwFJSawDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lbvAoLhhSE/Itv6x1ukpxQkvZh457Af20zq0fK2jqHqRQtfqlFyBKqW68ujmMRo6K xCNX7navrClAUd910xWhgqoh+Jm5bHhraYrfT5iABMfMdyD3Vloz727QeAyzgnsY53 xaKkZVSG1zNJBZxVrBNctkmZnf60rRxGxWZVEh2vEoheKLT9rC4QfYpYXNqbznWumI oN7I3VmJCzyrVet6jDKAjK8PsqVcBuW+1yXwdPcQVktDh/B4cGQVFK3+kW+G524mNP jE78uFHUTn36SjltGmP5/0ncIrI38TOhs401JWIzn7t54wU07kgwcR7t0GaAKxgJS6 3v5eYtR2Cx3Sg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BC756690BD; Sun, 4 Jan 2026 13:09:08 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id G5m8TkWfrfzy; Sun, 4 Jan 2026 13:09:08 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767557344; bh=Rum0nXWznXEoJ120IyP/lSOvvNqpqf31913KP2e5DLU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cjvaK8LU89nODzCkNSp+PYBq0p7Rodfb9Y/ycBJj+wxs+8lJSb7iH4qyvA1S3GAb9 wvh4W1Rm8y2MjGyqrEaG2fFex8x6CAdVih52RTnqdBHo5ABPqdyUEmz3vHr8T9yegU ZLpP9/QB0RBFYYkg/LmDe3w6riOwzUSr7KMMz9uSFH2Br3gXHZhyagMY1VieK1KSsd 4lPb76Vh8WRo+m9SoqB2xC/SuA4sHkIho6BEyR9CHeo0Vs2UN5MvwJ11TWq/jleuOb TIRhsjNnxYlpzYsFgqeKrIhuFtFtuY6Nz0JIDC9NmCqsVjfygbBH79jT6bexpY2+/U mfeBgTm7CQPgg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 7D39E69003; Sun, 4 Jan 2026 13:09:04 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sun, 4 Jan 2026 13:08:32 -0700 Message-ID: <20260104200844.481633-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260104200844.481633-1-sjg@u-boot.org> References: <20260104200844.481633-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: V3IZQJCWP6SFBQ4UPNHG6J4H3U4YY6V3 X-Message-ID-Hash: V3IZQJCWP6SFBQ4UPNHG6J4H3U4YY6V3 X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 03/11] buildman: Fix pylint warnings in bsettings.py List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass - Add module docstring and define settings at module level - Fix docstrings: correct param names, add types, remove redundant returns - Add docstrings for add_file() and add_section() - Remove pointless except:raise and unused variable in get_items() - Remove unnecessary global statements in set_item() - Add encoding='utf-8' to open() calls - Rename param to avoid shadowing global config_fname - Use with statement for file handling - Convert % formatting to f-strings - Remove unnecessary semicolon - Add pylint disable comments for intentional global usage Co-developed-by: Claude Signed-off-by: Simon Glass --- tools/buildman/bsettings.py | 60 ++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/tools/buildman/bsettings.py b/tools/buildman/bsettings.py index a7358cfc08a..1af2bc66101 100644 --- a/tools/buildman/bsettings.py +++ b/tools/buildman/bsettings.py @@ -1,26 +1,30 @@ # SPDX-License-Identifier: GPL-2.0+ # Copyright (c) 2012 The Chromium OS Authors. +"""Handles settings for buildman, reading from a config file.""" + import configparser -import os import io +import os +# pylint: disable=C0103 +settings = None config_fname = None def setup(fname=''): """Set up the buildman settings module by reading config files Args: - config_fname: Config filename to read ('' for default) + fname (str): Config filename to read ('' for default) """ - global settings - global config_fname + global settings # pylint: disable=W0603 + global config_fname # pylint: disable=W0603 settings = configparser.ConfigParser() if fname is not None: config_fname = fname if config_fname == '': - config_fname = '%s/.buildman' % os.getenv('HOME') + config_fname = f"{os.getenv('HOME')}/.buildman" if not os.path.exists(config_fname): print('No config file found ~/.buildman\nCreating one...\n') create_buildman_config_file(config_fname) @@ -29,32 +33,40 @@ def setup(fname=''): settings.read(config_fname) def add_file(data): + """Add settings from a string + + Args: + data (str): Config data in INI format + """ settings.read_file(io.StringIO(data)) def add_section(name): + """Add a new section to the settings + + Args: + name (str): Name of section to add + """ settings.add_section(name) def get_items(section): """Get the items from a section of the config. Args: - section: name of section to retrieve + section (str): name of section to retrieve Returns: - List of (name, value) tuples for the section + list of tuple: List of (name, value) tuples for the section """ try: return settings.items(section) - except configparser.NoSectionError as e: + except configparser.NoSectionError: return [] - except: - raise def get_global_item_value(name): """Get an item from the 'global' section of the config. Args: - name: name of item to retrieve + name (str): name of item to retrieve Returns: str: Value of item, or None if not present @@ -63,30 +75,20 @@ def get_global_item_value(name): def set_item(section, tag, value): """Set an item and write it back to the settings file""" - global settings - global config_fname - settings.set(section, tag, value) if config_fname is not None: - with open(config_fname, 'w') as fd: + with open(config_fname, 'w', encoding='utf-8') as fd: settings.write(fd) -def create_buildman_config_file(config_fname): +def create_buildman_config_file(cfgname): """Creates a new config file with no tool chain information. Args: - config_fname: Config filename to create - - Returns: - None + cfgname (str): Config filename to create """ try: - f = open(config_fname, 'w') - except IOError: - print("Couldn't create buildman config file '%s'\n" % config_fname) - raise - - print('''[toolchain] + with open(cfgname, 'w', encoding='utf-8') as out: + print('''[toolchain] # name = path # e.g. x86 = /opt/gcc-4.6.3-nolibc/x86_64-linux other = / @@ -108,5 +110,7 @@ x86 = i386 # snapper-boards=ENABLE_AT91_TEST=1 # snapper9260=${snapper-boards} BUILD_TAG=442 # snapper9g45=${snapper-boards} BUILD_TAG=443 -''', file=f) - f.close(); +''', file=out) + except IOError: + print(f"Couldn't create buildman config file '{cfgname}'\n") + raise