Skip to content

Commit a0b0ad3

Browse files
Merge pull request #23 from pythonbpf/formatter
update formatter and pre-commit
2 parents bf78ac2 + 86b9ec5 commit a0b0ad3

File tree

6 files changed

+12
-17
lines changed

6 files changed

+12
-17
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ci:
2121
repos:
2222
# Standard hooks
2323
- repo: https://github.com/pre-commit/pre-commit-hooks
24-
rev: v4.6.0
24+
rev: v6.0.0
2525
hooks:
2626
- id: check-added-large-files
2727
- id: check-case-conflict
@@ -36,7 +36,7 @@ repos:
3636
- id: trailing-whitespace
3737

3838
- repo: https://github.com/astral-sh/ruff-pre-commit
39-
rev: "v0.4.2"
39+
rev: "v0.13.2"
4040
hooks:
4141
- id: ruff
4242
args: ["--fix", "--show-fixes"]
@@ -45,7 +45,7 @@ repos:
4545

4646
# Checking static types
4747
- repo: https://github.com/pre-commit/mirrors-mypy
48-
rev: "v1.10.0"
48+
rev: "v1.18.2"
4949
hooks:
5050
- id: mypy
5151
exclude: ^(tests)|^(examples)

examples/clone-matplotlib.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"from pythonbpf import bpf, map, section, bpfglobal, BPF\n",
1313
"from pythonbpf.helper import pid\n",
1414
"from pythonbpf.maps import HashMap\n",
15-
"from pylibbpf import *\n",
15+
"from pylibbpf import BpfMap\n",
1616
"from ctypes import c_void_p, c_int64, c_uint64, c_int32\n",
1717
"import matplotlib.pyplot as plt"
1818
]

pythonbpf/functions_pass.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ def handle_assign(
146146
local_sym_tab[var_name].var,
147147
)
148148
logger.info(
149-
f"Assigned {call_type} constant "
150-
f"{rval.args[0].value} to {var_name}"
149+
f"Assigned {call_type} constant {rval.args[0].value} to {var_name}"
151150
)
152151
elif HelperHandlerRegistry.has_handler(call_type):
153152
# var = builder.alloca(ir.IntType(64), name=var_name)
@@ -483,8 +482,7 @@ def allocate_mem(
483482
var = builder.alloca(ir_type, name=var_name)
484483
has_metadata = True
485484
logger.info(
486-
f"Pre-allocated variable {var_name} "
487-
f"for struct {call_type}"
485+
f"Pre-allocated variable {var_name} for struct {call_type}"
488486
)
489487
elif isinstance(rval.func, ast.Attribute):
490488
ir_type = ir.PointerType(ir.IntType(64))

pythonbpf/helper/bpf_helper_handler.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def bpf_map_lookup_elem_emitter(
6262
"""
6363
if not call.args or len(call.args) != 1:
6464
raise ValueError(
65-
"Map lookup expects exactly one argument (key), got " f"{len(call.args)}"
65+
f"Map lookup expects exactly one argument (key), got {len(call.args)}"
6666
)
6767
key_ptr = get_or_create_ptr_from_arg(call.args[0], builder, local_sym_tab)
6868
map_void_ptr = builder.bitcast(map_ptr, ir.PointerType())
@@ -145,8 +145,7 @@ def bpf_map_update_elem_emitter(
145145
"""
146146
if not call.args or len(call.args) < 2 or len(call.args) > 3:
147147
raise ValueError(
148-
"Map update expects 2 or 3 args (key, value, flags), "
149-
f"got {len(call.args)}"
148+
f"Map update expects 2 or 3 args (key, value, flags), got {len(call.args)}"
150149
)
151150

152151
key_arg = call.args[0]
@@ -196,7 +195,7 @@ def bpf_map_delete_elem_emitter(
196195
"""
197196
if not call.args or len(call.args) != 1:
198197
raise ValueError(
199-
"Map delete expects exactly one argument (key), got " f"{len(call.args)}"
198+
f"Map delete expects exactly one argument (key), got {len(call.args)}"
200199
)
201200
key_ptr = get_or_create_ptr_from_arg(call.args[0], builder, local_sym_tab)
202201
map_void_ptr = builder.bitcast(map_ptr, ir.PointerType())
@@ -255,7 +254,7 @@ def bpf_perf_event_output_handler(
255254
):
256255
if len(call.args) != 1:
257256
raise ValueError(
258-
"Perf event output expects exactly one argument, " f"got {len(call.args)}"
257+
f"Perf event output expects exactly one argument, got {len(call.args)}"
259258
)
260259
data_arg = call.args[0]
261260
ctx_ptr = func.args[0] # First argument to the function is ctx

pythonbpf/helper/helper_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def _prepare_expr_args(expr, func, module, builder, local_sym_tab, struct_sym_ta
270270
val = builder.sext(val, ir.IntType(64))
271271
else:
272272
logger.warning(
273-
"Only int and ptr supported in bpf_printk args. " "Others default to 0."
273+
"Only int and ptr supported in bpf_printk args. Others default to 0."
274274
)
275275
val = ir.Constant(ir.IntType(64), 0)
276276
return val

pythonbpf/maps/maps_pass.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,7 @@ def process_bpf_map(func_node, module):
278278
if handler:
279279
return handler(map_name, rval, module)
280280
else:
281-
logger.warning(
282-
f"Unknown map type " f"{rval.func.id}, defaulting to HashMap"
283-
)
281+
logger.warning(f"Unknown map type {rval.func.id}, defaulting to HashMap")
284282
return process_hash_map(map_name, rval, module)
285283
else:
286284
raise ValueError("Function under @map must return a map")

0 commit comments

Comments
 (0)