From a5c15ed80b23e7caa655351cc4b74dbb01c91e8e Mon Sep 17 00:00:00 2001
From: Jameson Graef Rollins <jrollins@finestructure.net>
Date: Thu, 23 Apr 2020 13:13:12 -0700
Subject: [PATCH] cli: fix interactive mode

At some point this mode stopped producing plots.  This fixes that by
updating the code execution call to InteractiveShellEmbed.

Also only imports ipython opportunistically, so it's not a hard dependency.
---
 gwinc/__main__.py | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/gwinc/__main__.py b/gwinc/__main__.py
index e4eea3b1..5b112dfb 100644
--- a/gwinc/__main__.py
+++ b/gwinc/__main__.py
@@ -3,7 +3,6 @@ import os
 import signal
 import argparse
 import numpy as np
-from IPython.terminal.embed import InteractiveShellEmbed
 
 import logging
 logging.basicConfig(
@@ -247,14 +246,8 @@ def main():
 
     # interactive shell plotting
     if args.interactive:
+        from IPython.terminal.embed import InteractiveShellEmbed
         ipshell = InteractiveShellEmbed(
-            user_ns={
-                'freq': freq,
-                'traces': traces,
-                'ifo': ifo,
-                'plot_style': plot_style,
-                'plot_noise': plot_noise,
-            },
             banner1='''
 GWINC interactive plotter
 
@@ -262,10 +255,18 @@ You may interact with plot using "plt." methods, e.g.:
 
 >>> plt.title("foo")
 >>> plt.savefig("foo.pdf")
-''')
+''',
+            user_ns={
+                'freq': freq,
+                'traces': traces,
+                'ifo': ifo,
+                'plot_style': plot_style,
+                'plot_noise': plot_noise,
+            },
+        )
         ipshell.enable_pylab()
-        ipshell.run_code("plot_noise(freq, traces, **plot_style)")
-        ipshell.run_code("plt.title('{}')".format(plot_style['title']))
+        ipshell.ex("fig = plot_noise(freq, traces, **plot_style)")
+        ipshell.ex("plt.title('{}')".format(plot_style['title']))
         ipshell()
 
     ##########
-- 
GitLab