Commit 215668fc authored by Andrew Gibiansky's avatar Andrew Gibiansky

Run setup if no haskell profile exists. Closes #65.

parent b82c1577
...@@ -33,9 +33,11 @@ ipython suppress args = do ...@@ -33,9 +33,11 @@ ipython suppress args = do
putStrLn "Could not find `ipython` executable." putStrLn "Could not find `ipython` executable."
fail "`ipython` not on $PATH." fail "`ipython` not on $PATH."
Just ipythonPath -> runHandles ipythonPath args handles doNothing Just ipythonPath -> runHandles ipythonPath args handles doNothing
where handles = [InHandle Inherit, outHandle suppress, ErrorHandle Inherit] where handles = [InHandle Inherit, outHandle suppress, errorHandle suppress]
outHandle True = OutHandle CreatePipe outHandle True = OutHandle CreatePipe
outHandle False = OutHandle Inherit outHandle False = OutHandle Inherit
errorHandle True = ErrorHandle CreatePipe
errorHandle False = ErrorHandle Inherit
doNothing _ stdout _ = if suppress doNothing _ stdout _ = if suppress
then liftIO $ StrictIO.hGetContents stdout then liftIO $ StrictIO.hGetContents stdout
else return "" else return ""
...@@ -59,14 +61,25 @@ runIHaskell :: String -- ^ IHaskell profile name. ...@@ -59,14 +61,25 @@ runIHaskell :: String -- ^ IHaskell profile name.
-> String -- ^ IPython app name. -> String -- ^ IPython app name.
-> [String] -- ^ Arguments to IPython. -> [String] -- ^ Arguments to IPython.
-> IO () -> IO ()
runIHaskell profile app args = void . shelly . ipython False $ [pack app, "--profile", pack profile] ++ map pack args runIHaskell profile app args = void . shelly $ do
-- Try to locate the profile. Do not die if it doesn't exist.
errExit False $ ipython True ["locate", "profile", pack profile]
-- If the profile doesn't exist, create it.
exitCode <- lastExitCode
when (exitCode /= 0) $ liftIO $ do
putStrLn "Creating IPython profile."
setupIPythonProfile profile
-- Run the IHaskell command.
ipython False $ map pack $ [app, "--profile", profile] ++ args
-- | Create the IPython profile. -- | Create the IPython profile.
setupIPythonProfile :: String -- ^ IHaskell profile name. setupIPythonProfile :: String -- ^ IHaskell profile name.
-> IO () -> IO ()
setupIPythonProfile profile = shelly $ do setupIPythonProfile profile = shelly $ do
-- Create the IPython profile. -- Create the IPython profile.
void $ ipython False ["profile", "create", pack profile] void $ ipython True ["profile", "create", pack profile]
-- Find the IPython profile directory. Make sure to get rid of trailing -- Find the IPython profile directory. Make sure to get rid of trailing
-- newlines from the output of the `ipython locate` call. -- newlines from the output of the `ipython locate` call.
......
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