Skip to content

Commit 8d50679

Browse files
format chore and pre commit hook addition
1 parent 8658143 commit 8d50679

37 files changed

+83186
-82670
lines changed

.github/workflows/format.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This is a format job. Pre-commit has a first-party GitHub action, so we use
2+
# that: https://github.com/pre-commit/action
3+
4+
name: Format
5+
6+
on:
7+
workflow_dispatch:
8+
pull_request:
9+
push:
10+
branches:
11+
- master
12+
13+
jobs:
14+
pre-commit:
15+
name: Format
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.x"
22+
- uses: pre-commit/action@v3.0.1

.pre-commit-config.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# To use:
2+
#
3+
# pre-commit run -a
4+
#
5+
# Or:
6+
#
7+
# pre-commit install # (runs every time you commit in git)
8+
#
9+
# To update this file:
10+
#
11+
# pre-commit autoupdate
12+
#
13+
# See https://github.com/pre-commit/pre-commit
14+
15+
exclude: 'vmlinux.*\.py$'
16+
17+
ci:
18+
autoupdate_commit_msg: "chore: update pre-commit hooks"
19+
autofix_commit_msg: "style: pre-commit fixes"
20+
21+
repos:
22+
# Standard hooks
23+
- repo: https://github.com/pre-commit/pre-commit-hooks
24+
rev: v4.6.0
25+
hooks:
26+
- id: check-added-large-files
27+
- id: check-case-conflict
28+
- id: check-merge-conflict
29+
- id: check-symlinks
30+
- id: check-yaml
31+
exclude: ^conda\.recipe/meta\.yaml$
32+
- id: debug-statements
33+
- id: end-of-file-fixer
34+
- id: mixed-line-ending
35+
- id: requirements-txt-fixer
36+
- id: trailing-whitespace
37+
38+
#- repo: https://github.com/astral-sh/ruff-pre-commit
39+
# rev: "v0.4.2"
40+
# hooks:
41+
# - id: ruff
42+
# args: ["--fix", "--show-fixes"]
43+
# - id: ruff-format
44+
# exclude: ^(docs)
45+
46+
## Checking static types
47+
#- repo: https://github.com/pre-commit/mirrors-mypy
48+
# rev: "v1.10.0"
49+
# hooks:
50+
# - id: mypy
51+
# files: "setup.py"
52+
# args: []
53+
# additional_dependencies: [types-setuptools]
54+
55+
# Changes tabs to spaces
56+
- repo: https://github.com/Lucas-C/pre-commit-hooks
57+
rev: v1.5.5
58+
hooks:
59+
- id: remove-tabs
60+
exclude: '^(docs)|.*/Makefile$|Makefile$'

LICENSE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,3 @@
200200
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201201
See the License for the specific language governing permissions and
202202
limitations under the License.
203-

examples/binops_demo.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# 3. Run the program with sudo: sudo tools/check.sh run examples/binops_demo.py
1111
# 4. Start up any program and watch the output
1212

13+
1314
@bpf
1415
@map
1516
def last() -> HashMap:
@@ -23,26 +24,28 @@ def do_trace(ctx: c_void_p) -> c_int64:
2324
tsp = last().lookup(key)
2425
if tsp:
2526
kt = ktime()
26-
delta = (kt - tsp)
27+
delta = kt - tsp
2728
if delta < 1000000000:
28-
time_ms = (delta // 1000000)
29+
time_ms = delta // 1000000
2930
print(f"Execve syscall entered within last second, last {time_ms} ms ago")
3031
last().delete(key)
3132
else:
3233
kt = ktime()
3334
last().update(key, kt)
3435
return c_int64(0)
3536

37+
3638
@bpf
3739
@section("tracepoint/syscalls/sys_exit_execve")
3840
def do_exit(ctx: c_void_p) -> c_int64:
3941
va = 8
4042
nm = 5 ^ va
4143
al = 6 & 3
42-
ru = (nm + al)
44+
ru = nm + al
4345
print(f"this is a variable {ru}")
4446
return c_int64(0)
4547

48+
4649
@bpf
4750
@bpfglobal
4851
def LICENSE() -> str:

examples/blk_request.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
from pythonbpf import bpf, map, section, bpfglobal, compile
2-
from pythonbpf.helpers import ktime, deref
2+
from pythonbpf.helpers import ktime
33
from pythonbpf.maps import HashMap
44

5-
from ctypes import c_void_p, c_int64, c_int32, c_uint64
5+
from ctypes import c_void_p, c_int32, c_uint64
66

77

88
@bpf
99
@map
1010
def last() -> HashMap:
1111
return HashMap(key=c_uint64, value=c_uint64, max_entries=3)
1212

13+
1314
@bpf
1415
@section("blk_start_request")
1516
def trace_start(ctx: c_void_p) -> c_int32:
1617
ts = ktime()
17-
print("req started")
18+
print(f"req started {ts}")
1819
return c_int32(0)
1920

2021

examples/clone_plot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
# Everything is done with Python only code and with the new pylibbpf library.
1515
# Run `sudo /path/to/python/binary/ clone_plot.py`
1616

17+
1718
@bpf
1819
@map
1920
def hist() -> HashMap:
2021
return HashMap(key=c_int32, value=c_uint64, max_entries=4096)
2122

23+
2224
@bpf
2325
@section("tracepoint/syscalls/sys_enter_clone")
2426
def hello(ctx: c_void_p) -> c_int64:

examples/hello_world.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pythonbpf import bpf, section, bpfglobal, compile, BPF
1+
from pythonbpf import bpf, section, bpfglobal, BPF
22
from ctypes import c_void_p, c_int64
33

44
# Instructions to how to run this program
@@ -13,11 +13,13 @@ def hello_world(ctx: c_void_p) -> c_int64:
1313
print("Hello, World!")
1414
return c_int64(0)
1515

16+
1617
@bpf
1718
@bpfglobal
1819
def LICENSE() -> str:
1920
return "GPL"
2021

22+
2123
b = BPF()
2224
b.load_and_attach()
2325
if b.is_loaded() and b.is_attached():

examples/struct_and_perf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pythonbpf.helpers import ktime, pid
33
from pythonbpf.maps import PerfEventArray
44

5-
from ctypes import c_void_p, c_int64, c_int32, c_uint64
5+
from ctypes import c_void_p, c_int32, c_uint64
66

77

88
@bpf

examples/sys_sync.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# 3. Run the program with sudo: sudo tools/check.sh run examples/sys_sync.o
1111
# 4. Start a Python repl and `import os` and then keep entering `os.sync()` to see reponses.
1212

13+
1314
@bpf
1415
@map
1516
def last() -> HashMap:
@@ -23,9 +24,9 @@ def do_trace(ctx: c_void_p) -> c_int64:
2324
tsp = last().lookup(key)
2425
if tsp:
2526
kt = ktime()
26-
delta = (kt - tsp)
27+
delta = kt - tsp
2728
if delta < 1000000000:
28-
time_ms = (delta // 1000000)
29+
time_ms = delta // 1000000
2930
print(f"sync called within last second, last {time_ms} ms ago")
3031
last().delete(key)
3132
else:

examples/vmlinux.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def __getattr__(self, _):
149149

150150
# libraries['FIXME_STUB'] explanation
151151
# As you did not list (-l libraryname.so) a library that exports this function
152-
# This is a non-working stub instead.
152+
# This is a non-working stub instead.
153153
# You can either re-run clan2py with -l /path/to/library.so
154154
# Or manually fix this by comment the ctypes.CDLL loading
155155
_libraries = {}

0 commit comments

Comments
 (0)