From 24c8f8bc1301467506e02b298a232f8649419e00 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Sun, 22 Dec 2024 01:17:50 -0500 Subject: [PATCH] jupyterlab: replace `expect` dependency with Ruby libs --- Formula/j/jupyterlab.rb | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/Formula/j/jupyterlab.rb b/Formula/j/jupyterlab.rb index 2a7ec0166f34b..e9fcf931f72b0 100644 --- a/Formula/j/jupyterlab.rb +++ b/Formula/j/jupyterlab.rb @@ -29,7 +29,6 @@ class Jupyterlab < Formula depends_on "python@3.13" depends_on "zeromq" - uses_from_macos "expect" => :test uses_from_macos "libffi" uses_from_macos "libxml2" uses_from_macos "libxslt" @@ -559,22 +558,17 @@ def caveats end test do - system bin/"jupyter-console --help" + assert_match "The Jupyter terminal-based Console", shell_output("#{bin}/jupyter-console --help") assert_match python3, shell_output("#{bin}/jupyter kernelspec list") - - (testpath/"console.exp").write <<~EOS - spawn #{bin}/jupyter-console - expect -timeout 60 "In " - send "exit\r" - EOS - assert_match "Jupyter console", shell_output("expect -f console.exp") - - (testpath/"notebook.exp").write <<~EOS - set timeout 60 - spawn #{bin}/jupyter notebook --no-browser - expect "ServerApp" - EOS - assert_match "ServerApp", shell_output("expect -f notebook.exp") + assert_match(/In \[1\]:.*exit.*Shutting down/m, pipe_output("#{bin}/jupyter-console 2>&1", "exit")) + + require "expect" + require "open3" + Open3.popen3(bin/"jupyter", "notebook", "--no-browser") do |_stdin, _stdout, stderr, wait_thread| + refute_nil stderr.expect("Serving notebooks from local directory:", 15), "Expected running message" + ensure + Process.kill "TERM", wait_thread.pid + end (testpath/"nbconvert.ipynb").write <<~JSON {