code_relocation: fix ruff B028 warnings

The ruff python linter produces a B028 warning when the warnings.warn()
function is called with a stacklevel parameter.

By default the function will set a stacklevel of 1 which causes it to
output the stack frame of the line where the function is called without
any context information from higher up the stack.

It is recommended to use a stacklevel of 2 or higher. Therfore, this patch
sets the stacklevel parameter of all warnings.warn() calls to to 2.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
This commit is contained in:
Joel Holdsworth 2025-05-21 10:02:40 -07:00 committed by Benjamin Cabé
commit 4f0b402224
2 changed files with 6 additions and 4 deletions

View file

@ -233,7 +233,6 @@
"UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting "UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting
] ]
"./scripts/build/gen_relocate_app.py" = [ "./scripts/build/gen_relocate_app.py" = [
"B028", # https://docs.astral.sh/ruff/rules/no-explicit-stacklevel
"E101", # https://docs.astral.sh/ruff/rules/mixed-spaces-and-tabs "E101", # https://docs.astral.sh/ruff/rules/mixed-spaces-and-tabs
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports "I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
"SIM102", # https://docs.astral.sh/ruff/rules/collapsible-if "SIM102", # https://docs.astral.sh/ruff/rules/collapsible-if

View file

@ -266,7 +266,8 @@ def find_sections(filename: str, symbol_filter: str) -> 'dict[SectionKind, list[
warnings.warn( warnings.warn(
"Common variable found. Move " "Common variable found. Move "
+ symbol.name + symbol.name
+ " to bss by assigning it to 0/NULL" + " to bss by assigning it to 0/NULL",
stacklevel=2,
) )
return out return out
@ -608,10 +609,12 @@ def create_dict_wrt_mem():
for file_glob in file_list: for file_glob in file_list:
glob_results = glob.glob(file_glob) glob_results = glob.glob(file_glob)
if not glob_results: if not glob_results:
warnings.warn("File: " + file_glob + " Not found") warnings.warn("File: " + file_glob + " Not found", stacklevel=2)
continue continue
elif len(glob_results) > 1: elif len(glob_results) > 1:
warnings.warn("Regex in file lists is deprecated, please use file(GLOB) instead") warnings.warn(
"Regex in file lists is deprecated, please use file(GLOB) instead", stacklevel=2
)
file_name_list.extend(glob_results) file_name_list.extend(glob_results)
if len(file_name_list) == 0: if len(file_name_list) == 0:
continue continue