Fix pre-commit conditions

This commit is contained in:
Pragyansh Chaturvedi
2025-10-20 04:05:14 +05:30
parent ddbbce400e
commit b7aa0807c5
6 changed files with 31 additions and 27 deletions

View File

@ -10,7 +10,6 @@ include_directories(${CMAKE_SOURCE_DIR}/src)
add_subdirectory(pybind11)
pybind11_add_module(
pylibbpf
# Core
src/core/bpf_program.h
src/core/bpf_exception.h
@ -19,15 +18,12 @@ pybind11_add_module(
src/core/bpf_program.cpp
src/core/bpf_map.cpp
src/core/bpf_object.cpp
# Maps
src/maps/perf_event_array.h
src/maps/perf_event_array.cpp
# Utils
src/utils/struct_parser.h
src/utils/struct_parser.cpp
# Bindings
src/bindings/main.cpp)

View File

@ -1,10 +1,11 @@
import time
from ctypes import c_int32, c_int64, c_uint64, c_void_p
from pylibbpf import BpfMap
from pythonbpf import BPF, bpf, bpfglobal, map, section
from pythonbpf.maps import HashMap
from pylibbpf import BpfMap
@bpf
@map

View File

@ -1,14 +1,17 @@
import logging
from .ir_to_ctypes import convert_structs_to_ctypes, is_pythonbpf_structs
from .pylibbpf import (
BpfObject as _BpfObject, # C++ object (internal)
BpfProgram,
BpfException,
BpfMap,
BpfProgram,
PerfEventArray,
StructParser,
BpfException,
)
from .pylibbpf import (
BpfObject as _BpfObject, # C++ object (internal)
)
from .wrappers import BpfObjectWrapper
from .ir_to_ctypes import convert_structs_to_ctypes, is_pythonbpf_structs
logger = logging.getLogger(__name__)

View File

@ -1,7 +1,8 @@
import ctypes
from typing import Dict, Type
from llvmlite import ir
import logging
from typing import Dict, Type
from llvmlite import ir
logger = logging.getLogger(__name__)
@ -54,12 +55,18 @@ def convert_structs_to_ctypes(structs_sym_tab) -> Dict[str, Type[ctypes.Structur
struct_class = type(
struct_name,
(ctypes.Structure,),
{'_fields_': fields, '__module__': 'pylibbpf.ir_to_ctypes', '__doc__': f'Auto-generated ctypes structure for {struct_name}',
'__repr__': lambda self: (
f"<{struct_name} " +
" ".join(f"{name}={getattr(self, name)}" for name, _ in fields) +
">"
)}
{
"_fields_": fields,
"__module__": "pylibbpf.ir_to_ctypes",
"__doc__": f"Auto-generated ctypes structure for {struct_name}",
"__repr__": lambda self: (
f"<{struct_name} "
+ " ".join(
f"{name}={getattr(self, name)}" for name, _ in fields
)
+ ">"
),
},
)
ctypes_structs[struct_name] = struct_class
@ -80,9 +87,9 @@ def is_pythonbpf_structs(structs) -> bool:
first_value = next(iter(structs.values()))
return (
hasattr(first_value, 'ir_type') and
hasattr(first_value, 'fields') and
hasattr(first_value, 'size')
hasattr(first_value, "ir_type")
and hasattr(first_value, "fields")
and hasattr(first_value, "size")
)

View File

@ -13,7 +13,7 @@ class PerfEventArrayHelper:
callback: Callable,
struct_name: str = "",
page_cnt: int = 8,
lost_callback: Optional[Callable] = None
lost_callback: Optional[Callable] = None,
):
"""Open perf buffer with auto-deserialization."""
from .pylibbpf import PerfEventArray
@ -24,14 +24,11 @@ class PerfEventArrayHelper:
page_cnt,
callback,
struct_name,
lost_callback or (lambda cpu, cnt: None)
lost_callback or (lambda cpu, cnt: None),
)
else:
self._perf_buffer = PerfEventArray(
self._map,
page_cnt,
callback,
lost_callback or (lambda cpu, cnt: None)
self._map, page_cnt, callback, lost_callback or (lambda cpu, cnt: None)
)
return self

View File

@ -3,7 +3,7 @@ import subprocess
import sys
from pathlib import Path
from setuptools import Extension, setup, find_packages
from setuptools import Extension, find_packages, setup
from setuptools.command.build_ext import build_ext
# Convert distutils Windows platform specifiers to CMake -A arguments