Projects ¶
Module: lean_interact.project
This module provides classes for managing Lean projects, including local directories and git repositories.
It supports automatic building and dependency management using lake, and can be used to create temporary projects
with specific configurations.
It is useful for setting up Lean environments for development, testing, or running benchmarks without manual setup.
            LocalProject
  
      dataclass
  
¶
LocalProject(
    *,
    directory: str | PathLike,
    lake_path: str | PathLike = "lake",
    auto_build: bool = True,
)
              Bases: BaseProject
Configuration for using an existing local Lean project directory.
Examples:
# Use an existing local project
project = LocalProject(
    directory="/path/to/my/lean/project",
    auto_build=True  # Build the project automatically
)
config = LeanREPLConfig(project=project)
            lake_path
  
      class-attribute
      instance-attribute
  
¶
    The path to the lake executable. Default is "lake", which assumes it is in the system PATH.
            auto_build
  
      class-attribute
      instance-attribute
  
¶
    Whether to automatically build the project after instantiation.
get_directory ¶
get_lean_version ¶
The Lean version used by this project.
build ¶
Build the Lean project using lake.
Args:
    verbose: Whether to print building information to the console.
    update: Whether to run lake update before building.
    _lock: (internal parameter) Whether to acquire a file lock (should be False if already locked by caller).
Source code in src/lean_interact/project.py
              
            GitProject
  
      dataclass
  
¶
GitProject(
    *,
    directory: str | PathLike | None = None,
    lake_path: str | PathLike = "lake",
    auto_build: bool = True,
    url: str,
    rev: str | None = None,
    force_pull: bool = False,
)
              Bases: BaseProject
Configuration for using an online git repository containing a Lean project.
Examples:
# Clone and use a Git repository
project = GitProject(
    url="https://github.com/user/lean-project",
    rev="main",  # Optional: specific branch/tag/commit
    directory="/custom/cache/dir",  # Optional: custom directory
    force_pull=False  # Optional: force update on each use
)
config = LeanREPLConfig(project=project)
            directory
  
      class-attribute
      instance-attribute
  
¶
    The directory where the git project will be cloned. If None, a unique path inside the default LeanInteract cache directory will be used.
            rev
  
      class-attribute
      instance-attribute
  
¶
    The specific git revision (tag, branch, or commit hash) to checkout. If None, uses the default branch.
            force_pull
  
      class-attribute
      instance-attribute
  
¶
    Whether to force pull the latest changes from the remote repository, overwriting local changes.
            lake_path
  
      class-attribute
      instance-attribute
  
¶
    The path to the lake executable. Default is "lake", which assumes it is in the system PATH.
            auto_build
  
      class-attribute
      instance-attribute
  
¶
    Whether to automatically build the project after instantiation.
get_directory ¶
get_lean_version ¶
The Lean version used by this project.
build ¶
Build the Lean project using lake.
Args:
    verbose: Whether to print building information to the console.
    update: Whether to run lake update before building.
    _lock: (internal parameter) Whether to acquire a file lock (should be False if already locked by caller).
Source code in src/lean_interact/project.py
              
            TemporaryProject
  
      dataclass
  
¶
TemporaryProject(
    *,
    directory: str | PathLike | None = None,
    lake_path: str | PathLike = "lake",
    auto_build: bool = True,
    lean_version: str,
    verbose: bool = True,
    content: str,
    lakefile_type: Literal["lean", "toml"] = "lean",
)
              Bases: BaseTempProject
Configuration for creating a temporary Lean project with custom lakefile content.
Examples:
# Create a temporary project with custom lakefile
project = TemporaryProject(
    lean_version="v4.19.0",
    content="""
import Lake
open Lake DSL
package "my_temp_project" where
version := v!"0.1.0"
require mathlib from git
"https://github.com/leanprover-community/mathlib4.git" @ "v4.19.0"
""",
    lakefile_type="lean"  # or "toml"
)
config = LeanREPLConfig(project=project)
            content
  
      instance-attribute
  
¶
    The content to write to the lakefile (either lakefile.lean or lakefile.toml format).
            lakefile_type
  
      class-attribute
      instance-attribute
  
¶
    The type of lakefile to create. Either 'lean' for lakefile.lean or 'toml' for lakefile.toml.
            directory
  
      class-attribute
      instance-attribute
  
¶
    The directory where temporary Lean projects will be cached. If None, a unique path inside the default LeanInteract cache directory will be used.
            lake_path
  
      class-attribute
      instance-attribute
  
¶
    The path to the lake executable. Default is "lake", which assumes it is in the system PATH.
            auto_build
  
      class-attribute
      instance-attribute
  
¶
    Whether to automatically build the project after instantiation.
            verbose
  
      class-attribute
      instance-attribute
  
¶
    Whether to print additional information during the setup process.
get_directory ¶
get_lean_version ¶
The Lean version used by this project.
build ¶
Build the Lean project using lake.
Args:
    verbose: Whether to print building information to the console.
    update: Whether to run lake update before building.
    _lock: (internal parameter) Whether to acquire a file lock (should be False if already locked by caller).
Source code in src/lean_interact/project.py
              
            TempRequireProject
  
      dataclass
  
¶
TempRequireProject(
    *,
    directory: str | PathLike | None = None,
    lake_path: str | PathLike = "lake",
    auto_build: bool = True,
    lean_version: str,
    verbose: bool = True,
    require: Literal["mathlib"]
    | LeanRequire
    | list[LeanRequire | Literal["mathlib"]],
)
              Bases: BaseTempProject
Configuration for setting up a temporary project with specific dependencies.
As Mathlib is a common dependency, you can just set require="mathlib" and a compatible
version of mathlib will be used. This feature has been developed mostly to be able to run
benchmarks using Mathlib as a dependency (such as ProofNet# or MiniF2F) without having
to manually set up a Lean project.
Examples:
# Create a temporary project with Mathlib
project = TempRequireProject(
    lean_version="v4.19.0",
    require="mathlib"  # Shortcut for Mathlib
)
# Or with custom dependencies
project = TempRequireProject(
    lean_version="v4.19.0",
    require=[
        LeanRequire("mathlib", "https://github.com/leanprover-community/mathlib4.git", "v4.19.0"),
        LeanRequire("my_lib", "https://github.com/user/my-lib.git", "v1.0.0")
    ]
)
config = LeanREPLConfig(project=project)
            require
  
      instance-attribute
  
¶
require: (
    Literal["mathlib"]
    | LeanRequire
    | list[LeanRequire | Literal["mathlib"]]
)
The dependencies to include in the project. Can be:
- "mathlib" for automatic Mathlib dependency matching the Lean version
- A single LeanRequire object for a custom dependency
- A list of dependencies (mix of "mathlib" and LeanRequire objects)
            directory
  
      class-attribute
      instance-attribute
  
¶
    The directory where temporary Lean projects will be cached. If None, a unique path inside the default LeanInteract cache directory will be used.
            lake_path
  
      class-attribute
      instance-attribute
  
¶
    The path to the lake executable. Default is "lake", which assumes it is in the system PATH.
            auto_build
  
      class-attribute
      instance-attribute
  
¶
    Whether to automatically build the project after instantiation.
            verbose
  
      class-attribute
      instance-attribute
  
¶
    Whether to print additional information during the setup process.
get_directory ¶
get_lean_version ¶
The Lean version used by this project.
build ¶
Build the Lean project using lake.
Args:
    verbose: Whether to print building information to the console.
    update: Whether to run lake update before building.
    _lock: (internal parameter) Whether to acquire a file lock (should be False if already locked by caller).