lean-interact 0.7.0__tar.gz → 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lean_interact-0.8.0/.github/ISSUE_TEMPLATE/bug_report.md +24 -0
- lean_interact-0.8.0/.github/copilot-instructions.md +134 -0
- {lean_interact-0.7.0 → lean_interact-0.8.0}/.github/workflows/ci.yml +1 -1
- lean_interact-0.8.0/.github/workflows/docs.yml +113 -0
- {lean_interact-0.7.0 → lean_interact-0.8.0}/PKG-INFO +30 -26
- {lean_interact-0.7.0 → lean_interact-0.8.0}/README.md +29 -25
- lean_interact-0.8.0/docs/api/config.md +7 -0
- lean_interact-0.8.0/docs/api/interface.md +26 -0
- lean_interact-0.8.0/docs/api/project.md +11 -0
- lean_interact-0.8.0/docs/api/server.md +8 -0
- lean_interact-0.8.0/docs/api/sessioncache.md +9 -0
- lean_interact-0.8.0/docs/api/utils.md +69 -0
- lean_interact-0.8.0/docs/contributing.md +71 -0
- lean_interact-0.8.0/docs/generate_changelog.py +136 -0
- {lean_interact-0.7.0 → lean_interact-0.8.0}/docs/index.md +7 -2
- lean_interact-0.8.0/docs/theme/main.html +8 -0
- {lean_interact-0.7.0 → lean_interact-0.8.0}/docs/user-guide/custom-lean-configuration.md +42 -18
- {lean_interact-0.7.0/docs → lean_interact-0.8.0/docs/user-guide}/examples.md +1 -1
- {lean_interact-0.7.0/docs → lean_interact-0.8.0/docs/user-guide}/installation.md +1 -5
- {lean_interact-0.7.0/docs → lean_interact-0.8.0/docs/user-guide}/troubleshooting.md +5 -6
- {lean_interact-0.7.0 → lean_interact-0.8.0}/examples/beq_plus.py +4 -4
- {lean_interact-0.7.0 → lean_interact-0.8.0}/examples/proof_generation_and_autoformalization.py +1 -1
- {lean_interact-0.7.0 → lean_interact-0.8.0}/examples/type_check.py +2 -2
- {lean_interact-0.7.0 → lean_interact-0.8.0}/mkdocs.yml +41 -13
- {lean_interact-0.7.0 → lean_interact-0.8.0}/pyproject.toml +5 -2
- {lean_interact-0.7.0 → lean_interact-0.8.0}/src/lean_interact/__init__.py +8 -8
- lean_interact-0.8.0/src/lean_interact/config.py +455 -0
- {lean_interact-0.7.0 → lean_interact-0.8.0}/src/lean_interact/interface.py +151 -141
- lean_interact-0.8.0/src/lean_interact/project.py +480 -0
- {lean_interact-0.7.0 → lean_interact-0.8.0}/src/lean_interact/server.py +134 -45
- {lean_interact-0.7.0 → lean_interact-0.8.0}/src/lean_interact/sessioncache.py +47 -15
- {lean_interact-0.7.0 → lean_interact-0.8.0}/src/lean_interact/utils.py +33 -9
- {lean_interact-0.7.0 → lean_interact-0.8.0}/tests/test_concurrency.py +19 -11
- {lean_interact-0.7.0 → lean_interact-0.8.0}/tests/test_git_functionality.py +17 -26
- {lean_interact-0.7.0 → lean_interact-0.8.0}/tests/test_server.py +66 -22
- {lean_interact-0.7.0 → lean_interact-0.8.0}/uv.lock +139 -1
- lean_interact-0.7.0/.github/workflows/docs.yml +0 -70
- lean_interact-0.7.0/.github/workflows/update-changelog.yml +0 -38
- lean_interact-0.7.0/docs/api/config.md +0 -90
- lean_interact-0.7.0/docs/api/interface.md +0 -121
- lean_interact-0.7.0/docs/api/server.md +0 -34
- lean_interact-0.7.0/docs/api/sessioncache.md +0 -52
- lean_interact-0.7.0/docs/api/utils.md +0 -98
- lean_interact-0.7.0/docs/changelog.md +0 -105
- lean_interact-0.7.0/docs/contributing.md +0 -72
- lean_interact-0.7.0/docs/update_changelog.py +0 -156
- lean_interact-0.7.0/src/lean_interact/config.py +0 -804
- {lean_interact-0.7.0 → lean_interact-0.8.0}/.devcontainer/devcontainer.json +0 -0
- {lean_interact-0.7.0 → lean_interact-0.8.0}/.github/workflows/publish-to-pypi.yml +0 -0
- {lean_interact-0.7.0 → lean_interact-0.8.0}/.gitignore +0 -0
- {lean_interact-0.7.0 → lean_interact-0.8.0}/LICENSE +0 -0
- {lean_interact-0.7.0 → lean_interact-0.8.0}/docs/.nojekyll +0 -0
- {lean_interact-0.7.0 → lean_interact-0.8.0}/docs/user-guide/basic-usage.md +0 -0
- {lean_interact-0.7.0 → lean_interact-0.8.0}/docs/user-guide/getting-started.md +0 -0
- {lean_interact-0.7.0 → lean_interact-0.8.0}/docs/user-guide/tactic-mode.md +0 -0
- {lean_interact-0.7.0 → lean_interact-0.8.0}/tests/test_utils.py +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Create a report to help us improve
|
|
4
|
+
title: "[BUG]"
|
|
5
|
+
labels: ''
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**Describe the bug**
|
|
11
|
+
A clear and concise description of what the bug is.
|
|
12
|
+
|
|
13
|
+
**To Reproduce**
|
|
14
|
+
Your environment:
|
|
15
|
+
- OS: Linux, macOS, Windows, ...
|
|
16
|
+
- Python version
|
|
17
|
+
- LeanInteract version (`pip show lean-interact`)
|
|
18
|
+
Then the steps to reproduce the behavior.
|
|
19
|
+
|
|
20
|
+
**Expected behavior**
|
|
21
|
+
A clear and concise description of what you expected to happen.
|
|
22
|
+
|
|
23
|
+
**Additional context**
|
|
24
|
+
Add any other context about the problem here.
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# LeanInteract AI Coding Guidelines
|
|
2
|
+
|
|
3
|
+
## Project Overview
|
|
4
|
+
LeanInteract is a Python package that provides a high-level interface to the Lean 4 theorem prover through the Lean REPL. It abstracts project setup, dependency management, and REPL communication to enable seamless Lean-Python integration for theorem proving, autoformalization, and mathematical verification tasks.
|
|
5
|
+
|
|
6
|
+
## Architecture Overview
|
|
7
|
+
|
|
8
|
+
### Core Components
|
|
9
|
+
- **Projects**: Self-contained Lean project configurations that handle their own setup and building
|
|
10
|
+
- **REPL Configuration**: Manages REPL-specific settings
|
|
11
|
+
- **Servers**: Thread-safe wrappers around Lean REPL processes with async support
|
|
12
|
+
- **Interface**: Pydantic models for type-safe communication with Lean REPL
|
|
13
|
+
|
|
14
|
+
### Project Instantiation Pattern
|
|
15
|
+
```python
|
|
16
|
+
# Projects are instantiated independently and passed to config
|
|
17
|
+
project = TempRequireProject(lean_version="v4.8.0", require="mathlib")
|
|
18
|
+
config = LeanREPLConfig(project=project)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Key Project Types
|
|
22
|
+
- `LocalProject(directory="path")`: Existing local Lean projects
|
|
23
|
+
- `GitProject(url="...", rev="...")`: Auto-cloning git repositories
|
|
24
|
+
- `TempRequireProject(lean_version="...", require=[...])`: Temporary projects with dependencies
|
|
25
|
+
- `TemporaryProject(lean_version="...", content="...")`: Custom lakefile content
|
|
26
|
+
|
|
27
|
+
## Critical Development Patterns
|
|
28
|
+
|
|
29
|
+
### File Locking for Concurrency
|
|
30
|
+
All project operations use `FileLock(f"{directory}.lock")` to prevent race conditions during setup:
|
|
31
|
+
```python
|
|
32
|
+
with FileLock(f"{directory}.lock"):
|
|
33
|
+
# Setup operations here
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Environment State Management
|
|
37
|
+
Commands return `CommandResponse` with `env` field for chaining:
|
|
38
|
+
```python
|
|
39
|
+
result1 = server.run(Command(cmd="def x := 1"))
|
|
40
|
+
result2 = server.run(Command(cmd="def y := x + 1", env=result1.env))
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Thread-Safe Server Operations
|
|
44
|
+
Both sync and async operations use internal locking:
|
|
45
|
+
```python
|
|
46
|
+
# Synchronous
|
|
47
|
+
result = server.run(Command(cmd="..."))
|
|
48
|
+
# Asynchronous
|
|
49
|
+
result = await server.async_run(Command(cmd="..."))
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Testing Conventions
|
|
53
|
+
|
|
54
|
+
### Configuration Setup
|
|
55
|
+
Always pre-instantiate config for multiprocessing tests:
|
|
56
|
+
```python
|
|
57
|
+
@classmethod
|
|
58
|
+
def setUpClass(cls):
|
|
59
|
+
cls.config = LeanREPLConfig(cache_dir=tempfile.mkdtemp())
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Concurrency Testing
|
|
63
|
+
Use `mp.get_context("spawn")` for cross-platform process spawning and proper timeout handling:
|
|
64
|
+
```python
|
|
65
|
+
ctx = mp.get_context("spawn")
|
|
66
|
+
p = ctx.Process(target=worker_func, args=(config,))
|
|
67
|
+
p.start()
|
|
68
|
+
p.join(timeout=60)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### First-Time Setup Timeouts
|
|
72
|
+
Initial Lean setup can take minutes - use generous timeouts (60s+) for setup-related tests.
|
|
73
|
+
|
|
74
|
+
## Build & Development Workflow
|
|
75
|
+
|
|
76
|
+
### Essential Commands
|
|
77
|
+
- **All scripts, tests, and commands should be run using [`uv`](https://github.com/astral-sh/uv) for speed and reproducibility.**
|
|
78
|
+
- **Tests are run with the standard `unittest` framework, not pytest.**
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Setup: Install with dev dependencies
|
|
82
|
+
uv pip install -e ".[dev]"
|
|
83
|
+
|
|
84
|
+
# Testing: Run all tests with unittest
|
|
85
|
+
uv run python -m unittest discover tests
|
|
86
|
+
# Or run a specific test module
|
|
87
|
+
uv run python -m unittest tests/test_server.py
|
|
88
|
+
uv run python -m unittest tests/test_concurrency.py
|
|
89
|
+
|
|
90
|
+
# Documentation: Local preview
|
|
91
|
+
uv run mkdocs serve
|
|
92
|
+
|
|
93
|
+
# Cache management
|
|
94
|
+
uv run clear-lean-cache # Clear all cached projects
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Project Structure
|
|
98
|
+
- `src/lean_interact/`: Core package modules
|
|
99
|
+
- `tests/`: Comprehensive test suite with concurrency tests
|
|
100
|
+
- `examples/`: Real-world usage examples (autoformalization, benchmarks)
|
|
101
|
+
- `docs/`: MkDocs documentation with API reference
|
|
102
|
+
|
|
103
|
+
## Integration Patterns
|
|
104
|
+
|
|
105
|
+
### Error Handling
|
|
106
|
+
Commands can return `LeanError` instead of `CommandResponse`:
|
|
107
|
+
```python
|
|
108
|
+
result = server.run(command)
|
|
109
|
+
if isinstance(result, LeanError):
|
|
110
|
+
# Handle error
|
|
111
|
+
elif isinstance(result, CommandResponse):
|
|
112
|
+
# Process successful result
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Memory Management
|
|
116
|
+
Set memory limits for Linux platforms:
|
|
117
|
+
```python
|
|
118
|
+
config = LeanREPLConfig(memory_hard_limit_mb=4096)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Session Caching
|
|
122
|
+
Use `AutoLeanServer` for automatic session state management across commands.
|
|
123
|
+
|
|
124
|
+
## External Dependencies
|
|
125
|
+
- **Lean 4**: Managed via `elan` toolchain, versions v4.8.0+ supported
|
|
126
|
+
- **Lake**: Lean's build system, used for project initialization and building
|
|
127
|
+
- **Git**: Required for project cloning and REPL setup
|
|
128
|
+
- **FileSystem**: Heavy use of file locking, temp directories, and path manipulation
|
|
129
|
+
|
|
130
|
+
## Common Pitfalls
|
|
131
|
+
- Don't pass `lean_version` when providing a `project` - version is inferred from project
|
|
132
|
+
- Use absolute paths for all file operations
|
|
133
|
+
- First-time project setup requires internet access and can be slow
|
|
134
|
+
- Concurrency tests may timeout on slow systems due to Lean compilation
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
name: Deploy Documentation
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
paths:
|
|
8
|
+
- 'docs/**'
|
|
9
|
+
- 'mkdocs.yml'
|
|
10
|
+
- 'src/lean_interact/**'
|
|
11
|
+
- '.github/workflows/docs.yml'
|
|
12
|
+
tags:
|
|
13
|
+
- 'v*' # Deploy on version tags
|
|
14
|
+
workflow_dispatch:
|
|
15
|
+
inputs:
|
|
16
|
+
version:
|
|
17
|
+
description: 'Version to deploy (e.g., v0.7.0, latest, dev)'
|
|
18
|
+
required: false
|
|
19
|
+
default: 'dev'
|
|
20
|
+
alias:
|
|
21
|
+
description: 'Alias for this version (e.g., stable, latest)'
|
|
22
|
+
required: false
|
|
23
|
+
|
|
24
|
+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
|
25
|
+
permissions:
|
|
26
|
+
contents: write
|
|
27
|
+
pages: write
|
|
28
|
+
id-token: write
|
|
29
|
+
|
|
30
|
+
# Allow only one concurrent deployment
|
|
31
|
+
concurrency:
|
|
32
|
+
group: 'pages'
|
|
33
|
+
cancel-in-progress: false
|
|
34
|
+
|
|
35
|
+
jobs:
|
|
36
|
+
build-and-deploy:
|
|
37
|
+
runs-on: ubuntu-latest
|
|
38
|
+
steps:
|
|
39
|
+
- name: Checkout
|
|
40
|
+
uses: actions/checkout@v4
|
|
41
|
+
with:
|
|
42
|
+
fetch-depth: 0 # Full history for mike
|
|
43
|
+
|
|
44
|
+
- name: Setup Python
|
|
45
|
+
uses: actions/setup-python@v5
|
|
46
|
+
with:
|
|
47
|
+
python-version: '3.10'
|
|
48
|
+
|
|
49
|
+
- name: Install uv
|
|
50
|
+
uses: astral-sh/setup-uv@v4
|
|
51
|
+
with:
|
|
52
|
+
version: "latest"
|
|
53
|
+
|
|
54
|
+
- name: Install dependencies
|
|
55
|
+
run: |
|
|
56
|
+
uv venv
|
|
57
|
+
uv pip install -e ".[dev]"
|
|
58
|
+
|
|
59
|
+
- name: Install Lean
|
|
60
|
+
run: |
|
|
61
|
+
uv run install-lean
|
|
62
|
+
echo "$HOME/.elan/bin" >> $GITHUB_PATH
|
|
63
|
+
|
|
64
|
+
- name: Configure Git
|
|
65
|
+
run: |
|
|
66
|
+
git config --global user.name "github-actions[bot]"
|
|
67
|
+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
68
|
+
|
|
69
|
+
- name: Fetch gh-pages branch
|
|
70
|
+
run: |
|
|
71
|
+
git fetch origin gh-pages --depth=1 || echo "gh-pages branch doesn't exist yet"
|
|
72
|
+
|
|
73
|
+
- name: Generate changelog
|
|
74
|
+
run: |
|
|
75
|
+
uv run python docs/generate_changelog.py
|
|
76
|
+
|
|
77
|
+
- name: Determine version and alias
|
|
78
|
+
id: version
|
|
79
|
+
run: |
|
|
80
|
+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
|
|
81
|
+
VERSION="${{ github.event.inputs.version }}"
|
|
82
|
+
ALIAS="${{ github.event.inputs.alias }}"
|
|
83
|
+
elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
|
|
84
|
+
VERSION="${{ github.ref_name }}"
|
|
85
|
+
# Only set stable for release versions (not pre-release)
|
|
86
|
+
if [[ "${{ github.ref_name }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
|
87
|
+
ALIAS="stable"
|
|
88
|
+
else
|
|
89
|
+
ALIAS="" # Pre-release versions don't get stable alias
|
|
90
|
+
fi
|
|
91
|
+
elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
|
|
92
|
+
VERSION="dev"
|
|
93
|
+
ALIAS=""
|
|
94
|
+
else
|
|
95
|
+
VERSION="dev"
|
|
96
|
+
ALIAS=""
|
|
97
|
+
fi
|
|
98
|
+
|
|
99
|
+
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
100
|
+
echo "alias=$ALIAS" >> $GITHUB_OUTPUT
|
|
101
|
+
echo "Deploying version: $VERSION with alias: $ALIAS"
|
|
102
|
+
|
|
103
|
+
- name: Deploy with mike
|
|
104
|
+
run: |
|
|
105
|
+
if [[ -n "${{ steps.version.outputs.alias }}" ]]; then
|
|
106
|
+
uv run mike deploy --push --update-aliases ${{ steps.version.outputs.version }} ${{ steps.version.outputs.alias }}
|
|
107
|
+
# Set default version if this is a stable release
|
|
108
|
+
if [[ "${{ steps.version.outputs.alias }}" == "stable" ]]; then
|
|
109
|
+
uv run mike set-default --push stable
|
|
110
|
+
fi
|
|
111
|
+
else
|
|
112
|
+
uv run mike deploy --push ${{ steps.version.outputs.version }}
|
|
113
|
+
fi
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lean-interact
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: LeanInteract is a Python package that allows you to interact with the Lean theorem prover.
|
|
5
5
|
Author-email: Auguste Poiroux <auguste.poiroux@epfl.ch>
|
|
6
6
|
License: MIT License
|
|
@@ -38,7 +38,7 @@ Description-Content-Type: text/markdown
|
|
|
38
38
|
|
|
39
39
|
# LeanInteract
|
|
40
40
|
|
|
41
|
-
[](https://augustepoiroux.github.io/LeanInteract/)
|
|
42
42
|
[](https://pypi.org/project/lean-interact/)
|
|
43
43
|
[](https://pypi.org/project/lean-interact/)
|
|
44
44
|
[](https://www.python.org/downloads/)
|
|
@@ -46,12 +46,14 @@ Description-Content-Type: text/markdown
|
|
|
46
46
|
|
|
47
47
|
**LeanInteract** is a Python package designed to seamlessly interact with Lean 4 through the [Lean REPL](https://github.com/leanprover-community/repl).
|
|
48
48
|
|
|
49
|
+
Check the [documentation](https://augustepoiroux.github.io/LeanInteract/) for detailed usage and examples.
|
|
50
|
+
|
|
49
51
|
## Key Features
|
|
50
52
|
|
|
51
53
|
- **🔗 Interactivity**: Execute Lean code and files directly from Python.
|
|
52
54
|
- **🚀 Ease of Use**: LeanInteract abstracts the complexities of Lean setup and interaction.
|
|
53
55
|
- **💻 Cross-platform**: Works on Windows, macOS, and Linux operating systems.
|
|
54
|
-
- **🔧 Compatibility**: Supports all Lean versions between `v4.7.0-rc1` and `v4.22.0-
|
|
56
|
+
- **🔧 Compatibility**: Supports all Lean versions between `v4.7.0-rc1` and `v4.22.0-rc4`.
|
|
55
57
|
- We backport the latest features of Lean REPL to older versions of Lean (see [fork](https://github.com/augustepoiroux/repl)).
|
|
56
58
|
- **📦 Temporary Projects**: Easily instantiate temporary Lean environments.
|
|
57
59
|
- Useful for experimenting with benchmarks depending on [Mathlib](https://github.com/leanprover-community/mathlib4) like [ProofNet#](https://huggingface.co/datasets/PAug/ProofNetSharp) and [MiniF2F](https://github.com/yangky11/miniF2F-lean4).
|
|
@@ -81,7 +83,6 @@ Description-Content-Type: text/markdown
|
|
|
81
83
|
- [Custom Lean REPL](#custom-lean-repl)
|
|
82
84
|
- [Similar tools](#similar-tools)
|
|
83
85
|
- [Troubleshooting](#troubleshooting)
|
|
84
|
-
- [Contributing](#contributing)
|
|
85
86
|
- [Citation](#citation)
|
|
86
87
|
- [License](#license)
|
|
87
88
|
|
|
@@ -264,13 +265,17 @@ config = LeanREPLConfig(lean_version="v4.7.0")
|
|
|
264
265
|
#### Existing Lean projects
|
|
265
266
|
|
|
266
267
|
```python
|
|
267
|
-
|
|
268
|
+
# Local project
|
|
269
|
+
project = LocalProject(directory="path/to/your/project")
|
|
270
|
+
config = LeanREPLConfig(project=project)
|
|
268
271
|
```
|
|
269
272
|
|
|
270
273
|
or
|
|
271
274
|
|
|
272
275
|
```python
|
|
273
|
-
|
|
276
|
+
# Git project
|
|
277
|
+
project = GitProject(url="https://github.com/yangky11/lean4-example", rev="main")
|
|
278
|
+
config = LeanREPLConfig(project=project)
|
|
274
279
|
```
|
|
275
280
|
|
|
276
281
|
You can then use `run` as usual:
|
|
@@ -288,19 +293,24 @@ server.run(FileCommand(path="file.lean"))
|
|
|
288
293
|
#### Temporary project with dependencies
|
|
289
294
|
|
|
290
295
|
```python
|
|
291
|
-
from lean_interact import TempRequireProject
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
296
|
+
from lean_interact import TempRequireProject, LeanRequire
|
|
297
|
+
|
|
298
|
+
project = TempRequireProject(
|
|
299
|
+
lean_version="v4.8.0",
|
|
300
|
+
require=[LeanRequire(
|
|
301
|
+
name="mathlib",
|
|
302
|
+
git="https://github.com/leanprover-community/mathlib4.git",
|
|
303
|
+
rev="v4.8.0"
|
|
304
|
+
)]
|
|
305
|
+
)
|
|
306
|
+
config = LeanREPLConfig(project=project)
|
|
298
307
|
```
|
|
299
308
|
|
|
300
309
|
Mathlib being a frequent requirement, a shortcut is available:
|
|
301
310
|
|
|
302
311
|
```python
|
|
303
|
-
|
|
312
|
+
project = TempRequireProject(lean_version="v4.8.0", require="mathlib")
|
|
313
|
+
config = LeanREPLConfig(project=project)
|
|
304
314
|
```
|
|
305
315
|
|
|
306
316
|
You can then use Mathlib as follows:
|
|
@@ -347,7 +357,9 @@ For more control over the temporary project, you can use `TemporaryProject` to s
|
|
|
347
357
|
```python
|
|
348
358
|
from lean_interact import TemporaryProject
|
|
349
359
|
|
|
350
|
-
|
|
360
|
+
project = TemporaryProject(
|
|
361
|
+
lean_version="v4.18.0",
|
|
362
|
+
content="""
|
|
351
363
|
import Lake
|
|
352
364
|
open Lake DSL
|
|
353
365
|
|
|
@@ -360,7 +372,9 @@ lean_exe "dummy" where
|
|
|
360
372
|
|
|
361
373
|
require mathlib from git
|
|
362
374
|
"https://github.com/leanprover-community/mathlib4.git" @ "v4.18.0"
|
|
363
|
-
"""
|
|
375
|
+
"""
|
|
376
|
+
)
|
|
377
|
+
config = LeanREPLConfig(project=project)
|
|
364
378
|
```
|
|
365
379
|
|
|
366
380
|
## Available Queries
|
|
@@ -520,16 +534,6 @@ If you get an error similar to the following one, you are likely affected by thi
|
|
|
520
534
|
git config --system core.longpaths true
|
|
521
535
|
```
|
|
522
536
|
|
|
523
|
-
## Contributing
|
|
524
|
-
|
|
525
|
-
Contributions are welcome! Here's how you can help:
|
|
526
|
-
|
|
527
|
-
1. Fork the repository
|
|
528
|
-
2. Create a feature branch: `git checkout -b feature-name`
|
|
529
|
-
3. Commit your changes: `git commit -am 'Add new feature'`
|
|
530
|
-
4. Push to the branch: `git push origin feature-name`
|
|
531
|
-
5. Submit a pull request
|
|
532
|
-
|
|
533
537
|
## Citation
|
|
534
538
|
|
|
535
539
|
If you use LeanInteract in your research, please cite it as follows:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# LeanInteract
|
|
2
2
|
|
|
3
|
-
[](https://augustepoiroux.github.io/LeanInteract/)
|
|
4
4
|
[](https://pypi.org/project/lean-interact/)
|
|
5
5
|
[](https://pypi.org/project/lean-interact/)
|
|
6
6
|
[](https://www.python.org/downloads/)
|
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
|
|
9
9
|
**LeanInteract** is a Python package designed to seamlessly interact with Lean 4 through the [Lean REPL](https://github.com/leanprover-community/repl).
|
|
10
10
|
|
|
11
|
+
Check the [documentation](https://augustepoiroux.github.io/LeanInteract/) for detailed usage and examples.
|
|
12
|
+
|
|
11
13
|
## Key Features
|
|
12
14
|
|
|
13
15
|
- **🔗 Interactivity**: Execute Lean code and files directly from Python.
|
|
14
16
|
- **🚀 Ease of Use**: LeanInteract abstracts the complexities of Lean setup and interaction.
|
|
15
17
|
- **💻 Cross-platform**: Works on Windows, macOS, and Linux operating systems.
|
|
16
|
-
- **🔧 Compatibility**: Supports all Lean versions between `v4.7.0-rc1` and `v4.22.0-
|
|
18
|
+
- **🔧 Compatibility**: Supports all Lean versions between `v4.7.0-rc1` and `v4.22.0-rc4`.
|
|
17
19
|
- We backport the latest features of Lean REPL to older versions of Lean (see [fork](https://github.com/augustepoiroux/repl)).
|
|
18
20
|
- **📦 Temporary Projects**: Easily instantiate temporary Lean environments.
|
|
19
21
|
- Useful for experimenting with benchmarks depending on [Mathlib](https://github.com/leanprover-community/mathlib4) like [ProofNet#](https://huggingface.co/datasets/PAug/ProofNetSharp) and [MiniF2F](https://github.com/yangky11/miniF2F-lean4).
|
|
@@ -43,7 +45,6 @@
|
|
|
43
45
|
- [Custom Lean REPL](#custom-lean-repl)
|
|
44
46
|
- [Similar tools](#similar-tools)
|
|
45
47
|
- [Troubleshooting](#troubleshooting)
|
|
46
|
-
- [Contributing](#contributing)
|
|
47
48
|
- [Citation](#citation)
|
|
48
49
|
- [License](#license)
|
|
49
50
|
|
|
@@ -226,13 +227,17 @@ config = LeanREPLConfig(lean_version="v4.7.0")
|
|
|
226
227
|
#### Existing Lean projects
|
|
227
228
|
|
|
228
229
|
```python
|
|
229
|
-
|
|
230
|
+
# Local project
|
|
231
|
+
project = LocalProject(directory="path/to/your/project")
|
|
232
|
+
config = LeanREPLConfig(project=project)
|
|
230
233
|
```
|
|
231
234
|
|
|
232
235
|
or
|
|
233
236
|
|
|
234
237
|
```python
|
|
235
|
-
|
|
238
|
+
# Git project
|
|
239
|
+
project = GitProject(url="https://github.com/yangky11/lean4-example", rev="main")
|
|
240
|
+
config = LeanREPLConfig(project=project)
|
|
236
241
|
```
|
|
237
242
|
|
|
238
243
|
You can then use `run` as usual:
|
|
@@ -250,19 +255,24 @@ server.run(FileCommand(path="file.lean"))
|
|
|
250
255
|
#### Temporary project with dependencies
|
|
251
256
|
|
|
252
257
|
```python
|
|
253
|
-
from lean_interact import TempRequireProject
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
258
|
+
from lean_interact import TempRequireProject, LeanRequire
|
|
259
|
+
|
|
260
|
+
project = TempRequireProject(
|
|
261
|
+
lean_version="v4.8.0",
|
|
262
|
+
require=[LeanRequire(
|
|
263
|
+
name="mathlib",
|
|
264
|
+
git="https://github.com/leanprover-community/mathlib4.git",
|
|
265
|
+
rev="v4.8.0"
|
|
266
|
+
)]
|
|
267
|
+
)
|
|
268
|
+
config = LeanREPLConfig(project=project)
|
|
260
269
|
```
|
|
261
270
|
|
|
262
271
|
Mathlib being a frequent requirement, a shortcut is available:
|
|
263
272
|
|
|
264
273
|
```python
|
|
265
|
-
|
|
274
|
+
project = TempRequireProject(lean_version="v4.8.0", require="mathlib")
|
|
275
|
+
config = LeanREPLConfig(project=project)
|
|
266
276
|
```
|
|
267
277
|
|
|
268
278
|
You can then use Mathlib as follows:
|
|
@@ -309,7 +319,9 @@ For more control over the temporary project, you can use `TemporaryProject` to s
|
|
|
309
319
|
```python
|
|
310
320
|
from lean_interact import TemporaryProject
|
|
311
321
|
|
|
312
|
-
|
|
322
|
+
project = TemporaryProject(
|
|
323
|
+
lean_version="v4.18.0",
|
|
324
|
+
content="""
|
|
313
325
|
import Lake
|
|
314
326
|
open Lake DSL
|
|
315
327
|
|
|
@@ -322,7 +334,9 @@ lean_exe "dummy" where
|
|
|
322
334
|
|
|
323
335
|
require mathlib from git
|
|
324
336
|
"https://github.com/leanprover-community/mathlib4.git" @ "v4.18.0"
|
|
325
|
-
"""
|
|
337
|
+
"""
|
|
338
|
+
)
|
|
339
|
+
config = LeanREPLConfig(project=project)
|
|
326
340
|
```
|
|
327
341
|
|
|
328
342
|
## Available Queries
|
|
@@ -482,16 +496,6 @@ If you get an error similar to the following one, you are likely affected by thi
|
|
|
482
496
|
git config --system core.longpaths true
|
|
483
497
|
```
|
|
484
498
|
|
|
485
|
-
## Contributing
|
|
486
|
-
|
|
487
|
-
Contributions are welcome! Here's how you can help:
|
|
488
|
-
|
|
489
|
-
1. Fork the repository
|
|
490
|
-
2. Create a feature branch: `git checkout -b feature-name`
|
|
491
|
-
3. Commit your changes: `git commit -am 'Add new feature'`
|
|
492
|
-
4. Push to the branch: `git push origin feature-name`
|
|
493
|
-
5. Submit a pull request
|
|
494
|
-
|
|
495
499
|
## Citation
|
|
496
500
|
|
|
497
501
|
If you use LeanInteract in your research, please cite it as follows:
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
::: lean_interact.interface
|
|
2
|
+
options:
|
|
3
|
+
heading_level: 1
|
|
4
|
+
heading: "Interface"
|
|
5
|
+
show_symbol_type_heading: false
|
|
6
|
+
members:
|
|
7
|
+
- Command
|
|
8
|
+
- FileCommand
|
|
9
|
+
- ProofStep
|
|
10
|
+
- PickleEnvironment
|
|
11
|
+
- UnpickleEnvironment
|
|
12
|
+
- PickleProofState
|
|
13
|
+
- UnpickleProofState
|
|
14
|
+
- CommandResponse
|
|
15
|
+
- ProofStepResponse
|
|
16
|
+
- LeanError
|
|
17
|
+
- Message
|
|
18
|
+
- Pos
|
|
19
|
+
- Range
|
|
20
|
+
- Sorry
|
|
21
|
+
- Tactic
|
|
22
|
+
- InfoTree
|
|
23
|
+
- TacticNode
|
|
24
|
+
- CommandNode
|
|
25
|
+
- TermNode
|
|
26
|
+
- Syntax
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Utilities
|
|
2
|
+
|
|
3
|
+
This page documents the utility functions and classes used in LeanInteract.
|
|
4
|
+
|
|
5
|
+
## Installation and Cache Management
|
|
6
|
+
|
|
7
|
+
::: lean_interact.utils.install_lean
|
|
8
|
+
options:
|
|
9
|
+
heading_level: 3
|
|
10
|
+
|
|
11
|
+
::: lean_interact.utils.clear_cache
|
|
12
|
+
options:
|
|
13
|
+
heading_level: 3
|
|
14
|
+
|
|
15
|
+
## Project Utilities
|
|
16
|
+
|
|
17
|
+
::: lean_interact.utils.get_project_lean_version
|
|
18
|
+
options:
|
|
19
|
+
heading_level: 3
|
|
20
|
+
|
|
21
|
+
## Windows Path Utilities
|
|
22
|
+
|
|
23
|
+
::: lean_interact.utils.check_windows_long_paths
|
|
24
|
+
options:
|
|
25
|
+
heading_level: 3
|
|
26
|
+
|
|
27
|
+
## Memory Management
|
|
28
|
+
|
|
29
|
+
::: lean_interact.utils.get_total_memory_usage
|
|
30
|
+
options:
|
|
31
|
+
heading_level: 3
|
|
32
|
+
|
|
33
|
+
## Code Processing Utilities
|
|
34
|
+
|
|
35
|
+
::: lean_interact.utils.indent_code
|
|
36
|
+
options:
|
|
37
|
+
heading_level: 3
|
|
38
|
+
|
|
39
|
+
::: lean_interact.utils.compress_newlines
|
|
40
|
+
options:
|
|
41
|
+
heading_level: 3
|
|
42
|
+
|
|
43
|
+
::: lean_interact.utils.lean_comments_ranges
|
|
44
|
+
options:
|
|
45
|
+
heading_level: 3
|
|
46
|
+
|
|
47
|
+
::: lean_interact.utils.remove_lean_comments
|
|
48
|
+
options:
|
|
49
|
+
heading_level: 3
|
|
50
|
+
|
|
51
|
+
::: lean_interact.utils.split_implementation
|
|
52
|
+
options:
|
|
53
|
+
heading_level: 3
|
|
54
|
+
|
|
55
|
+
::: lean_interact.utils.split_conclusion
|
|
56
|
+
options:
|
|
57
|
+
heading_level: 3
|
|
58
|
+
|
|
59
|
+
::: lean_interact.utils.clean_theorem_string
|
|
60
|
+
options:
|
|
61
|
+
heading_level: 3
|
|
62
|
+
|
|
63
|
+
::: lean_interact.utils.extract_last_theorem
|
|
64
|
+
options:
|
|
65
|
+
heading_level: 3
|
|
66
|
+
|
|
67
|
+
::: lean_interact.utils.clean_last_theorem_string
|
|
68
|
+
options:
|
|
69
|
+
heading_level: 3
|