Commit 75b17b55 authored by Andrew Gibiansky's avatar Andrew Gibiansky

Check for IPython version.

parent 13af0ec2
...@@ -23,6 +23,7 @@ import GHC hiding (Stmt) ...@@ -23,6 +23,7 @@ import GHC hiding (Stmt)
import GHC.Paths import GHC.Paths
import Exception hiding (evaluate) import Exception hiding (evaluate)
import Outputable
import qualified System.IO.Strict as StrictIO import qualified System.IO.Strict as StrictIO
import IHaskell.Types import IHaskell.Types
...@@ -164,7 +165,9 @@ evalCommand (Statement stmt) = do ...@@ -164,7 +165,9 @@ evalCommand (Statement stmt) = do
ghandle handler $ do ghandle handler $ do
(printed, result) <- capturedStatement stmt (printed, result) <- capturedStatement stmt
case result of case result of
RunOk _ -> RunOk names -> do
dflags <- getSessionDynFlags
write $ "Names: " ++ show (map (showPpr dflags) names)
return [Display PlainText printed] return [Display PlainText printed]
RunException exception -> do RunException exception -> do
write $ "RunException: " ++ show exception write $ "RunException: " ++ show exception
......
module IHaskell.IPython ( module IHaskell.IPython (
runIHaskell, runIHaskell,
setupIPythonProfile setupIPythonProfile,
ipythonVersion
) where ) where
import ClassyPrelude import ClassyPrelude
...@@ -9,6 +10,10 @@ import Text.Printf ...@@ -9,6 +10,10 @@ import Text.Printf
import System.Argv0 import System.Argv0
import System.Directory import System.Directory
import qualified Filesystem.Path.CurrentOS as FS import qualified Filesystem.Path.CurrentOS as FS
import Data.List.Utils (split)
import Prelude (read)
import qualified System.IO.Strict as StrictIO
import qualified IHaskell.Config as Config import qualified IHaskell.Config as Config
...@@ -23,6 +28,17 @@ ipython args = do ...@@ -23,6 +28,17 @@ ipython args = do
doNothing _ _ _ = return () doNothing _ _ _ = return ()
-- | Use the `ipython --version` command to figure out the version.
-- Return a tuple with (major, minor, patch).
ipythonVersion :: IO (Int, Int, Int)
ipythonVersion = shelly $ do
path <- which "ipython"
case path of
Nothing -> error "Could not find `ipython` executable."
Just path -> do
[major, minor, patch] <- map read <$> split "." <$> runHandle path ["--version"] (liftIO . StrictIO.hGetContents) :: Sh [Int]
return (major, minor, patch)
-- | Run an IHaskell application using the given profile. -- | Run an IHaskell application using the given profile.
runIHaskell :: String -- ^ IHaskell profile name. runIHaskell :: String -- ^ IHaskell profile name.
-> String -- ^ IPython app name. -> String -- ^ IPython app name.
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import ClassyPrelude hiding (liftIO) import ClassyPrelude hiding (liftIO)
import Control.Concurrent.Chan import Control.Concurrent.Chan
import Data.Aeson import Data.Aeson
import Text.Printf
import qualified Data.Map as Map import qualified Data.Map as Map
...@@ -20,6 +21,11 @@ data KernelState = KernelState ...@@ -20,6 +21,11 @@ data KernelState = KernelState
main :: IO () main :: IO ()
main = do main = do
(major, minor, patch) <- ipythonVersion
when (major /= 1) $ do
printf "Expecting IPython version 1.*, found version %d.%d.%d.\n" major minor patch
error "Incorrect ipython --version."
args <- map unpack <$> getArgs args <- map unpack <$> getArgs
case args of case args of
-- Create the "haskell" profile. -- Create the "haskell" profile.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment