Commit 0c161751 authored by Andrew Gibiansky's avatar Andrew Gibiansky

Updates

parent 35e469d1
......@@ -78,7 +78,7 @@ if [ ! $2 = "no-widgets" ] && { [ $1 = "display" ] || [ $1 = "all" ]; } then
fi
if hash ihaskell 2>/dev/null; then
ihaskell install 2>/dev/null || echo "The command \"ihaskell install\" failed. Please check your 'ipython --version'. 3.0 or up is required but it is $(ipython --version)!"
ihaskell install 2>/dev/null || echo "The command \"ihaskell install\" failed. Please check your 'ipython --version'. 3.0 or up is required. Yours is $(ipython --version)."
else
echo "Reminder: run 'ihaskell install' to install the IHaskell kernel to Jupyter."
fi
......@@ -2,7 +2,7 @@
-- documentation, see http://haskell.org/cabal/users-guide/
name: ghc-parser
version: 0.1.7.0
version: 0.1.8.0
synopsis: Haskell source parser from GHC.
-- description:
homepage: https://github.com/gibiansky/IHaskell
......@@ -16,13 +16,16 @@ build-type: Custom
-- extra-source-files:
cabal-version: >=1.16
-- hs-source-dirs doesn't work well, doesn't take union, so include all src dirs specifically
extra-source-files:
build-parser.sh
HaskellParser76.y.pp
HaskellParser782.y.pp
HaskellParser783.y.pp
src-7.10/Language/Haskell/GHC/HappyParser.hs
src-7.8.2/Language/Haskell/GHC/HappyParser.hs
src-7.8.3/Language/Haskell/GHC/HappyParser.hs
src-7.6/Language/Haskell/GHC/HappyParser.hs
library
build-tools: happy, cpphs
......
......@@ -297,6 +297,11 @@ replyTo _ HistoryRequest{} replyHeader state = do
}
return (state, reply)
-- TODO: What else can be implemented?
replyTo _ message _ state = do
liftIO $ hPutStrLn stderr $ "Unimplemented message: " ++ show message
return (state, SendNothing)
-- | Handle comm messages
handleComm :: (Message -> IO ()) -> KernelState -> Message -> MessageHeader -> Interpreter KernelState
handleComm send kernelState req replyHeader = do
......
......@@ -30,6 +30,7 @@ import System.Exit (exitFailure)
import Data.Aeson (toJSON)
import Data.Aeson.Encode (encodeToTextBuilder)
import Data.Text.Lazy.Builder (toLazyText)
import Control.Monad (mplus)
import qualified System.IO.Strict as StrictIO
import qualified Paths_ihaskell as Paths
......@@ -61,6 +62,14 @@ kernelName = "haskell"
kernelArgs :: [String]
kernelArgs = ["--kernel", kernelName]
ipythonCommand :: SH.Sh SH.FilePath
ipythonCommand = do
jupyterMay <- SH.which "jupyter"
return $
case jupyterMay of
Nothing -> "ipython"
Just _ -> "jupyter"
-- | Run the IPython command with any arguments. The kernel is set to IHaskell.
ipython :: Bool -- ^ Whether to suppress output.
-> [Text] -- ^ IPython command line arguments.
......@@ -69,7 +78,8 @@ ipython suppress args = do
liftIO $ installHandler keyboardSignal (CatchOnce $ return ()) Nothing
-- We have this because using `run` does not let us use stdin.
SH.runHandles "jupyter" args handles doNothing
cmd <- ipythonCommand
SH.runHandles cmd args handles doNothing
where
handles = [SH.InHandle SH.Inherit, outHandle suppress, errorHandle suppress]
......@@ -103,9 +113,6 @@ ihaskellDir = do
home <- maybe (error "$HOME not defined.") SH.fromText <$> SH.get_env "HOME"
fp <$> ensure (return (home SH.</> ".ihaskell"))
ipythonDir :: SH.Sh SH.FilePath
ipythonDir = ensure $ (SH.</> "ipython") <$> ihaskellDir
notebookDir :: SH.Sh SH.FilePath
notebookDir = ensure $ (SH.</> "notebooks") <$> ihaskellDir
......@@ -128,43 +135,35 @@ replaceIPythonKernelspec kernelSpecOpts = SH.shelly $ do
-- | Verify that a proper version of IPython is installed and accessible.
verifyIPythonVersion :: SH.Sh ()
verifyIPythonVersion = do
pathMay <- SH.which "jupyter"
pathMay' <- SH.which "ipython"
case (pathMay, pathMay') of
(Nothing, Nothing) -> badIPython
"No Jupyter detected -- install Jupyter 3.0+ before using IHaskell."
(Just path, _) -> do
cmd <- ipythonCommand
pathMay <- SH.which cmd
case pathMay of
Nothing -> badIPython
"No Jupyter / IPython detected -- install Jupyter 3.0+ before using IHaskell."
Just path -> do
stdout <- SH.silently (SH.run path ["--version"])
stderr <- SH.lastStderr
case parseVersion $ T.unpack stderr of
Just (4:_) -> return ()
Just (3:_) -> return ()
Just (2:_) -> oldIPython
Just (1:_) -> oldIPython
Just (0:_) -> oldIPython
_ -> badIPython $ T.concat
[ "Detected Jupyter, but could not parse version number."
, "\n"
, "(stdout = "
, stdout
, ", stderr = "
, stderr
, ")"
]
(_, Just path) -> do
output <- T.unpack <$> SH.silently (SH.run path ["--version"])
case parseVersion output of
Just (x:_) -> if x >= 3
then return ()
else oldIPython
_ -> badIPython "Detected IPython, but could not parse version number."
let majorVersion = join . fmap listToMaybe . parseVersion . T.unpack
case mplus (majorVersion stderr) (majorVersion stdout) of
Nothing -> badIPython $ T.concat
[ "Detected Jupyter, but could not parse version number."
, "\n"
, "(stdout = "
, stdout
, ", stderr = "
, stderr
, ")"
]
Just version -> when (version < 3) oldIPython
where
badIPython :: Text -> SH.Sh ()
badIPython message = liftIO $ do
IO.hPutStrLn IO.stderr (T.unpack message)
exitFailure
oldIPython = badIPython "Detected old version of IPython. IHaskell requires 3.0.0 or up."
oldIPython = badIPython
"Detected old version of Jupyter / IPython. IHaskell requires 3.0.0 or up."
-- | Install an IHaskell kernelspec into the right location. The right location is determined by
-- using `ipython kernelspec install --user`.
......
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