From 86b9ec56d74020ace713e1a4f6ecc2e9df2759f0 Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Thu, 2 Oct 2025 22:43:05 +0530 Subject: [PATCH] update formatter and pre-commit Signed-off-by: varun-r-mallya --- .pre-commit-config.yaml | 6 +++--- examples/clone-matplotlib.ipynb | 2 +- pythonbpf/functions_pass.py | 6 ++---- pythonbpf/helper/bpf_helper_handler.py | 9 ++++----- pythonbpf/helper/helper_utils.py | 2 +- pythonbpf/maps/maps_pass.py | 4 +--- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 89c6a80..cfd7a8d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ ci: repos: # Standard hooks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v6.0.0 hooks: - id: check-added-large-files - id: check-case-conflict @@ -36,7 +36,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.4.2" + rev: "v0.13.2" hooks: - id: ruff args: ["--fix", "--show-fixes"] @@ -45,7 +45,7 @@ repos: # Checking static types - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.10.0" + rev: "v1.18.2" hooks: - id: mypy exclude: ^(tests)|^(examples) diff --git a/examples/clone-matplotlib.ipynb b/examples/clone-matplotlib.ipynb index 8cfcb9c..2bf7a33 100644 --- a/examples/clone-matplotlib.ipynb +++ b/examples/clone-matplotlib.ipynb @@ -12,7 +12,7 @@ "from pythonbpf import bpf, map, section, bpfglobal, BPF\n", "from pythonbpf.helper import pid\n", "from pythonbpf.maps import HashMap\n", - "from pylibbpf import *\n", + "from pylibbpf import BpfMap\n", "from ctypes import c_void_p, c_int64, c_uint64, c_int32\n", "import matplotlib.pyplot as plt" ] diff --git a/pythonbpf/functions_pass.py b/pythonbpf/functions_pass.py index 6653677..746eb4c 100644 --- a/pythonbpf/functions_pass.py +++ b/pythonbpf/functions_pass.py @@ -146,8 +146,7 @@ def handle_assign( local_sym_tab[var_name].var, ) logger.info( - f"Assigned {call_type} constant " - f"{rval.args[0].value} to {var_name}" + f"Assigned {call_type} constant {rval.args[0].value} to {var_name}" ) elif HelperHandlerRegistry.has_handler(call_type): # var = builder.alloca(ir.IntType(64), name=var_name) @@ -485,8 +484,7 @@ def allocate_mem( var = builder.alloca(ir_type, name=var_name) has_metadata = True logger.info( - f"Pre-allocated variable {var_name} " - f"for struct {call_type}" + f"Pre-allocated variable {var_name} for struct {call_type}" ) elif isinstance(rval.func, ast.Attribute): ir_type = ir.PointerType(ir.IntType(64)) diff --git a/pythonbpf/helper/bpf_helper_handler.py b/pythonbpf/helper/bpf_helper_handler.py index e3ed1df..f5ae9a0 100644 --- a/pythonbpf/helper/bpf_helper_handler.py +++ b/pythonbpf/helper/bpf_helper_handler.py @@ -62,7 +62,7 @@ def bpf_map_lookup_elem_emitter( """ if not call.args or len(call.args) != 1: raise ValueError( - "Map lookup expects exactly one argument (key), got " f"{len(call.args)}" + f"Map lookup expects exactly one argument (key), got {len(call.args)}" ) key_ptr = get_or_create_ptr_from_arg(call.args[0], builder, local_sym_tab) map_void_ptr = builder.bitcast(map_ptr, ir.PointerType()) @@ -145,8 +145,7 @@ def bpf_map_update_elem_emitter( """ if not call.args or len(call.args) < 2 or len(call.args) > 3: raise ValueError( - "Map update expects 2 or 3 args (key, value, flags), " - f"got {len(call.args)}" + f"Map update expects 2 or 3 args (key, value, flags), got {len(call.args)}" ) key_arg = call.args[0] @@ -196,7 +195,7 @@ def bpf_map_delete_elem_emitter( """ if not call.args or len(call.args) != 1: raise ValueError( - "Map delete expects exactly one argument (key), got " f"{len(call.args)}" + f"Map delete expects exactly one argument (key), got {len(call.args)}" ) key_ptr = get_or_create_ptr_from_arg(call.args[0], builder, local_sym_tab) map_void_ptr = builder.bitcast(map_ptr, ir.PointerType()) @@ -255,7 +254,7 @@ def bpf_perf_event_output_handler( ): if len(call.args) != 1: raise ValueError( - "Perf event output expects exactly one argument, " f"got {len(call.args)}" + f"Perf event output expects exactly one argument, got {len(call.args)}" ) data_arg = call.args[0] ctx_ptr = func.args[0] # First argument to the function is ctx diff --git a/pythonbpf/helper/helper_utils.py b/pythonbpf/helper/helper_utils.py index d06a72b..0da1e5e 100644 --- a/pythonbpf/helper/helper_utils.py +++ b/pythonbpf/helper/helper_utils.py @@ -270,7 +270,7 @@ def _prepare_expr_args(expr, func, module, builder, local_sym_tab, struct_sym_ta val = builder.sext(val, ir.IntType(64)) else: logger.warning( - "Only int and ptr supported in bpf_printk args. " "Others default to 0." + "Only int and ptr supported in bpf_printk args. Others default to 0." ) val = ir.Constant(ir.IntType(64), 0) return val diff --git a/pythonbpf/maps/maps_pass.py b/pythonbpf/maps/maps_pass.py index 693655f..cc8dfa6 100644 --- a/pythonbpf/maps/maps_pass.py +++ b/pythonbpf/maps/maps_pass.py @@ -278,9 +278,7 @@ def process_bpf_map(func_node, module): if handler: return handler(map_name, rval, module) else: - logger.warning( - f"Unknown map type " f"{rval.func.id}, defaulting to HashMap" - ) + logger.warning(f"Unknown map type {rval.func.id}, defaulting to HashMap") return process_hash_map(map_name, rval, module) else: raise ValueError("Function under @map must return a map")