lean-interact 0.3.0__tar.gz → 0.3.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lean-interact
3
- Version: 0.3.0
3
+ Version: 0.3.2
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "lean-interact"
3
- version = "0.3.0"
3
+ version = "0.3.2"
4
4
  description = "LeanInteract is a Python package that allows you to interact with the Lean theorem prover."
5
5
  keywords = ["Lean", "theorem proving", "autoformalization", "REPL"]
6
6
  license = { file = "LICENSE" }
@@ -64,9 +64,10 @@ class LeanServer:
64
64
  echo=False,
65
65
  preexec_fn=lambda: _limit_memory(self.config.memory_hard_limit_mb),
66
66
  )
67
+ self._proc.delaybeforesend = None
67
68
  # `stty -icanon` is required to handle arbitrary long inputs in the Lean REPL
68
69
  self._proc.sendline("stty -icanon")
69
- self._proc.sendline(f"lake env {self.config._cache_repl_dir}/.lake/build/bin/repl")
70
+ self._proc.sendline(f"lake env {self.config._cache_repl_dir}/.lake/build/bin/repl || exit")
70
71
 
71
72
  def is_alive(self) -> bool:
72
73
  return hasattr(self, "_proc") and self._proc is not None and self._proc.isalive()
@@ -131,8 +132,9 @@ class LeanServer:
131
132
  self.kill()
132
133
  raise ConnectionAbortedError(
133
134
  "The Lean server closed unexpectedly. Possible reasons (not exhaustive):\n"
135
+ "- An uncaught exception in the Lean REPL (for example, an unexistent file has been requested)\n"
134
136
  "- Not enough memory and/or compute available\n"
135
- "- Your cached Lean REPL is corrupted. In this case, clear the cache"
137
+ "- The cached Lean REPL is corrupted. In this case, clear the cache"
136
138
  " using the `clear_cache` (`from pyleanrepl import clear_cache`) method."
137
139
  ) from e
138
140
 
@@ -411,6 +411,18 @@ class TestLeanServer(unittest.TestCase):
411
411
  step2 = server.run(ProofStep(tactic="rfl", proof_state=step1.proof_state))
412
412
  self.assertEqual(step2, ProofStepResponse(proof_state=2, goals=[]))
413
413
 
414
+ def test_run_lots_of_commands(self):
415
+ server = LeanServer(LeanREPLConfig(verbose=True))
416
+
417
+ init_env = server.run(Command(cmd="#eval 1"))
418
+ assert isinstance(init_env, CommandResponse)
419
+ for i in range(1000):
420
+ cmd = Command(
421
+ cmd=f"theorem womp{i} (a{i} b c : Nat) : (a{i} + b) + c = c + a{i} + b := by sorry", env=init_env.env
422
+ )
423
+ result = server.run(cmd)
424
+ self.assertIsInstance(result, CommandResponse)
425
+
414
426
  def test_bug_increasing_memory(self):
415
427
  mem_limit = 512
416
428
  server = AutoLeanServer(config=LeanREPLConfig(memory_hard_limit_mb=mem_limit, verbose=True))
@@ -435,6 +447,8 @@ class TestLeanServer(unittest.TestCase):
435
447
  result_queue.put(("success", result))
436
448
  except TimeoutError as e:
437
449
  result_queue.put(("timeout", e))
450
+ except ConnectionAbortedError as e:
451
+ result_queue.put(("connection_aborted", e)) # out of memory
438
452
  except Exception as e:
439
453
  result_queue.put(("error", e))
440
454
 
@@ -549,13 +563,11 @@ class TestLeanServer(unittest.TestCase):
549
563
  # Try to unpickle invalid data
550
564
  temp_pickle_file = tempfile.mkstemp(suffix=".olean")[1]
551
565
 
552
- # TODO: Fix this in Lean REPL, it should crash instead of hanging
553
-
554
- with self.assertRaises(TimeoutError):
555
- server.run(UnpickleEnvironment(unpickle_env_from=temp_pickle_file), timeout=5)
556
-
557
- with self.assertRaises(TimeoutError):
558
- server.run(UnpickleProofState(unpickle_proof_state_from=temp_pickle_file), timeout=5)
566
+ # Try to unpickle invalid data
567
+ with self.assertRaises(ConnectionAbortedError):
568
+ server.run(UnpickleEnvironment(unpickle_env_from=temp_pickle_file))
569
+ with self.assertRaises(ConnectionAbortedError):
570
+ server.run(UnpickleProofState(unpickle_proof_state_from=temp_pickle_file))
559
571
 
560
572
  # delete the temp file
561
573
  os.remove(temp_pickle_file)
@@ -351,7 +351,7 @@ wheels = [
351
351
 
352
352
  [[package]]
353
353
  name = "lean-interact"
354
- version = "0.3.0"
354
+ version = "0.3.2"
355
355
  source = { editable = "." }
356
356
  dependencies = [
357
357
  { name = "gitpython" },
File without changes
File without changes
File without changes