Commit a061e229 authored by Andrew Gibiansky's avatar Andrew Gibiansky

Update to newest kernel_info_reply protocol

parent 45011f5a
*.hi *.hi
Untitled*.ipynb
main/Main main/Main
.stack-work .stack-work
notebooks/Test.ipynb notebooks/Test.ipynb
......
name: ipython-kernel name: ipython-kernel
version: 0.6.1.3 version: 0.7
synopsis: A library for creating kernels for IPython frontends synopsis: A library for creating kernels for IPython frontends
description: ipython-kernel is a library for communicating with frontends for the interactive IPython framework. It is used extensively in IHaskell, the interactive Haskell environment. description: ipython-kernel is a library for communicating with frontends for the interactive IPython framework. It is used extensively in IHaskell, the interactive Haskell environment.
......
...@@ -70,11 +70,8 @@ import System.IO (openFile, IOMode(ReadMode)) ...@@ -70,11 +70,8 @@ import System.IO (openFile, IOMode(ReadMode))
data KernelConfig m output result = data KernelConfig m output result =
KernelConfig KernelConfig
{ {
-- | The name of the language. This field is used to calculate the name of the profile, -- | Info on the language of the kernel.
-- so it should contain characters that are reasonable to have in file names. kernelLanguageInfo :: LanguageInfo
languageName :: String
-- | The version of the language
, languageVersion :: [Int]
-- | Determine the source of a profile to install using 'installProfile'. The source should be a -- | Determine the source of a profile to install using 'installProfile'. The source should be a
-- tarball whose contents will be unpacked directly into the profile directory. For example, the -- tarball whose contents will be unpacked directly into the profile directory. For example, the
-- file whose name is @ipython_config.py@ in the tar file for a language named @lang@ will end up in -- file whose name is @ipython_config.py@ in the tar file for a language named @lang@ will end up in
...@@ -122,7 +119,7 @@ installProfile config = do ...@@ -122,7 +119,7 @@ installProfile config = do
where where
profDir = do profDir = do
home <- liftIO getHomeDirectory home <- liftIO getHomeDirectory
return $ home </> ".ipython" </> ("profile_" ++ languageName config) return $ home </> ".ipython" </> ("profile_" ++ languageName (kernelLanguageInfo config))
isInstalled = do isInstalled = do
prof <- profDir prof <- profDir
dirThere <- liftIO $ doesDirectoryExist prof dirThere <- liftIO $ doesDirectoryExist prof
...@@ -185,8 +182,9 @@ replyTo config _ _ KernelInfoRequest{} replyHeader = ...@@ -185,8 +182,9 @@ replyTo config _ _ KernelInfoRequest{} replyHeader =
return return
KernelInfoReply KernelInfoReply
{ header = replyHeader { header = replyHeader
, language = languageName config , languageInfo = kernelLanguageInfo config
, versionList = languageVersion config , implementation = "ipython-kernel.EasyKernel"
, implementationVersion = "0.0"
} }
replyTo config _ interface ShutdownRequest { restartPending = pending } replyHeader = do replyTo config _ interface ShutdownRequest { restartPending = pending } replyHeader = do
liftIO $ writeChan (shellReplyChannel interface) $ ShutdownReply replyHeader pending liftIO $ writeChan (shellReplyChannel interface) $ ShutdownReply replyHeader pending
...@@ -206,10 +204,10 @@ replyTo config execCount interface req@ExecuteRequest { getCode = code } replyHe ...@@ -206,10 +204,10 @@ replyTo config execCount interface req@ExecuteRequest { getCode = code } replyHe
sendOutput x = sendOutput x =
send $ PublishDisplayData send $ PublishDisplayData
outputHeader outputHeader
(languageName config) (languageName $ kernelLanguageInfo config)
(displayOutput config x) (displayOutput config x)
in run config code clearOutput sendOutput in run config code clearOutput sendOutput
liftIO . send $ PublishDisplayData outputHeader (languageName config) (displayResult config res) liftIO . send $ PublishDisplayData outputHeader (languageName $ kernelLanguageInfo config) (displayResult config res)
idleHeader <- dupHeader replyHeader StatusMessage idleHeader <- dupHeader replyHeader StatusMessage
...@@ -230,8 +228,8 @@ replyTo config _ _ req@CompleteRequest{} replyHeader = ...@@ -230,8 +228,8 @@ replyTo config _ _ req@CompleteRequest{} replyHeader =
-- TODO: FIX -- TODO: FIX
error "Completion: Unimplemented for IPython 3.0" error "Completion: Unimplemented for IPython 3.0"
replyTo _ _ _ InspectRequest{} _ = do replyTo _ _ _ InspectRequest{} _ =
error $ "Inspection: Unimplemented for IPython 3.0" error "Inspection: Unimplemented for IPython 3.0"
replyTo _ _ _ msg _ = do replyTo _ _ _ msg _ = do
liftIO $ putStrLn "Unknown message: " liftIO $ putStrLn "Unknown message: "
......
...@@ -16,11 +16,23 @@ import Data.Text.Encoding ...@@ -16,11 +16,23 @@ import Data.Text.Encoding
import IHaskell.IPython.Types import IHaskell.IPython.Types
instance ToJSON LanguageInfo where
toJSON info = object
[ "name" .= languageName info
, "version" .= languageVersion info
, "file_extension" .= languageFileExtension info
, "codemirror_mode" .= languageCodeMirrorMode info
]
-- Convert message bodies into JSON. -- Convert message bodies into JSON.
instance ToJSON Message where instance ToJSON Message where
toJSON KernelInfoReply { versionList = vers, language = language } = toJSON rep@KernelInfoReply{} =
object ["protocol_version" .= string "5.0" -- current protocol version, major and minor object
, "language_version" .= vers, "language" .= language] [ "protocol_version" .= string "5.0" -- current protocol version, major and minor
, "implementation" .= implementation rep
, "implementation_version" .= implementationVersion rep
, "language_info" .= languageInfo rep
]
toJSON ExecuteReply { status = status, executionCounter = counter, pagerOutput = pager } = toJSON ExecuteReply { status = status, executionCounter = counter, pagerOutput = pager } =
object object
......
...@@ -24,6 +24,7 @@ module IHaskell.IPython.Types ( ...@@ -24,6 +24,7 @@ module IHaskell.IPython.Types (
ExecuteReplyStatus(..), ExecuteReplyStatus(..),
HistoryAccessType(..), HistoryAccessType(..),
HistoryReplyElement(..), HistoryReplyElement(..),
LanguageInfo(..),
replyType, replyType,
showMessageType, showMessageType,
...@@ -246,6 +247,15 @@ instance FromJSON MessageType where ...@@ -246,6 +247,15 @@ instance FromJSON MessageType where
_ -> fail ("Unknown message type: " ++ show s) _ -> fail ("Unknown message type: " ++ show s)
parseJSON _ = fail "Must be a string." parseJSON _ = fail "Must be a string."
data LanguageInfo =
LanguageInfo
{ languageName :: String -- ^ The language name, e.g. "haskell"
, languageVersion :: String -- ^ GHC 7.6.3
, languageFileExtension :: String -- ^ .hs
, languageCodeMirrorMode :: String -- ^ 'ihaskell'. can be 'null'
}
deriving (Show, Eq)
-- | A message used to communicate with the IPython frontend. -- | A message used to communicate with the IPython frontend.
data Message = data Message =
-- | A request from a frontend for information about the kernel. -- | A request from a frontend for information about the kernel.
...@@ -254,9 +264,9 @@ data Message = ...@@ -254,9 +264,9 @@ data Message =
-- | A response to a KernelInfoRequest. -- | A response to a KernelInfoRequest.
KernelInfoReply KernelInfoReply
{ header :: MessageHeader { header :: MessageHeader
, versionList :: [Int] -- ^ The version of the language, e.g. [7, 6, 3] for GHC , implementation :: String -- ^ e.g. IHaskell
-- 7.6.3 , implementationVersion :: String -- ^ The version of the implementation
, language :: String -- ^ The language name, e.g. "haskell" , languageInfo :: LanguageInfo
} }
| |
-- | A request from a frontend to execute some code. -- | A request from a frontend to execute some code.
......
...@@ -229,8 +229,14 @@ replyTo _ KernelInfoRequest{} replyHeader state = ...@@ -229,8 +229,14 @@ replyTo _ KernelInfoRequest{} replyHeader state =
return return
(state, KernelInfoReply (state, KernelInfoReply
{ header = replyHeader { header = replyHeader
, language = "haskell" , implementation = "IHaskell"
, versionList = ghcVersionInts , implementationVersion = VERSION_ipython_kernel
, languageInfo = LanguageInfo
{ languageName = "haskell"
, languageVersion = VERSION_ghc
, languageFileExtension = ".hs"
, languageCodeMirrorMode = "ihaskell"
}
}) })
-- Reply to a shutdown request by exiting the main thread. Before shutdown, reply to the request to -- Reply to a shutdown request by exiting the main thread. Before shutdown, reply to the request to
......
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