benchmark.py: uv run shebang, executable bit, stdlib-random shadowing guard
Fixes CI EXE001 (shebang on non-executable file). Running the script directly puts src/aeg on sys.path, where aeg/random.py would shadow the stdlib random module that secrets and others import — pop it before any imports so both direct execution and -m aeg.benchmark work.
This commit is contained in:
1 parent
b4404b42e6
commit
276b2faa0b
1 file changed
+12
-1
Regular → Executable
+12
-1
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
#!/usr/bin/env -S uv run
|
||||
"""
|
||||
Python benchmark matching src/test/benchmark.zig for all supported Aegis algorithms.
|
||||
|
||||
@@ -7,8 +7,19 @@ It performs two benchmarks with the same parameters as the Zig version:
|
||||
- AEGIS MAC (clone state pattern)
|
||||
|
||||
Output format and throughput units mirror the Zig benchmark (Mb/s).
|
||||
|
||||
Runnable directly (./src/aeg/benchmark.py) or as python -m aeg.benchmark.
|
||||
"""
|
||||
|
||||
# Direct execution puts this package's directory on sys.path, where our
|
||||
# random.py would shadow the stdlib random module — drop it before imports.
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
_pkg_dir = str(Path(__file__).resolve().parent)
|
||||
if sys.path and Path(sys.path[0]).resolve() == Path(_pkg_dir):
|
||||
sys.path.pop(0)
|
||||
|
||||
import secrets
|
||||
import time
|
||||
|
||||
|
||||
Reference in new issue
Block a user