mirror of
https://github.com/Z3Prover/z3
synced 2026-07-19 05:25:48 +00:00
simplify skill scripts: expose find_repo_root, fix split string, simplify label
- z3db.py: rename _find_repo_root to find_repo_root (make public) and add require_repo_root helper that exits on failure; update docstring and internal caller; fix unnecessary string literal split in log() - memory_safety.py: remove 13-line duplicate find_repo_root function; import and use require_repo_root from z3db instead - static_analysis.py: simplify two-line label assignment in print_findings to a single expression using 'or' Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
59bb444694
commit
4dec7b1324
3 changed files with 17 additions and 22 deletions
18
.github/skills/shared/z3db.py
vendored
18
.github/skills/shared/z3db.py
vendored
|
|
@ -3,7 +3,7 @@
|
|||
z3db: shared library and CLI for Z3 skill scripts.
|
||||
|
||||
Library usage:
|
||||
from z3db import Z3DB, find_z3, run_z3
|
||||
from z3db import Z3DB, find_z3, run_z3, find_repo_root, require_repo_root
|
||||
|
||||
CLI usage:
|
||||
python z3db.py init
|
||||
|
|
@ -131,7 +131,7 @@ class Z3DB:
|
|||
"""Write to stderr and to the interaction_log table."""
|
||||
getattr(logger, level, logger.info)(message)
|
||||
self.conn.execute(
|
||||
"INSERT INTO interaction_log (run_id, level, message) " "VALUES (?, ?, ?)",
|
||||
"INSERT INTO interaction_log (run_id, level, message) VALUES (?, ?, ?)",
|
||||
(run_id, level, message),
|
||||
)
|
||||
self.conn.commit()
|
||||
|
|
@ -182,7 +182,7 @@ def find_z3(hint: str = None) -> str:
|
|||
if hint:
|
||||
candidates.append(hint)
|
||||
|
||||
repo_root = _find_repo_root()
|
||||
repo_root = find_repo_root()
|
||||
if repo_root:
|
||||
for build_dir in ["build", "build/release", "build/debug"]:
|
||||
candidates.append(str(repo_root / build_dir / "z3"))
|
||||
|
|
@ -201,7 +201,8 @@ def find_z3(hint: str = None) -> str:
|
|||
sys.exit(1)
|
||||
|
||||
|
||||
def _find_repo_root() -> Optional[Path]:
|
||||
def find_repo_root() -> Optional[Path]:
|
||||
"""Walk up from cwd looking for the Z3 repository root."""
|
||||
d = Path.cwd()
|
||||
for _ in range(10):
|
||||
if (d / "CMakeLists.txt").exists() and (d / "src").is_dir():
|
||||
|
|
@ -213,6 +214,15 @@ def _find_repo_root() -> Optional[Path]:
|
|||
return None
|
||||
|
||||
|
||||
def require_repo_root() -> Path:
|
||||
"""Return the Z3 repo root, or exit with an error message if not found."""
|
||||
root = find_repo_root()
|
||||
if root is None:
|
||||
logger.error("could not locate Z3 repository root")
|
||||
sys.exit(1)
|
||||
return root
|
||||
|
||||
|
||||
def run_z3(
|
||||
formula: str,
|
||||
z3_bin: str = None,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue