-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
49 lines (43 loc) · 1.45 KB
/
Copy pathscript.py
File metadata and controls
49 lines (43 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import json
import subprocess
import os
import sys
from typing import List, Any
# Try to find the lake executable
lake_path = subprocess.run(["which", "lake"], capture_output=True, text=True).stdout.strip()
if not lake_path:
# Alternative paths where lake might be installed
potential_paths = [
os.path.expanduser("~/.elan/bin/lake"),
"/usr/local/bin/lake",
"/opt/homebrew/bin/lake"
]
for path in potential_paths:
if os.path.exists(path):
lake_path = path
break
if not lake_path:
raise FileNotFoundError("Lake executable not found. Please install Lean/Lake or add it to PATH.")
process = subprocess.Popen(
[lake_path, "exe", "repl", "--load-dynlib=.lake/packages/Canonical/.lake/build/lib/libcanonical_lean.dylib"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
text=True,
bufsize=1,
env=os.environ,
)
def send_command(command):
json_command = json.dumps(command, ensure_ascii=False) + "\n\n"
process.stdin.write(json_command)
process.stdin.flush()
response_lines = []
while True:
stdout_line = process.stdout.readline()
if stdout_line.strip() == "":
break
response_lines.append(stdout_line)
return json.loads("".join(response_lines))
lol = send_command({ "cmd" : "import Mathlib\nimport Canonical\ntheorem womp : (2:Nat) + 2 = 4 := by canonical" })
print(lol)
env_import = lol["env"]
print(env_import)