feat: pretty output line

This commit is contained in:
Benjamin Lipp
2025-06-03 16:22:56 +02:00
parent 4bdc464b5b
commit 744cf6fb50
4 changed files with 60 additions and 17 deletions

View File

@@ -5,5 +5,4 @@
* call the old script from the Rosenpass repository's root directory with `./analyze.sh` * call the old script from the Rosenpass repository's root directory with `./analyze.sh`
* call the new script: * call the new script:
* in `analyze_py/marzipan`: `nix shell` * `nix run .# -- analyze $repo` where `$repo` is the absolute(?) path to the root directory of the Rosenpass repository.
* `src/analyze.sh analyze $repo` where `$repo` is the absolute(?) path to the root directory of the Rosenpass repository.

View File

@@ -14,7 +14,7 @@
## Next Steps ## Next Steps
* `pretty_output` Bash function * `pretty_output` Bash function
* pretty_output_line * ~~pretty_output_line~~
* awk RESULT flush in marzipan() * awk RESULT flush in marzipan()
* move the whole metaverif function to Python * move the whole metaverif function to Python
* move the whole analyze function to Python * move the whole analyze function to Python
@@ -25,4 +25,7 @@
* integrate this upstream, into the CI? * integrate this upstream, into the CI?
* “make it beautiful” steps? more resiliency to working directory? * “make it beautiful” steps? more resiliency to working directory?
* rewrite our awk usages into Python/…? * rewrite our awk usages into Python/…?
* yes, possibly as extension to the LARK grammar
* and rewrite the AST within Python
* reconstruct ProVerif input file for ProVerif
* rewrite our CPP usages into Python/…? * rewrite our CPP usages into Python/…?

View File

@@ -1,7 +1,8 @@
from .util import pkgs, setup_exports, export, rename from .util import pkgs, setup_exports, export, rename
from rich import print from rich import print as rich_print
import click import click
(__all__, export) = setup_exports() (__all__, export) = setup_exports()
export(setup_exports) export(setup_exports)
@@ -58,16 +59,58 @@ def awk_prep(cpp_prep, awk_prep):
@click.argument("color") @click.argument("color")
@click.argument("text") @click.argument("text")
def pretty_output_line(prefix, mark, color, text): def pretty_output_line(prefix, mark, color, text):
colored_prefix = f"[grey42]{prefix}[/grey42]" colored = f"[grey42]{prefix}[/grey42][{color}]{mark} {text}[/{color}]"
colored_mark_text = f"[{color}]{mark} {text}[/{color}]" rich_print(colored)
print(colored_prefix, colored_mark_text)
@click.command() @click.command()
@click.argument("file")
def pretty_output(file_path):
expected = []
descs = []
# Process lemmas first
with open(file_path, 'r') as file:
content = file.read()
expected += pkgs.re.findall(r'@(lemma)(?=\s+"[^\"]*")', content)
expected = ['true' if e == '@lemma' else e for e in expected]
descs += pkgs.re.findall(r'@(lemma)\s+"([^\"]*)"', content)
descs = [d[1] for d in descs]
# Then process regular queries
expected += pkgs.re.findall(r'@(query|reachable)(?=\s+"[^\"]*")', content)
expected = ['true' if e == '@query' else 'false' for e in expected]
descs += pkgs.re.findall(r'@(query|reachable)\s+"([^\"]*)"', content)
descs = [d[1] for d in descs]
res = 0
ctr = 0
ta = pkgs.time.time()
for outp in expected:
tz = pkgs.time.time()
if outp == expected[ctr]:
pretty_output_line(f"{int(tz - ta)}s ", "", "green", descs[ctr])
else:
res = 1
pretty_output_line(f"{int(tz - ta)}s ", "", "red", descs[ctr])
print()
ctr += 1
ta = tz
return res
@click.command()
@click.argument("command")
@click.argument("path") @click.argument("path")
def analyze(path): def analyze(command, path):
exc([ exc([
f"{pkgs.pathlib.Path(__file__).resolve().parent}/analyze.sh", f"{pkgs.pathlib.Path(__file__).resolve().parent}/analyze.sh",
command,
path path
]) ])
@@ -109,4 +152,5 @@ main.add_command(run_proverif)
main.add_command(cpp) main.add_command(cpp)
main.add_command(awk_prep) main.add_command(awk_prep)
main.add_command(pretty_output_line) main.add_command(pretty_output_line)
main.add_command(pretty_output)
main.add_command(clean_warnings) main.add_command(clean_warnings)

View File

@@ -16,20 +16,16 @@ clean_warnings() {
exc rosenpass-marzipan clean-warnings exc rosenpass-marzipan clean-warnings
} }
color_red='\033[0;31m' color_red='red'
color_green='\033[0;32m' color_green='green'
color_gray='\033[0;30m' color_gray='gray'
color_clear='\033[0m' color_clear=''
checkmark="✔" checkmark="✔"
cross="❌" cross="❌"
pretty_output_line() { pretty_output_line() {
local prefix; prefix="$1"; shift exc rosenpass-marzipan pretty-output-line "${@}"
local mark; mark="$1"; shift
local color; color="$1"; shift
local text; text="$1"; shift
echo -ne "\033[0\r${color_gray}${prefix}${color}${mark} ${text}${color_clear}"
} }
pretty_output() { pretty_output() {
@@ -138,6 +134,7 @@ main() {
case "${cmd}" in case "${cmd}" in
analyze) analyze ;; analyze) analyze ;;
pretty) pretty_output_line PREFIX MARK green TEXT ;;
clean_warnings) clean_warnings ;; clean_warnings) clean_warnings ;;
*) err_usage *) err_usage
esac esac