Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gargantext-ihaskell
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
gargantext-ihaskell
Commits
42d24930
Commit
42d24930
authored
Mar 16, 2014
by
Andrew Gibiansky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding types and scaffold for widgets.
parent
47e0bbec
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
171 additions
and
24 deletions
+171
-24
build.sh
build.sh
+9
-1
Parser.hs
ipython-kernel/src/IPython/Message/Parser.hs
+34
-0
UUID.hs
ipython-kernel/src/IPython/Message/UUID.hs
+1
-1
Writer.hs
ipython-kernel/src/IPython/Message/Writer.hs
+15
-0
Types.hs
ipython-kernel/src/IPython/Types.hs
+28
-1
Display.hs
src/IHaskell/Display.hs
+1
-10
Types.hs
src/IHaskell/Types.hs
+42
-4
Main.hs
src/Main.hs
+41
-7
No files found.
build.sh
View file @
42d24930
...
@@ -36,8 +36,9 @@ INSTALLS="$INSTALLS ."
...
@@ -36,8 +36,9 @@ INSTALLS="$INSTALLS ."
if
[
$#
-gt
0
]
;
then
if
[
$#
-gt
0
]
;
then
if
[
$1
=
"display"
]
;
then
if
[
$1
=
"display"
]
;
then
# Install all the display libraries
# Install all the display libraries
# However, install ihaskell-diagrams separately...
cd
ihaskell-display
cd
ihaskell-display
for
dir
in
`
ls
`
for
dir
in
`
ls
|
grep
-v
diagrams
`
do
do
INSTALLS
=
"
$INSTALLS
ihaskell-display/
$dir
"
INSTALLS
=
"
$INSTALLS
ihaskell-display/
$dir
"
done
done
...
@@ -57,3 +58,10 @@ done
...
@@ -57,3 +58,10 @@ done
# Stick a "./" before everything.
# Stick a "./" before everything.
INSTALL_DIRS
=
`
echo
$INSTALLS
|
tr
' '
'\n'
|
sed
's#^#./#'
|
tr
' '
'\n'
`
INSTALL_DIRS
=
`
echo
$INSTALLS
|
tr
' '
'\n'
|
sed
's#^#./#'
|
tr
' '
'\n'
`
cabal
install
-j
$INSTALL_DIRS
--force-reinstalls
cabal
install
-j
$INSTALL_DIRS
--force-reinstalls
# Finish installing ihaskell-diagrams.
if
[
$#
-gt
0
]
;
then
if
[
$1
=
"display"
]
;
then
cabal
install
-j
ihaskell-display/ihaskell-diagrams
--force-reinstalls
fi
fi
ipython-kernel/src/IPython/Message/Parser.hs
View file @
42d24930
...
@@ -82,6 +82,9 @@ parser CompleteRequestMessage = completeRequestParser
...
@@ -82,6 +82,9 @@ parser CompleteRequestMessage = completeRequestParser
parser
ObjectInfoRequestMessage
=
objectInfoRequestParser
parser
ObjectInfoRequestMessage
=
objectInfoRequestParser
parser
ShutdownRequestMessage
=
shutdownRequestParser
parser
ShutdownRequestMessage
=
shutdownRequestParser
parser
InputReplyMessage
=
inputReplyParser
parser
InputReplyMessage
=
inputReplyParser
parser
CommOpenMessage
=
commOpenParser
parser
CommDataMessage
=
commDataParser
parser
CommCloseMessage
=
commCloseParser
parser
other
=
error
$
"Unknown message type "
++
show
other
parser
other
=
error
$
"Unknown message type "
++
show
other
-- | Parse a kernel info request.
-- | Parse a kernel info request.
...
@@ -155,3 +158,34 @@ inputReplyParser content = parsed
...
@@ -155,3 +158,34 @@ inputReplyParser content = parsed
return
$
InputReply
noHeader
value
return
$
InputReply
noHeader
value
Just
decoded
=
decode
content
Just
decoded
=
decode
content
commOpenParser
::
LByteString
->
Message
commOpenParser
content
=
parsed
where
Success
parsed
=
flip
parse
decoded
$
\
obj
->
do
uuid
<-
obj
.:
"comm_id"
name
<-
obj
.:
"target_name"
value
<-
obj
.:
"data"
return
$
CommOpen
noHeader
name
uuid
value
Just
decoded
=
decode
content
commDataParser
::
LByteString
->
Message
commDataParser
content
=
parsed
where
Success
parsed
=
flip
parse
decoded
$
\
obj
->
do
uuid
<-
obj
.:
"comm_id"
value
<-
obj
.:
"data"
return
$
CommData
noHeader
uuid
value
Just
decoded
=
decode
content
commCloseParser
::
LByteString
->
Message
commCloseParser
content
=
parsed
where
Success
parsed
=
flip
parse
decoded
$
\
obj
->
do
uuid
<-
obj
.:
"comm_id"
value
<-
obj
.:
"data"
return
$
CommClose
noHeader
uuid
value
Just
decoded
=
decode
content
ipython-kernel/src/IPython/Message/UUID.hs
View file @
42d24930
...
@@ -23,7 +23,7 @@ import Text.Read as Read hiding (pfail, String)
...
@@ -23,7 +23,7 @@ import Text.Read as Read hiding (pfail, String)
-- them.
-- them.
-- | A UUID (universally unique identifier).
-- | A UUID (universally unique identifier).
data
UUID
=
UUID
String
deriving
(
Show
,
Read
,
Eq
)
data
UUID
=
UUID
String
deriving
(
Show
,
Read
,
Eq
,
Ord
)
-- | Generate a list of random UUIDs.
-- | Generate a list of random UUIDs.
randoms
::
Int
-- ^ Number of UUIDs to generate.
randoms
::
Int
-- ^ Number of UUIDs to generate.
...
...
ipython-kernel/src/IPython/Message/Writer.hs
View file @
42d24930
...
@@ -87,6 +87,21 @@ instance ToJSON Message where
...
@@ -87,6 +87,21 @@ instance ToJSON Message where
"prompt"
.=
prompt
"prompt"
.=
prompt
]
]
toJSON
req
@
CommOpen
{}
=
object
[
"comm_id"
.=
commUuid
req
,
"target_name"
.=
commTargetName
req
,
"data"
.=
commData
req
]
toJSON
req
@
CommData
{}
=
object
[
"comm_id"
.=
commUuid
req
,
"data"
.=
commData
req
]
toJSON
req
@
CommClose
{}
=
object
[
"comm_id"
.=
commUuid
req
,
"data"
.=
commData
req
]
toJSON
body
=
error
$
"Do not know how to convert to JSON for message "
++
show
body
toJSON
body
=
error
$
"Do not know how to convert to JSON for message "
++
show
body
...
...
ipython-kernel/src/IPython/Types.hs
View file @
42d24930
...
@@ -148,7 +148,10 @@ data MessageType = KernelInfoReplyMessage
...
@@ -148,7 +148,10 @@ data MessageType = KernelInfoReplyMessage
|
ClearOutputMessage
|
ClearOutputMessage
|
InputRequestMessage
|
InputRequestMessage
|
InputReplyMessage
|
InputReplyMessage
deriving
(
Show
,
Read
)
|
CommOpenMessage
|
CommDataMessage
|
CommCloseMessage
deriving
(
Show
,
Read
,
Eq
)
showMessageType
::
MessageType
->
String
showMessageType
::
MessageType
->
String
showMessageType
KernelInfoReplyMessage
=
"kernel_info_reply"
showMessageType
KernelInfoReplyMessage
=
"kernel_info_reply"
...
@@ -169,6 +172,9 @@ showMessageType ShutdownReplyMessage = "shutdown_reply"
...
@@ -169,6 +172,9 @@ showMessageType ShutdownReplyMessage = "shutdown_reply"
showMessageType
ClearOutputMessage
=
"clear_output"
showMessageType
ClearOutputMessage
=
"clear_output"
showMessageType
InputRequestMessage
=
"input_request"
showMessageType
InputRequestMessage
=
"input_request"
showMessageType
InputReplyMessage
=
"input_reply"
showMessageType
InputReplyMessage
=
"input_reply"
showMessageType
CommOpenMessage
=
"comm_open"
showMessageType
CommDataMessage
=
"comm_msg"
showMessageType
CommCloseMessage
=
"comm_close"
instance
FromJSON
MessageType
where
instance
FromJSON
MessageType
where
parseJSON
(
String
s
)
=
case
s
of
parseJSON
(
String
s
)
=
case
s
of
...
@@ -190,6 +196,9 @@ instance FromJSON MessageType where
...
@@ -190,6 +196,9 @@ instance FromJSON MessageType where
"clear_output"
->
return
ClearOutputMessage
"clear_output"
->
return
ClearOutputMessage
"input_request"
->
return
InputRequestMessage
"input_request"
->
return
InputRequestMessage
"input_reply"
->
return
InputReplyMessage
"input_reply"
->
return
InputReplyMessage
"comm_open"
->
return
CommOpenMessage
"comm_msg"
->
return
CommDataMessage
"comm_close"
->
return
CommCloseMessage
_
->
fail
(
"Unknown message type: "
++
show
s
)
_
->
fail
(
"Unknown message type: "
++
show
s
)
parseJSON
_
=
fail
"Must be a string."
parseJSON
_
=
fail
"Must be a string."
...
@@ -315,6 +324,24 @@ data Message
...
@@ -315,6 +324,24 @@ data Message
inputValue
::
String
inputValue
::
String
}
}
|
CommOpen
{
header
::
MessageHeader
,
commTargetName
::
String
,
commUuid
::
UUID
,
commData
::
Value
}
|
CommData
{
header
::
MessageHeader
,
commUuid
::
UUID
,
commData
::
Value
}
|
CommClose
{
header
::
MessageHeader
,
commUuid
::
UUID
,
commData
::
Value
}
deriving
Show
deriving
Show
-- | Possible statuses in the execution reply messages.
-- | Possible statuses in the execution reply messages.
...
...
src/IHaskell/Display.hs
View file @
42d24930
...
@@ -19,6 +19,7 @@ import Data.ByteString hiding (map, pack)
...
@@ -19,6 +19,7 @@ import Data.ByteString hiding (map, pack)
import
Data.String.Utils
(
rstrip
)
import
Data.String.Utils
(
rstrip
)
import
qualified
Data.ByteString.Base64
as
Base64
import
qualified
Data.ByteString.Base64
as
Base64
import
qualified
Data.ByteString.Char8
as
Char
import
qualified
Data.ByteString.Char8
as
Char
import
Data.Aeson
(
Value
)
import
Control.Concurrent.STM.TChan
import
Control.Concurrent.STM.TChan
import
Control.Monad.STM
import
Control.Monad.STM
...
@@ -28,16 +29,6 @@ import IHaskell.Types
...
@@ -28,16 +29,6 @@ import IHaskell.Types
type
Base64
=
Text
type
Base64
=
Text
-- | A class for displayable Haskell types.
--
-- IHaskell's displaying of results behaves as if these two
-- overlapping/undecidable instances also existed:
--
-- > instance (Show a) => IHaskellDisplay a
-- > instance Show a where shows _ = id
class
IHaskellDisplay
a
where
display
::
a
->
IO
Display
-- | these instances cause the image, html etc. which look like:
-- | these instances cause the image, html etc. which look like:
--
--
-- > Display
-- > Display
...
...
src/IHaskell/Types.hs
View file @
42d24930
{-# LANGUAGE NoImplicitPrelude, OverloadedStrings, DeriveDataTypeable, DeriveGeneric #-}
{-# LANGUAGE NoImplicitPrelude, OverloadedStrings, DeriveDataTypeable, DeriveGeneric #-}
{-# LANGUAGE ExistentialQuantification #-}
-- | Description : All message type definitions.
-- | Description : All message type definitions.
module
IHaskell.Types
(
module
IHaskell.Types
(
Message
(
..
),
Message
(
..
),
...
@@ -24,20 +25,23 @@ module IHaskell.Types (
...
@@ -24,20 +25,23 @@ module IHaskell.Types (
extractPlain
,
extractPlain
,
kernelOpts
,
kernelOpts
,
KernelOpt
(
..
),
KernelOpt
(
..
),
IHaskellDisplay
(
..
),
IHaskellWidget
(
..
),
Widget
(
..
),
)
where
)
where
import
ClassyPrelude
import
ClassyPrelude
import
qualified
Data.ByteString.Char8
as
Char
import
qualified
Data.ByteString.Char8
as
Char
import
Data.Serialize
import
Data.Serialize
import
GHC.Generics
import
GHC.Generics
import
Data.Map
(
Map
,
empty
)
import
Data.Aeson
(
Value
)
import
Text.Read
as
Read
hiding
(
pfail
,
String
)
import
Text.Read
as
Read
hiding
(
pfail
,
String
)
import
Text.ParserCombinators.ReadP
import
Text.ParserCombinators.ReadP
import
IPython.Kernel
import
IPython.Kernel
data
Test
=
Test
data
ViewFormat
data
ViewFormat
=
Pdf
=
Pdf
|
Html
|
Html
...
@@ -66,6 +70,38 @@ instance Read ViewFormat where
...
@@ -66,6 +70,38 @@ instance Read ViewFormat where
"md"
->
return
Markdown
"md"
->
return
Markdown
_
->
pfail
_
->
pfail
-- | A class for displayable Haskell types.
--
-- IHaskell's displaying of results behaves as if these two
-- overlapping/undecidable instances also existed:
--
-- > instance (Show a) => IHaskellDisplay a
-- > instance Show a where shows _ = id
class
IHaskellDisplay
a
where
display
::
a
->
IO
Display
-- | Display as an interactive widget.
class
IHaskellDisplay
a
=>
IHaskellWidget
a
where
open
::
a
-- ^ Widget to open a comm port with.
->
Value
-- ^ Comm open metadata.
->
(
Value
->
IO
()
)
-- ^ Way to respond to the message.
->
IO
()
comm
::
a
-- ^ Widget which is being communicated with.
->
Value
-- ^ Sent data.
->
(
Value
->
IO
()
)
-- ^ Way to respond to the message.
->
IO
()
close
::
a
-- ^ Widget to close comm port with.
->
Value
-- ^ Sent data.
->
IO
()
data
Widget
=
forall
a
.
IHaskellWidget
a
=>
Widget
a
instance
Show
Widget
where
show
_
=
"<Widget>"
-- | Wrapper for ipython-kernel's DisplayData which allows sending multiple
-- | Wrapper for ipython-kernel's DisplayData which allows sending multiple
-- results from the same expression.
-- results from the same expression.
data
Display
=
Display
[
DisplayData
]
data
Display
=
Display
[
DisplayData
]
...
@@ -90,7 +126,8 @@ data KernelState = KernelState
...
@@ -90,7 +126,8 @@ data KernelState = KernelState
getFrontend
::
FrontendType
,
getFrontend
::
FrontendType
,
useSvg
::
Bool
,
useSvg
::
Bool
,
useShowErrors
::
Bool
,
useShowErrors
::
Bool
,
useShowTypes
::
Bool
useShowTypes
::
Bool
,
openComms
::
Map
UUID
Widget
}
}
deriving
Show
deriving
Show
...
@@ -101,7 +138,8 @@ defaultKernelState = KernelState
...
@@ -101,7 +138,8 @@ defaultKernelState = KernelState
getFrontend
=
IPythonConsole
,
getFrontend
=
IPythonConsole
,
useSvg
=
True
,
useSvg
=
True
,
useShowErrors
=
False
,
useShowErrors
=
False
,
useShowTypes
=
False
useShowTypes
=
False
,
openComms
=
empty
}
}
data
FrontendType
data
FrontendType
...
...
src/Main.hs
View file @
42d24930
...
@@ -180,17 +180,29 @@ runKernel profileSrc initInfo = do
...
@@ -180,17 +180,29 @@ runKernel profileSrc initInfo = do
-- Create a header for the reply.
-- Create a header for the reply.
replyHeader
<-
createReplyHeader
(
header
request
)
replyHeader
<-
createReplyHeader
(
header
request
)
-- Create the reply, possibly modifying kernel state.
-- We handle comm messages and normal ones separately.
oldState
<-
liftIO
$
takeMVar
state
-- The normal ones are a standard request/response style, while comms
(
newState
,
reply
)
<-
replyTo
interface
request
replyHeader
oldState
-- can be anything, and don't necessarily require a response.
liftIO
$
putMVar
state
newState
if
isCommMessage
request
then
liftIO
$
do
-- Write the reply to the reply channel.
oldState
<-
takeMVar
state
liftIO
$
writeChan
(
shellReplyChannel
interface
)
reply
let
replier
=
writeChan
(
shellReplyChannel
interface
)
newState
<-
handleComm
replier
oldState
request
replyHeader
putMVar
state
newState
else
do
-- Create the reply, possibly modifying kernel state.
oldState
<-
liftIO
$
takeMVar
state
(
newState
,
reply
)
<-
replyTo
interface
request
replyHeader
oldState
liftIO
$
putMVar
state
newState
-- Write the reply to the reply channel.
liftIO
$
writeChan
(
shellReplyChannel
interface
)
reply
where
where
ignoreCtrlC
=
ignoreCtrlC
=
installHandler
keyboardSignal
(
CatchOnce
$
putStrLn
"Press Ctrl-C again to quit kernel."
)
Nothing
installHandler
keyboardSignal
(
CatchOnce
$
putStrLn
"Press Ctrl-C again to quit kernel."
)
Nothing
isCommMessage
req
=
msgType
(
header
req
)
`
elem
`
[
CommOpenMessage
,
CommDataMessage
,
CommCloseMessage
]
-- Initial kernel state.
-- Initial kernel state.
initialKernelState
::
IO
(
MVar
KernelState
)
initialKernelState
::
IO
(
MVar
KernelState
)
initialKernelState
=
initialKernelState
=
...
@@ -348,3 +360,25 @@ replyTo _ ObjectInfoRequest{objectName = oname} replyHeader state = do
...
@@ -348,3 +360,25 @@ replyTo _ ObjectInfoRequest{objectName = oname} replyHeader state = do
objectDocString
=
docs
objectDocString
=
docs
}
}
return
(
state
,
reply
)
return
(
state
,
reply
)
handleComm
::
(
Message
->
IO
()
)
->
KernelState
->
Message
->
MessageHeader
->
IO
KernelState
handleComm
replier
kernelState
req
replyHeader
=
do
let
widgets
=
openComms
kernelState
uuid
=
commUuid
req
dat
=
commData
req
communicate
value
=
do
head
<-
dupHeader
replyHeader
CommDataMessage
replier
$
CommData
head
uuid
value
case
lookup
uuid
widgets
of
Nothing
->
fail
$
"no widget with uuid "
++
show
uuid
Just
(
Widget
widget
)
->
case
msgType
$
header
req
of
CommOpenMessage
->
do
open
widget
dat
communicate
return
kernelState
CommDataMessage
->
do
comm
widget
dat
communicate
return
kernelState
CommCloseMessage
->
do
close
widget
dat
return
kernelState
{
openComms
=
Map
.
delete
uuid
widgets
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment