BitBake Linting Errors
Using the ruff tool on bitbake-setup reports a number of linting errors.
This patch series resolves those errors to give bitbake-setup a clean bill of health:
bitbake-setup: Remove extraneous variable from
bitbake-setup: Resolve unused loop control variables
bitbake-setup: Fix ambiguous variable names
bitbake-setup: Remove unused stdout variable
bitbake-setup: Replace f-string without placeholders
bitbake-setup: Remove unused Namespace import
bitbake-setup: Remove unused parser_settings_list
bitbake-setup: Fix linting error related to membership
bitbake-setup: Maintain exception chain
bitbake-setup: Set function default to None
bitbake-setup: Sort and format imports
bitbake-setup: Remove extraneous variable from
bitbake-setup: Resolve unused loop control variables
bitbake-setup: Fix ambiguous variable names
bitbake-setup: Remove unused stdout variable
bitbake-setup: Replace f-string without placeholders
bitbake-setup: Remove unused Namespace import
bitbake-setup: Remove unused parser_settings_list
bitbake-setup: Fix linting error related to membership
bitbake-setup: Maintain exception chain
bitbake-setup: Set function default to None
bitbake-setup: Sort and format imports
PATCH 1/11 bitbake-setup: Remove extraneous variable from str.format()
The invocation of str.format() supplied an extra parameter that was not being referenced in the string.
--- bin/bitbake-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
bin/bitbake-setup +1 -1
@@ -1176,7 +1176,7 @@ def main(): list_configs(all_settings, args) return - logger.info('Bitbake-setup is using {} as top directory.'.format(top_dir, global_settings_path(args))) + logger.info('Bitbake-setup is using {} as top directory.'.format(top_dir)) if args.func == init_config: init_config(top_dir, all_settings, args)
Signature · 1 line
2.39.5
PATCH 2/11 bitbake-setup: Resolve unused loop control variables
In reply to Rob WoolleyThe ruff lint tool reported loop control variables that were not being used:
B007 Loop control variable dirs not used within loop body
Adding underscore as a prefix helps indicate that it is not being used inside the loop.
--- bin/bitbake-setup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
bin/bitbake-setup +3 -3
@@ -133,7 +133,7 @@ def commit_config(config_dir): def _write_layer_list(dest, repodirs): layers = [] for r in repodirs: - for root, dirs, files in os.walk(os.path.join(dest,r)): + for root, _dirs, files in os.walk(os.path.join(dest,r)): if os.path.basename(root) == 'conf' and 'layer.conf' in files: layers.append(os.path.relpath(os.path.dirname(root), dest)) layers_f = os.path.join(dest, ".oe-layers.json")
@@ -414,7 +414,7 @@ The bitbake configuration files (local.conf, bblayers.conf and more) can be foun logger.plain("The bitbake configuration files (local.conf, bblayers.conf and more) can be found in\n {}/conf\n".format(bitbake_builddir)) def get_registry_config(registry_path, id): - for root, dirs, files in os.walk(registry_path): + for root, _dirs, files in os.walk(registry_path): for f in files: if f.endswith('.conf.json') and id == get_config_name(f): return os.path.join(root, f)
@@ -818,7 +818,7 @@ def has_expired(expiry_date): def list_registry(registry_path, with_expired): json_data = {} - for root, dirs, files in os.walk(registry_path): + for root, _dirs, files in os.walk(registry_path): for f in files: if f.endswith('.conf.json'): config_name = get_config_name(f)
Signature · 1 line
2.39.5
PATCH 3/11 bitbake-setup: Fix ambiguous variable names
In reply to Rob WoolleyThe ruff lint tool detected use of ambiguous variables that were named with a single letter:
E741 Ambiguous variable name: l
E741 Ambiguous variable name: f
This replaces the variables with a descriptive variable to add clarity.
--- bin/bitbake-setup | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
bin/bitbake-setup +16 -16
@@ -231,11 +231,11 @@ bitbake-setup init -L {} /path/to/repo/checkout""".format( if oesetupbuild: links = {'setup-build': oesetupbuild, 'oe-scripts': os.path.dirname(oesetupbuild), 'oe-init-build-env-dir': oeinitbuildenvdir} - for l,t in links.items(): - symlink = os.path.join(layerdir, l) + for link,item in links.items(): + symlink = os.path.join(layerdir, link) if os.path.lexists(symlink): os.remove(symlink) - os.symlink(os.path.relpath(t,layerdir),symlink) + os.symlink(os.path.relpath(item,layerdir),symlink) return layers_fixed_revisions
@@ -244,19 +244,19 @@ def setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir, update_bb_c os.makedirs(build_conf_dir) layers_s = [] - for l in layers: - l = os.path.join(layerdir, l) - layers_s.append(" {} \\".format(l)) + for layer in layers: + layer = os.path.join(layerdir, layer) + layers_s.append(" {} \\".format(layer)) - for l in filerelative_layers: + for layer in filerelative_layers: if thisdir: - l = os.path.join(thisdir, l) + layer = os.path.join(thisdir, layer) else: raise Exception("Configuration is using bb-layers-file-relative to specify " \ "a layer path relative to itself. This can be done only " \ "when the configuration is specified by its path on local " \ "disk, not when it's in a registry or is fetched over http.") - layers_s.append(" {} \\".format(l)) + layers_s.append(" {} \\".format(layer)) layers_s = "\n".join(layers_s) bblayers_conf = """BBLAYERS ?= " \\
@@ -415,9 +415,9 @@ The bitbake configuration files (local.conf, bblayers.conf and more) can be foun def get_registry_config(registry_path, id): for root, _dirs, files in os.walk(registry_path): - for f in files: - if f.endswith('.conf.json') and id == get_config_name(f): - return os.path.join(root, f) + for file in files: + if file.endswith('.conf.json') and id == get_config_name(file): + return os.path.join(root, file) raise Exception("Unable to find {} in available configurations; use 'list' sub-command to see what is available".format(id)) def merge_overrides_into_sources(sources, overrides):
@@ -819,10 +819,10 @@ def list_registry(registry_path, with_expired): json_data = {} for root, _dirs, files in os.walk(registry_path): - for f in files: - if f.endswith('.conf.json'): - config_name = get_config_name(f) - config_data = json.load(open(os.path.join(root, f))) + for file in files: + if file.endswith('.conf.json'): + config_name = get_config_name(file) + config_data = json.load(open(os.path.join(root, file))) config_desc = config_data["description"] expiry_date = config_data.get("expires", None) if expiry_date:
Signature · 1 line
2.39.5
PATCH 4/11 bitbake-setup: Remove unused stdout variable
In reply to Rob WoolleyThe ruff lint tool reported that stdout was never used:
F841 Local variable stdout is assigned to but never used
--- bin/bitbake-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
bin/bitbake-setup +1 -1
@@ -626,7 +626,7 @@ def init_config(top_dir, settings, args): create_siteconf(top_dir, args.non_interactive, settings) d = init_bb_cache(top_dir, settings, args) - stdout = sys.stdout + def handle_task_progress(event, d): rate = event.rate if event.rate else '' progress = event.progress if event.progress > 0 else 0
Signature · 1 line
2.39.5
PATCH 5/11 bitbake-setup: Replace f-string without placeholders
In reply to Rob WoolleyThe ruff lint tool reported an f-string that didn't include any placeholders:
F541 f-string without any placeholders
--- bin/bitbake-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
bin/bitbake-setup +1 -1
@@ -1040,7 +1040,7 @@ def merge_settings(builtin_settings, global_settings, topdir_settings, cmdline_s return all_settings def sigint_handler(sig, frame, func, top_dir): - logger.plain(f'\nShutting down...') + logger.plain('\nShutting down...') if isinstance(top_dir, str) and os.path.exists(top_dir): if func in [init_config, build_update]: logger.warning(f'{top_dir} may contain an incomplete setup!')
Signature · 1 line
2.39.5
PATCH 6/11 bitbake-setup: Remove unused Namespace import
In reply to Rob WoolleyThe ruff lint tool reported that Namespace was not used:
F401 argparse.Namespace imported but unused
--- bin/bitbake-setup | 1 - 1 file changed, 1 deletion(-)
bin/bitbake-setup +0 -1
@@ -1186,7 +1186,6 @@ def main(): save_bb_cache() else: - from argparse import Namespace parser.print_help() main()
Signature · 1 line
2.39.5
PATCH 7/11 bitbake-setup: Remove unused parser_settings_list
In reply to Rob WoolleyThe ruff lint tool detected an used variable:
F841 Local variable parser_settings_list is assigned to but never used
The list_settings function gets invoked through the parent command's settings_func function. This means that creating this variable is unnecessary.
--- bin/bitbake-setup | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
bin/bitbake-setup +1 -2
@@ -1109,8 +1109,7 @@ def main(): subparser_settings = parser_settings.add_subparsers(dest="subcommand", required=True, help="The action to perform on the settings file") - parser_settings_list = subparser_settings.add_parser('list', - help="List all settings with their values") + subparser_settings.add_parser('list', help="List all settings with their values") parser_settings_set = subparser_settings.add_parser('set', parents=[parser_settings_arg_global], help="In a Section, set a setting to a certain value")
Signature · 1 line
2.39.5
PATCH 8/11 bitbake-setup: Fix linting error related to membership
In reply to Rob WoolleyThe pycodestyle E713 recommends that negative tests for membership use foo not in bar instead of not foo in bar.
--- bin/bitbake-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
bin/bitbake-setup +1 -1
@@ -154,7 +154,7 @@ def add_unique_timestamp_to_path(path): def _get_remotes(r_remote): remotes = [] - if not 'remotes' in r_remote and not 'uri' in r_remote: + if 'remotes' not in r_remote and 'uri' not in r_remote: raise Exception("Expected key(s): 'remotes', 'uri'") if 'remotes' in r_remote:
Signature · 1 line
2.39.5
PATCH 9/11 bitbake-setup: Maintain exception chain
In reply to Rob WoolleyChain the exceptions so that it is easier to trace the exception back to its root cause. This resolves B904 linting issues from flake8-bugbear.
--- bin/bitbake-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
bin/bitbake-setup +1 -1
@@ -579,7 +579,7 @@ def obtain_config(top_dir, registry, args, source_overrides, d): json_data = json.load(f) upstream_config = {'type':'network','uri':config_id,'name':get_config_name(config_id),'data':json_data} except json.JSONDecodeError as e: - raise Exception ("Invalid JSON from {}. Are you pointing to an HTML page? {}".format(config_id, e)) + raise Exception ("Invalid JSON from {}. Are you pointing to an HTML page? {}".format(config_id, e)) from e else: logger.info("Looking up config {} in configuration registry".format(config_id)) registry_path = update_registry(registry, cache_dir(top_dir), d)
Signature · 1 line
2.39.5
PATCH 10/11 bitbake-setup: Set function default to None
In reply to Rob WoolleyThe function defaults are evaluated once and use across calls can lead to unexpected behaviour.
Set the value to none and let the function initialize the value in the case when the value is not set.
Resolves B006 from flake8-bugbear
--- bin/bitbake-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
bin/bitbake-setup +1 -1
@@ -45,7 +45,7 @@ def color_enabled() -> bool: def get_diff_color_param() -> str: return "--color=always" if color_enabled() else "--color=never" -def print_configs(prompt: str, choices: list[str], descriptions: list[str] = []): +def print_configs(prompt: str, choices: list[str], descriptions: list[str] = None): """ Helper function to print a list of choices and align the output. Each option name is made bold to stand out, unless color is not enabled in
Signature · 1 line
2.39.5
Re: [bitbake-devel] [PATCH 10/11] bitbake-setup: Set function default to None
Quoted 18 lines · Rob Woolley via lists.openembedded.org
The function defaults are evaluated once and use across calls can lead to unexpected behaviour.
Set the value to none and let the function initialize the value in the case when the value is not set.
Resolves B006 from flake8-bugbear
Signed-off-by Rob Woolley <[email protected]>---
bin/bitbake-setup | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)bin/bitbake-setup +0
-0@@ -45,7 +45,7 @@ def color_enabled() -> bool:
Quoted 7 lines
def
get_diff_color_param()-> str:
return "--color=always" ifcolor_enabled()else "--color=never"
-def print_configs(prompt: str, choices: list[str], descriptions:
list[str] = []):
+def print_configs(prompt: str, choices: list[str], descriptions:
list[str] = None):
While "= None" looks better than "= []", this is still a bit wrong. It should be:
list[str] | None = None
However, this syntax would require Python 3.10+, so not possible.
Other options could be:
- Dropping the type checks from this function
- Using typing.Optional ?
Regards,
Adrian
Quoted 15 lines
"""
Helper function to print a list of choices and align the output. Each option name is made bold to stand out, unless color is not enabled in-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#19255):
https://lists.openembedded.org/g/bitbake-devel/message/19255
Mute This Topic: https://lists.openembedded.org/mt/118523930/4454582
Group Owner: [email protected] Unsubscribe:
https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]
]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [bitbake-devel] [PATCH 10/11] bitbake-setup: Set function default to None
Thanks for pointing this out.
As far as Python 3.9 is concerned, it went end-of-life on October 31, 2025. I recognize that some supported hosts (like Debian 11 and RHEL 9) may have it by default. Do we increment the minimum Python version when the language runtime goes EOL or when the supported hosts do?
Regards,
Rob
________________________________
From: [email protected] <[email protected]>
Sent: Monday, March 30, 2026 12:34 PM
To: Woolley, Rob <[email protected]>; [email protected] <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: [bitbake-devel] [PATCH 10/11] bitbake-setup: Set function default to None
CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.
Quoted 22 lines · Rob Woolley via lists.openembedded.org
The function defaults are evaluated once and use across calls can lead to unexpected behaviour.
Set the value to none and let the function initialize the value in the case when the value is not set.
Resolves B006 from flake8-bugbear
Signed-off-by Rob Woolley <[email protected]>--- bin/bitbake-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)bin/bitbake-setup +0
-1@@ -45,7 +45,7 @@ def color_enabled() -> bool: def get_diff_color_param() -> str: return "--color=always" if color_enabled() else "--color=never" -def print_configs(prompt: str, choices: list[str], descriptions:
Quoted 3 lines
list[str] = []):
+def print_configs(prompt: str, choices: list[str], descriptions:
list[str] = None):
While "= None" looks better than "= []", this is still a bit wrong. It should be:
list[str] | None = None
However, this syntax would require Python 3.10+, so not possible.
Other options could be:
- Dropping the type checks from this function
- Using typing.Optional ?
Regards,
Adrian
Quoted 15 lines
"""
Helper function to print a list of choices and align the output. Each option name is made bold to stand out, unless color is not
enabled in-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#19255):
https://lists.openembedded.org/g/bitbake-devel/message/19255
Mute This Topic: https://lists.openembedded.org/mt/118523930/4454582
Group Owner: [email protected] Unsubscribe:
https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected] ]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [bitbake-devel] [PATCH 10/11] bitbake-setup: Set function default to None
Quoted 8 lines · Rob Woolley via lists.openembedded.org
Thanks for pointing this out.
As far as Python 3.9 is concerned, it went end-of-life on October 31, 2025. I recognize that some supported hosts (like Debian 11 and RHEL
9) may have it by default. Do we increment the minimum Python version when the language runtime goes EOL or when the supported hosts do?
This is not an invitation to discuss the minimum python version this close to release, particularly on a relatively trivial change like this.
I'd rather just remove the typing than start trying to work out minimum versions of different systems, how that combines with build tools, the docs updates needed and so on.
Cheers,
Richard
PATCH 11/11 bitbake-setup: Sort and format imports
In reply to Rob WoolleyThe ruff linting tool reported 2 problems:
I001 Import block is un-sorted or un-formatted E402 Module level import not at top of file
An exception is made for sys.path modifications needed to find the modules.
--- bin/bitbake-setup | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
bin/bitbake-setup +13 -12
@@ -4,28 +4,29 @@ # SPDX-License-Identifier: GPL-2.0-only # -import logging -import os -import sys import argparse -import json -import shutil -import time import configparser +import copy import datetime +import functools import glob -import subprocess -import copy -import textwrap +import json +import logging +import os +import shutil import signal -import functools import string +import subprocess +import sys +import textwrap +import time + bindir = os.path.abspath(os.path.dirname(__file__)) sys.path[0:0] = [os.path.join(os.path.dirname(bindir), 'lib')] -import bb.msg -import bb.process +import bb.msg # noqa: E402 +import bb.process # noqa: E402 logger = bb.msg.logger_create('bitbake-setup', sys.stdout)
Signature · 1 line
2.39.5