Commit a638a86d authored by Andrew Gibiansky's avatar Andrew Gibiansky

Updated to reflect ipython 2.0 installation.

parent 54d87a4c
...@@ -44,7 +44,6 @@ cabal-version: >=1.16 ...@@ -44,7 +44,6 @@ cabal-version: >=1.16
data-files: data-files:
installation/ipython.sh installation/ipython.sh
installation/update.sh
installation/virtualenv.sh installation/virtualenv.sh
installation/run.sh installation/run.sh
profile/profile.tar profile/profile.tar
......
...@@ -4,9 +4,6 @@ set -e ...@@ -4,9 +4,6 @@ set -e
# Which virtualenv to use. # Which virtualenv to use.
VIRTUALENV=$1 VIRTUALENV=$1
# Commit hash to install.
COMMIT=$2
# Activate the virtualenv. # Activate the virtualenv.
source $VIRTUALENV/bin/activate source $VIRTUALENV/bin/activate
...@@ -32,4 +29,4 @@ pip install pygments==1.6 ...@@ -32,4 +29,4 @@ pip install pygments==1.6
# Install IPython itself. # Install IPython itself.
echo "Installing IPython (this may take a while)." echo "Installing IPython (this may take a while)."
pip install -e git+https://github.com/gibiansky/ipython.git@$COMMIT#egg=ipython-dev pip install ipython
#!/bin/bash
set -e
# Which virtualenv to use.
VIRTUALENV=$1
# Commit hash to install.
COMMIT=$2
# Find out current IPython commit hash.
cd $VIRTUALENV/src/ipython
CURRENT_COMMIT=`git rev-parse HEAD`
if [ $CURRENT_COMMIT != $COMMIT ]; then
# Activate the virtualenv.
source $VIRTUALENV/bin/activate
# Update IPython.
echo "Updating IPython (this may take a while)."
pip install --upgrade -e git+https://github.com/gibiansky/ipython.git@$COMMIT#egg=ipython-dev
fi;
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"metadata": { "metadata": {
"language": "haskell", "language": "haskell",
"name": "", "name": "",
"signature": "sha256:7873a6c9359f5b20e15e69afed5eebbaf984eaad2c41d5917c94c263fa2baef4" "signature": "sha256:536bbec84803f76deffe5c6fa15e83da024329a05073740fdd8affb98caf1834"
}, },
"nbformat": 3, "nbformat": 3,
"nbformat_minor": 0, "nbformat_minor": 0,
...@@ -102,99 +102,24 @@ ...@@ -102,99 +102,24 @@
"outputs": [ "outputs": [
{ {
"html": [ "html": [
"<!-- CodeMirror component -->\n", "<div class='collapse-group'><span class='btn' href='#' id='unshowable'>Unshowable:<span class='show-type'>Parser List</span></span><span class='err-msg collapse'>No instance for (Show (Parser List)) arising from a use of `print'<br/>Possible fix: add an instance declaration for (Show (Parser List))<br/>In a stmt of an interactive GHCi command: print it</span></div><script>$('#unshowable').on('click', function(e) {\n",
"<link rel=\"stylesheet\" href=\"/static/components/codemirror/addon/lint/lint.css\">\n", " e.preventDefault();\n",
"<script src=\"/static/components/codemirror/addon/lint/lint.js\" charset=\"utf-8\"></script>\n", " var $this = $(this);\n",
"\n", " var $collapse = $this.closest('.collapse-group').find('.err-msg');\n",
"<!-- Parsec widget -->\n", " $collapse.collapse('toggle');\n",
"<script>\n", "});\n",
"// Only load this script once.\n", "</script>"
"var kernel = IPython.notebook.kernel;\n",
"var initialized = kernel !== undefined && kernel != null;\n",
"if (initialized && window.parsecWidgetRegistered === undefined) {\n",
"\n",
"// Do not load this script again.\n",
"window.parsecWidgetRegistered = true;\n",
"\n",
"// Register the comm target.\n",
"var ParsecWidget = function (comm) {\n",
" this.comm = comm;\n",
" this.comm.on_msg($.proxy(this.handler, this));\n",
"\n",
" // Get the cell that was probably executed.\n",
" // The msg_id:cell mapping will make this possible without guessing.\n",
" this.cell = IPython.notebook.get_cell(IPython.notebook.get_selected_index()-1);\n",
"\n",
" // Store this widget so we can use it from callbacks.\n",
" var widget = this;\n",
"\n",
" // Editor options.\n",
" var options = {\n",
" lineNumbers: true,\n",
" // Show parsec errors as lint errors.\n",
" gutters: [\"CodeMirror-lint-markers\"],\n",
" lintWith: {\n",
" \"getAnnotations\": function(cm, update, opts) {\n",
" var errs = [];\n",
" if (widget.hasError) {\n",
" var col = widget.error[\"col\"];\n",
" var line = widget.error[\"line\"];\n",
" errs = [{\n",
" from: CodeMirror.Pos(line - 1, col - 1),\n",
" to: CodeMirror.Pos(line - 1, col),\n",
" message: widget.error[\"msg\"],\n",
" severity: \"error\"\n",
" }];\n",
" }\n",
" update(cm, errs);\n",
" },\n",
" \"async\": true,\n",
" }\n",
" };\n",
"\n",
" // Create the editor.\n",
" var out = this.cell.output_area.element;\n",
" this.textarea = out.find(\"#parsec-editor\")[0];\n",
" this.output = out.find(\"#parsec-output\")[0];\n",
"\n",
" var editor = CodeMirror.fromTextArea(this.textarea, options);\n",
" var editor = editor;\n",
"\n",
" // Update every key press.\n",
" editor.on(\"keyup\", function() {\n",
" var text = editor.getDoc().getValue();\n",
" comm.send({\"text\": text});\n",
" });\n",
"};\n",
"\n",
"ParsecWidget.prototype.handler = function(msg) {\n",
" var data = msg.content.data;\n",
" this.hasError = data[\"status\"] == \"error\";\n",
" if (this.hasError) {\n",
" out = data[\"msg\"];\n",
" this.error = data;\n",
" } else {\n",
" out = data[\"result\"];\n",
" }\n",
" // Update viewed output.\n",
" this.output.innerHTML = out;\n",
"};\n",
"\n",
"// Register this widget.\n",
"IPython.notebook.kernel.comm_manager.register_target('parsec', IPython.utils.always_new(ParsecWidget));\n",
"console.log(\"Registering Parsec widget.\");\n",
"}\n",
"</script>\n",
"\n",
"<!-- Parsec widget DOM -->\n",
"<form><textarea id=\"parsec-editor\">Insert parser text here...</textarea></form>\n",
"<pre id=\"parsec-output\"></pre>\n"
], ],
"metadata": {}, "metadata": {},
"output_type": "display_data" "output_type": "display_data",
"text": [
"No instance for (Show (Parser List)) arising from a use of `print'\n",
"Possible fix: add an instance declaration for (Show (Parser List))\n",
"In a stmt of an interactive GHCi command: print it"
]
} }
], ],
"prompt_number": 4 "prompt_number": 2
}, },
{ {
"cell_type": "code", "cell_type": "code",
......
...@@ -26,6 +26,7 @@ import qualified Filesystem.Path.CurrentOS as FS ...@@ -26,6 +26,7 @@ import qualified Filesystem.Path.CurrentOS as FS
import Data.List.Utils (split) import Data.List.Utils (split)
import Data.String.Utils (rstrip, endswith, strip, replace) import Data.String.Utils (rstrip, endswith, strip, replace)
import Text.Printf import Text.Printf
import Data.Maybe (fromJust)
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
...@@ -40,10 +41,6 @@ data WhichIPython ...@@ -40,10 +41,6 @@ data WhichIPython
| ExplicitIPython String -- ^ Use the command-line flag provided one. | ExplicitIPython String -- ^ Use the command-line flag provided one.
deriving Eq deriving Eq
-- | Which commit of IPython we are on.
ipythonCommit :: Text
ipythonCommit = "9c1c7a7e32118942a06eb39909c942e628090c14"
-- | The IPython profile name. -- | The IPython profile name.
ipythonProfile :: String ipythonProfile :: String
ipythonProfile = "haskell" ipythonProfile = "haskell"
...@@ -164,9 +161,30 @@ setupIPython (ExplicitIPython path) = do ...@@ -164,9 +161,30 @@ setupIPython (ExplicitIPython path) = do
setupIPython DefaultIPython = do setupIPython DefaultIPython = do
installed <- ipythonInstalled installed <- ipythonInstalled
if installed when (not installed) $ do
then updateIPython path <- shelly $ which "ipython"
else installIPython case path of
Just ipythonPath -> checkIPythonVersion ipythonPath
Nothing -> badIPython "Did not detect IHaskell-installed or system IPython."
where
checkIPythonVersion :: FilePath -> IO ()
checkIPythonVersion path = do
output <- unpack <$> shelly (run path ["--version"])
case parseVersion output of
Just (2:_) -> putStrLn "Detected IPython 2.0.0 or higher, using system-wide IPython."
Just (1:_) -> badIPython "Detected old version of IPython. IHaskell requires 2.0.0 or up."
Nothing -> badIPython "Detected IPython, but could not parse version number."
badIPython :: Text -> IO ()
badIPython reason = void $ do
putStrLn reason
putStrLn "IHaskell will not proceed to install IPython (locally for itself)."
putStrLn "Installing IPython in IHaskell's virtualenv in 10 seconds. Ctrl-C to cancel."
threadDelay $ 1000 * 1000 * 10
installIPython
-- | Replace "~" with $HOME if $HOME is defined. -- | Replace "~" with $HOME if $HOME is defined.
-- Otherwise, do nothing. -- Otherwise, do nothing.
...@@ -188,11 +206,16 @@ path exe = do ...@@ -188,11 +206,16 @@ path exe = do
Just exePath -> return exePath Just exePath -> return exePath
-- | Parse an IPython version string into a list of integers. -- | Parse an IPython version string into a list of integers.
parseVersion :: String -> [Int] parseVersion :: String -> Maybe [Int]
parseVersion versionStr = map read' $ split "." versionStr parseVersion versionStr =
where read' x = case reads x of let versions = map read' $ split "." versionStr
[(n, _)] -> n parsed = all isJust versions in
_ -> error $ "cannot parse version: "++ versionStr if parsed
then Just $ map fromJust versions
else Nothing
where read' x = case reads x of
[(n, _)] -> n
_ -> Nothing
-- | Run an IHaskell application using the given profile. -- | Run an IHaskell application using the given profile.
runIHaskell :: WhichIPython runIHaskell :: WhichIPython
...@@ -334,33 +357,28 @@ ipythonInstalled = shelly $ do ...@@ -334,33 +357,28 @@ ipythonInstalled = shelly $ do
ipythonPath <- ipythonExePath DefaultIPython ipythonPath <- ipythonExePath DefaultIPython
test_f ipythonPath test_f ipythonPath
-- | Update the IPython source tree and rebuild.
updateIPython :: IO ()
updateIPython = do
updateScript <- Paths.getDataFileName "installation/update.sh"
venv <- fpToText <$> shelly ipythonDir
runTmp updateScript [venv, ipythonCommit]
-- Remove the old IPython profile. -- Remove the old IPython profile.
-- A new one will be regenerated when it is needed. -- A new one will be regenerated when it is needed.
-- shelly $ removeIPythonProfile DefaultIPython ipythonProfile -- shelly $ removeIPythonProfile DefaultIPython ipythonProfile
-- | Install IPython from source. -- | Install IPython from source.
installIPython :: IO () installIPython :: IO ()
installIPython = do installIPython = shelly $ do
-- Print a message and wait a little. -- Print a message and wait a little.
putStrLn "Installing IPython for IHaskell. This may take a while." liftIO $ do
threadDelay $ 3 * 1000 * 100 putStrLn "Installing IPython for IHaskell. This may take a while."
threadDelay $ 500 * 1000
-- Set up the virtualenv. -- Set up the virtualenv.
virtualenvScript <- Paths.getDataFileName "installation/virtualenv.sh" virtualenvScript <- liftIO $ Paths.getDataFileName "installation/virtualenv.sh"
venvDir <- fpToText <$> shelly ipythonDir venvDir <- fpToText <$> ipythonDir
runTmp virtualenvScript [venvDir] runTmp virtualenvScript [venvDir]
-- Set up Python depenencies. -- Set up Python depenencies.
installScript <- Paths.getDataFileName "installation/ipython.sh" setenv "ARCHFLAGS" "-Wno-error=unused-command-line-argument-hard-error-in-future"
runTmp installScript [venvDir, ipythonCommit] installScript <- liftIO $ Paths.getDataFileName "installation/ipython.sh"
runTmp installScript [venvDir]
runTmp script args = shelly $ withTmpDir $ \tmp -> do runTmp script args = withTmpDir $ \tmp -> do
cd tmp cd tmp
run_ "bash" $ pack script: args run_ "bash" $ pack script: args
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