Commit 268bf239 authored by Andrew Gibiansky's avatar Andrew Gibiansky

Cleaned up using external ipython.

parent a638a86d
......@@ -5,8 +5,10 @@ set -e
VIRTUALENV=$1
shift
# Activate the virtualenv.
source $VIRTUALENV/bin/activate
# Activate the virtualenv, if it exists.
if [[ -f $VIRTUALENV/bin/activate ]]; then
source $VIRTUALENV/bin/activate;
fi
# Run IPython.
# Quotes around $@ are necessary to deal properly with spaces.
......
......@@ -2,7 +2,7 @@
"metadata": {
"language": "haskell",
"name": "",
"signature": "sha256:536bbec84803f76deffe5c6fa15e83da024329a05073740fdd8affb98caf1834"
"signature": "sha256:a97e75023c94aa5ee7bcd22c902e508c1e4d91e89ccea56df5c4fec8f369f94a"
},
"nbformat": 3,
"nbformat_minor": 0,
......@@ -102,24 +102,99 @@
"outputs": [
{
"html": [
"<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",
" e.preventDefault();\n",
" var $this = $(this);\n",
" var $collapse = $this.closest('.collapse-group').find('.err-msg');\n",
" $collapse.collapse('toggle');\n",
"});\n",
"</script>"
"<!-- CodeMirror component -->\n",
"<link rel=\"stylesheet\" href=\"/static/components/codemirror/addon/lint/lint.css\">\n",
"<script src=\"/static/components/codemirror/addon/lint/lint.js\" charset=\"utf-8\"></script>\n",
"\n",
"<!-- Parsec widget -->\n",
"<script>\n",
"// Only load this script once.\n",
"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": {},
"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"
]
"output_type": "display_data"
}
],
"prompt_number": 2
"prompt_number": 9
},
{
"cell_type": "code",
......
......@@ -169,9 +169,9 @@ setupIPython DefaultIPython = do
where
checkIPythonVersion :: FilePath -> IO ()
checkIPythonVersion path = do
output <- unpack <$> shelly (run path ["--version"])
output <- unpack <$> shelly (silently $ run path ["--version"])
case parseVersion output of
Just (2:_) -> putStrLn "Detected IPython 2.0.0 or higher, using system-wide IPython."
Just (2:_) -> putStrLn "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."
......@@ -184,8 +184,6 @@ setupIPython DefaultIPython = do
installIPython
-- | Replace "~" with $HOME if $HOME is defined.
-- Otherwise, do nothing.
subHome :: String -> IO String
......@@ -213,9 +211,12 @@ parseVersion versionStr =
if parsed
then Just $ map fromJust versions
else Nothing
where read' x = case reads x of
[(n, _)] -> n
_ -> Nothing
where
read' :: String -> Maybe Int
read' x =
case reads x of
[(n, _)] -> Just n
_ -> Nothing
-- | Run an IHaskell application using the given profile.
runIHaskell :: WhichIPython
......@@ -357,10 +358,6 @@ ipythonInstalled = shelly $ do
ipythonPath <- ipythonExePath DefaultIPython
test_f ipythonPath
-- Remove the old IPython profile.
-- A new one will be regenerated when it is needed.
-- shelly $ removeIPythonProfile DefaultIPython ipythonProfile
-- | Install IPython from source.
installIPython :: IO ()
installIPython = shelly $ do
......
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