From b118792cf43e8892eee1689d5f3e46a7c9e3d16a Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Thu, 2 May 2024 15:45:25 +0300 Subject: [PATCH] refactor env --- benchmarks/create_circuits.nim | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/benchmarks/create_circuits.nim b/benchmarks/create_circuits.nim index cfc081e4..fb98e496 100644 --- a/benchmarks/create_circuits.nim +++ b/benchmarks/create_circuits.nim @@ -1,6 +1,5 @@ import std/[hashes, json, strutils, strformat, os, osproc] - type CircuitEnv* = object nimCircuitCli*: string @@ -21,14 +20,20 @@ type ncells*: int index*: int +proc findCodexProjectDir(): string = + ## find codex proj dir -- assumes this script is in codex/benchmarks + result = currentSourcePath().parentDir.parentDir + func default*(tp: typedesc[CircuitEnv]): CircuitEnv = - result.nimCircuitCli = "vendor" / "codex-storage-proofs-circuits" / "reference" / "nim" / "proof_input" / "cli" - result.circuitDirIncludes = "vendor" / "codex-storage-proofs-circuits" / "circuit" - result.ptauPath = "benchmarks" / "ceremony" / "powersOfTau28_hez_final_23.ptau" + let codexDir = findCodexProjectDir() + result.nimCircuitCli = codexDir / "vendor" / "codex-storage-proofs-circuits" / "reference" / "nim" / "proof_input" / "cli" + result.circuitDirIncludes = codexDir / "vendor" / "codex-storage-proofs-circuits" / "circuit" + result.ptauPath = codexDir / "benchmarks" / "ceremony" / "powersOfTau28_hez_final_23.ptau" result.ptauUrl = "https://storage.googleapis.com/zkevm/ptau/" - result.codexProjDir = "" + result.codexProjDir = codexDir template withDir(dir: string, blk: untyped) = + ## set working dir for duration of blk let prev = getCurrentDir() try: setCurrentDir(dir) @@ -42,10 +47,6 @@ template runit(cmd: string) = echo "STATUS: ", cmdRes assert cmdRes == 0 -proc findCodexProjectDir(): string = - ## check that the CWD of script is in the codex parent - result = currentSourcePath.parentDir() - proc checkEnv*(env: var CircuitEnv) = ## check that the CWD of script is in the codex parent let codexProjDir = findCodexProjectDir() @@ -82,13 +83,8 @@ proc checkEnv*(env: var CircuitEnv) = echo "CWD: ", getCurrentDir() assert env.nimCircuitCli.fileExists() - env.nimCircuitCli = env.nimCircuitCli.absolutePath() echo "Found NimCircuitCli: ", env.nimCircuitCli - - env.circuitDirIncludes = env.circuitDirIncludes.absolutePath echo "Found Circuit Path: ", env.circuitDirIncludes - - env.ptauPath = env.ptauPath.absolutePath echo "Found PTAU file: ", env.ptauPath proc downloadPtau*(ptauPath, ptauUrl: string) =