Utilities¶
This page documents the utility functions and classes used in LeanInteract.
Installation and Cache Management¶
install_lean
¶
Install Lean 4 version manager (elan) in a cross-platform compatible way. Uses platform-specific methods for Windows, macOS, and Linux.
Source code in src/lean_interact/utils.py
clear_cache
¶
Project Utilities¶
get_project_lean_version
¶
Get the Lean version used in a project.
Source code in src/lean_interact/utils.py
Windows Path Utilities¶
check_windows_long_paths
¶
Check if long paths are enabled if running on Windows.
Source code in src/lean_interact/utils.py
Memory Management¶
get_total_memory_usage
¶
Get total resident memory usage of a process and its children (in bytes).
Source code in src/lean_interact/utils.py
Code Processing Utilities¶
indent_code
¶
compress_newlines
¶
Source code in src/lean_interact/utils.py
lean_comments_ranges
¶
lean_comments_ranges(
lean_code: str,
multiline_comment_suffix: str = "",
remove_single_line_comments: bool = True,
) -> list[tuple[int, int]]
Extract the ranges of Lean comments from a Lean code snippet.
Source code in src/lean_interact/utils.py
remove_lean_comments
¶
Source code in src/lean_interact/utils.py
split_implementation
¶
Source code in src/lean_interact/utils.py
split_conclusion
¶
Source code in src/lean_interact/utils.py
clean_theorem_string
¶
clean_theorem_string(
theorem_string: str,
new_theorem_name: str = "dummy",
add_sorry: bool = True,
) -> str | None
Clean a theorem string by removing the proof, comments, and updating the theorem name. This method assumes that no other declarations are present in the theorem string.
Source code in src/lean_interact/utils.py
extract_last_theorem
¶
Extract the last theorem from a Lean code snippet. It assumes that the Lean code snippet ends with a theorem.
Source code in src/lean_interact/utils.py
clean_last_theorem_string
¶
clean_last_theorem_string(
lean_code: str,
new_theorem_name: str = "dummy",
add_sorry: bool = False,
) -> str
Clean the last theorem string from a Lean code snippet. It assumes that the Lean code snippet ends with a theorem.