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