diff --git a/examples/Example/lake-manifest.json b/examples/Example/lake-manifest.json index 06e1c0e..2199727 100644 --- a/examples/Example/lake-manifest.json +++ b/examples/Example/lake-manifest.json @@ -1,11 +1,12 @@ -{"version": 7, +{"version": "1.1.0", "packagesDir": ".lake/packages", "packages": - [{"url": "https://github.com/leanprover/std4", + [{"url": "https://github.com/leanprover-community/batteries", "type": "git", "subDir": null, - "rev": "3025cb124492b423070f20cf0a70636f757d117f", - "name": "std", + "scope": "", + "rev": "2ead90d24b4fac3a05c9c4294daa39bd8686fb98", + "name": "batteries", "manifestFile": "lake-manifest.json", "inputRev": "main", "inherited": true, @@ -13,11 +14,12 @@ {"url": "https://github.com/leanprover-community/aesop.git", "type": "git", "subDir": null, - "rev": "0a21a48c286c4a4703c0be6ad2045f601f31b1d0", + "scope": "", + "rev": "a64fe24aa94e21404940e9217363a9a1ed9a33a6", "name": "aesop", "manifestFile": "lake-manifest.json", - "inputRev": "v4.8.0-rc1", + "inputRev": "v4.10.0-rc1", "inherited": false, - "configFile": "lakefile.lean"}], + "configFile": "lakefile.toml"}], "name": "Example", "lakeDir": ".lake"} diff --git a/examples/Example/lakefile.lean b/examples/Example/lakefile.lean index 52623f0..8759d91 100644 --- a/examples/Example/lakefile.lean +++ b/examples/Example/lakefile.lean @@ -2,7 +2,7 @@ import Lake open Lake DSL require aesop from git - "https://github.com/leanprover-community/aesop.git" @ "v4.8.0-rc1" + "https://github.com/leanprover-community/aesop.git" @ "v4.10.0-rc1" package Example diff --git a/examples/Example/lean-toolchain b/examples/Example/lean-toolchain index d8a6d7e..d69d1ed 100644 --- a/examples/Example/lean-toolchain +++ b/examples/Example/lean-toolchain @@ -1 +1 @@ -leanprover/lean4:v4.8.0-rc1 +leanprover/lean4:v4.10.0-rc1 diff --git a/examples/README.md b/examples/README.md index 68286fb..5991455 100644 --- a/examples/README.md +++ b/examples/README.md @@ -19,5 +19,8 @@ poetry run examples/aesop.py poetry run examples/data.py ``` -Warning: If you make modifications to any Lean files, you must re-run `lake build`! +Warning: If you make modifications to any Lean files, you must re-run `lake +build`! Moreover, the version of the Lean used in the example folder (including +dependencies in `lakefile.lean` and `lean-toolchain`) **must match exactly** +with the version in `src/`! diff --git a/examples/data.py b/examples/data.py index bb1365b..f1d8978 100755 --- a/examples/data.py +++ b/examples/data.py @@ -14,7 +14,7 @@ if __name__ == '__main__': print(f"$PWD: {project_path}") print(f"$LEAN_PATH: {lean_path}") server = Server(imports=['Example'], project_path=project_path, lean_path=lean_path) - units, invocations = server.compile_unit("Example") + units, invocations = server.tactic_invocations(project_path / "Example.lean") for i, u in enumerate(units): print(f"==== #{i} ====") print(u) diff --git a/pantograph/server.py b/pantograph/server.py index ddaeeb1..8595635 100644 --- a/pantograph/server.py +++ b/pantograph/server.py @@ -2,13 +2,15 @@ Class which manages a Pantograph instance. All calls to the kernel uses this interface. """ -import json, pexpect, pathlib, unittest, os +import json, pexpect, unittest, os +from typing import Union +from pathlib import Path from pantograph.expr import parse_expr, Expr, Variable, Goal, GoalState, \ Tactic, TacticHave, TacticCalc from pantograph.compiler import TacticInvocation def _get_proc_cwd(): - return pathlib.Path(__file__).parent + return Path(__file__).parent def _get_proc_path(): return _get_proc_cwd() / "pantograph-repl" @@ -64,7 +66,7 @@ class Server: ) self.proc.setecho(False) # Do not send any command before this. ready = self.proc.readline() # Reads the "ready." - assert ready == "ready.\r\n" + assert ready == "ready.\r\n", f"Server failed to emit ready signal: {ready}; Maybe the project needs to be rebuilt" if self.options: self.run("options.set", self.options) @@ -146,17 +148,19 @@ class Server: raise ServerError(result["parseError"]) return GoalState.parse(result, self.to_remove_goal_states) - def compile_unit(self, module: str) -> tuple[list[str], list[TacticInvocation]]: - file_path = self.project_path / (module.replace('.', '/') + '.lean') - result = self.run('compile.unit', { - 'module': module, - 'compilationUnits': True, - 'invocations': True + def tactic_invocations(self, file_name: Union[str, Path]) -> tuple[list[str], list[TacticInvocation]]: + """ + Collect tactic invocation points in file, and return them. + """ + result = self.run('frontend.process', { + 'fileName': str(file_name), + 'invocations': True, + "sorrys": False, }) if "error" in result: raise ServerError(result["desc"]) - with open(file_path, 'rb') as f: + with open(file_name, 'rb') as f: content = f.read() units = [content[begin:end].decode('utf-8') for begin,end in result['units']]