Skip to content

Commit

Permalink
Adding more general configuration mechanism.
Browse files Browse the repository at this point in the history
  • Loading branch information
gibiansky committed Oct 27, 2013
1 parent 89fdda8 commit e52d418
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
1 change: 1 addition & 0 deletions IHaskell.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ executable IHaskell
shelly ==1.3.*,
system-argv0,
directory,
here,
system-filepath,
text ==0.11.*
17 changes: 17 additions & 0 deletions IHaskell/Config.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{-# LANGUAGE QuasiQuotes #-}
module IHaskell.Config (ipython, notebook, console, qtconsole) where

import Data.String.Here
import ClassyPrelude

ipython :: String -> String
ipython executable = [template|config/ipython_config.py|]

notebook :: String
notebook = [template|config/ipython_notebook_config.py|]

console :: String
console = [template|config/ipython_console_config.py|]

qtconsole :: String
qtconsole = [template|config/ipython_qtconsole_config.py|]
19 changes: 8 additions & 11 deletions IHaskell/IPython.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import System.Argv0
import System.Directory
import qualified Filesystem.Path.CurrentOS as FS

import qualified IHaskell.Config as Config

-- | Run IPython with any arguments.
ipython :: [Text] -> Sh ()
ipython args = do
Expand Down Expand Up @@ -64,18 +66,13 @@ setupIPythonProfile profile = shelly $ do
writeConfigFilesTo :: Text -- ^ Profile directory to write to. Must have a trailing slash.
-> String -- ^ Path to IHaskell executable.
-> Sh ()
writeConfigFilesTo profileDir ihaskellPath = writeFile (fromText configFile) config
writeConfigFilesTo profileDir ihaskellPath = do
writeFile (conf "ipython_config.py") $ Config.ipython ihaskellPath
writeFile (conf "ipython_notebook_config.py") Config.notebook
writeFile (conf "ipython_console_config.py") Config.console
writeFile (conf "ipython_qtconsole_config.py") Config.qtconsole
where
configFile = profileDir ++ "ipython_config.py"

config :: String
config = unlines
[ "c = get_config()"
, printf "exe = '%s'.replace(' ', '\\\\ ')" ihaskellPath
, "c.KernelManager.kernel_cmd = [exe, 'kernel', '{connection_file}']"
, "c.Session.key = b''"
, "c.Session.keyfile = b''"
]
conf filename = fromText $ profileDir ++ filename

-- | Get the absolute path to this IHaskell executable.
getIHaskellPath :: Sh String
Expand Down
7 changes: 7 additions & 0 deletions config/ipython_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Available Subsitutions:
# ${executable}: Path to IHaskell kernel.
c = get_config()
exe = '${executable}'.replace(' ', '\\\\ ')
c.KernelManager.kernel_cmd = [exe, 'kernel', '{connection_file}']
c.Session.key = b''
c.Session.keyfile = b''
1 change: 1 addition & 0 deletions config/ipython_console_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Empty.
1 change: 1 addition & 0 deletions config/ipython_notebook_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Empty.
1 change: 1 addition & 0 deletions config/ipython_qtconsole_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Empty.

0 comments on commit e52d418

Please sign in to comment.