ihaskell 0.6.4.1 → 0.6.5.0
raw patch · 3 files changed
+47/−20 lines, 3 filesdep ~aeson
Dependency ranges changed: aeson
Files
- ihaskell.cabal +6/−6
- main/Main.hs +9/−0
- src/IHaskell/IPython.hs +32/−14
ihaskell.cabal view
@@ -7,7 +7,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.6.4.1+version: 0.6.5.0 -- A short (one-line) description of the package. synopsis: A Haskell backend kernel for the IPython project.@@ -17,7 +17,7 @@ a console or notebook interface. Additional packages may be installed to provide richer data visualizations. -- URL for the project homepage or repository.-homepage: http://gibiansky.github.io/IHaskell/+homepage: http://github.com/gibiansky/IHaskell -- The license under which the package is released. license: MIT@@ -54,8 +54,8 @@ library hs-source-dirs: src default-language: Haskell2010- build-depends: - aeson >=0.7 && < 0.9,+ build-depends:+ aeson >=0.7 && < 0.10, base >=4.6 && < 4.9, base64-bytestring >=1.0, bytestring >=0.10,@@ -142,7 +142,7 @@ transformers -any, ghc >=7.6 || < 7.11, here ==1.2.*,- aeson >=0.7 && < 0.9,+ aeson >=0.7 && < 0.10, bytestring >=0.10, containers >=0.5, strict >=0.3,@@ -166,7 +166,7 @@ default-language: Haskell2010 build-depends: ihaskell,- aeson >=0.6 && < 0.9,+ aeson >=0.6 && < 0.10, base >=4.6 && < 4.9, base64-bytestring >=1.0, bytestring >=0.10,
main/Main.hs view
@@ -71,6 +71,10 @@ ihaskell (Args (Kernel (Just filename)) args) = do let kernelSpecOpts = parseKernelArgs args runKernel kernelSpecOpts filename+ihaskell a@(Args (Kernel Nothing) _) = do+ hPutStrLn stderr "No kernel profile JSON specified."+ hPutStrLn stderr "This may be a bug!"+ hPrint stderr a showingHelp :: IHaskellMode -> [Argument] -> IO () -> IO () showingHelp mode flags act =@@ -292,6 +296,11 @@ , historyReply = [] } 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
src/IHaskell/IPython.hs view
@@ -30,6 +30,7 @@ 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 @@ 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 @@ liftIO $ installHandler keyboardSignal (CatchOnce $ return ()) Nothing -- We have this because using `run` does not let us use stdin.- SH.runHandles "ipython" 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 @@ 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,24 +135,35 @@ -- | Verify that a proper version of IPython is installed and accessible. verifyIPythonVersion :: SH.Sh () verifyIPythonVersion = do- pathMay <- SH.which "ipython"+ cmd <- ipythonCommand+ pathMay <- SH.which cmd case pathMay of- Nothing -> badIPython "No IPython detected -- install IPython 3.0+ before using IHaskell."+ Nothing -> badIPython+ "No Jupyter / IPython detected -- install Jupyter 3.0+ before using IHaskell." Just path -> do- output <- T.unpack <$> SH.silently (SH.run path ["--version"])- case parseVersion output of- Just (3:_) -> return ()- Just (2:_) -> oldIPython- Just (1:_) -> oldIPython- Just (0:_) -> oldIPython- _ -> badIPython "Detected IPython, but could not parse version number."+ stdout <- SH.silently (SH.run path ["--version"])+ stderr <- SH.lastStderr+ 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`.