Utilities API¶
This page documents the utility functions and classes used in LeanInteract.
Installation and Cache Management¶
lean_interact.utils.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 lean_interact/utils.py
lean_interact.utils.clear_cache()
¶
Project Utilities¶
lean_interact.utils.get_project_lean_version(project_dir)
¶
Get the Lean version used in a project.
Source code in lean_interact/utils.py
Windows Path Utilities¶
lean_interact.utils.check_windows_long_paths()
¶
Check if long paths are enabled if running on Windows.
Source code in lean_interact/utils.py
Memory Management¶
lean_interact.utils.get_total_memory_usage(proc)
¶
Get total resident memory usage of a process and its children (in bytes).
Source code in lean_interact/utils.py
lean_interact.utils._limit_memory(max_mb)
¶
Limit the memory usage of the current process.
Source code in lean_interact/utils.py
Code Processing Utilities¶
lean_interact.utils.indent_code(code, nb_spaces=2)
¶
lean_interact.utils.compress_newlines(lean_code)
¶
Source code in lean_interact/utils.py
lean_interact.utils.lean_comments_ranges(lean_code, multiline_comment_suffix='', remove_single_line_comments=True)
¶
Extract the ranges of Lean comments from a Lean code snippet.
Source code in lean_interact/utils.py
lean_interact.utils.remove_lean_comments(lean_code)
¶
Source code in lean_interact/utils.py
lean_interact.utils.split_implementation(declaration, start=0)
¶
Source code in lean_interact/utils.py
lean_interact.utils.split_conclusion(declaration, start=0)
¶
Source code in lean_interact/utils.py
lean_interact.utils.clean_theorem_string(theorem_string, new_theorem_name='dummy', add_sorry=True)
¶
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 lean_interact/utils.py
lean_interact.utils.extract_last_theorem(lean_code)
¶
Extract the last theorem from a Lean code snippet. It assumes that the Lean code snippet ends with a theorem.
Source code in lean_interact/utils.py
lean_interact.utils.clean_last_theorem_string(lean_code, new_theorem_name='dummy', add_sorry=False)
¶
Clean the last theorem string from a Lean code snippet. It assumes that the Lean code snippet ends with a theorem.