Commit 75cff70f authored by Andrew Gibiansky's avatar Andrew Gibiansky

Added simple mechanism for updating profile versions automatically.

Closes #141.
parent 2762da3e
...@@ -16,7 +16,7 @@ INSTALLS="" ...@@ -16,7 +16,7 @@ INSTALLS=""
# Make the profile # Make the profile
cd profile cd profile
rm -f profile.tar rm -f profile.tar
tar -cvf profile.tar * tar -cvf profile.tar * .profile_version
cd .. cd ..
# Remove my profile # Remove my profile
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"celltoolbar": "Hiding", "celltoolbar": "Hiding",
"language": "haskell", "language": "haskell",
"name": "", "name": "",
"signature": "sha256:bfb92bc59c8c3f67da7b83650a8f51392e6267254808a7bba3df4f09cbad6081" "signature": "sha256:7262ddac633b02f026eb4bc29633234f9f8327226256b7f1660e72296f21935b"
}, },
"nbformat": 3, "nbformat": 3,
"nbformat_minor": 0, "nbformat_minor": 0,
...@@ -36,18 +36,7 @@ ...@@ -36,18 +36,7 @@
"cell_type": "code", "cell_type": "code",
"collapsed": false, "collapsed": false,
"input": [ "input": [
"infixl 3 <<>>\n", ":doc map"
"a <<>> 1 = a + 1\n",
"a <<>> 3 = a - 1\n",
"(<<>>) a b = a * 3\n",
"\n",
"f :: Int -> Int\n",
"f x = x + x\n",
"\n",
"f 3 <<>> f 3\n",
"\n",
"f :: Int -> Int\n",
"f x = x + x"
], ],
"language": "python", "language": "python",
"metadata": { "metadata": {
...@@ -56,13 +45,59 @@ ...@@ -56,13 +45,59 @@
"outputs": [ "outputs": [
{ {
"metadata": {}, "metadata": {},
"output_type": "display_data", "output_type": "display_data"
"text": [ },
"18" {
] "html": [
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:map'>map</a> &#x2237; (a &#x2192; b) &#x2192; [a] &#x2192; [b]</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>base</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Prelude</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>map f xs is the list obtained by applying f to each element of xs, i.e.,\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-code'>> map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]\n",
"> map f [x1, x2, ...] == [f x1, f x2, ...] \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/bytestring/latest/doc/html/Data-ByteString-Char8.html#v:map'>map</a> &#x2237; (Char &#x2192; Char) &#x2192; ByteString &#x2192; ByteString</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>bytestring</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.ByteString.Char8</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>O(n) map f xs is the ByteString obtained by applying f to each element of xs \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/text/latest/doc/html/Data-Text.html#v:map'>map</a> &#x2237; (Char &#x2192; Char) &#x2192; Text &#x2192; Text</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>text</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.Text</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>O(n) map f t is the Text obtained by applying f to each element of t. Subject to fusion. Performs replacement on invalid scalar values. \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/containers/latest/doc/html/Data-IntSet.html#v:map'>map</a> &#x2237; (Key &#x2192; Key) &#x2192; IntSet &#x2192; IntSet</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>containers</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.IntSet</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>O(n*min(n,W)). map f s is the set obtained by applying f to each element of s.\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>It's worth noting that the size of the result may be smaller if, for some (x,y), x /= y && f x == f y \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/bytestring/latest/doc/html/Data-ByteString-Lazy.html#v:map'>map</a> &#x2237; (Word8 &#x2192; Word8) &#x2192; ByteString &#x2192; ByteString</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>bytestring</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.ByteString.Lazy</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>O(n) map f xs is the ByteString obtained by applying f to each element of xs. \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/bytestring/latest/doc/html/Data-ByteString.html#v:map'>map</a> &#x2237; (Word8 &#x2192; Word8) &#x2192; ByteString &#x2192; ByteString</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>bytestring</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.ByteString</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>O(n) map f xs is the ByteString obtained by applying f to each element of xs. This function is subject to array fusion. \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/containers/latest/doc/html/Data-IntMap-Strict.html#v:map'>map</a> &#x2237; (a &#x2192; b) &#x2192; IntMap a &#x2192; IntMap b</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>containers</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.IntMap.Strict</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>O(n). Map a function over all values in the map.\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-code'>> map (++ \"x\") (fromList [(5,\"a\"), (3,\"b\")]) == fromList [(3, \"bx\"), (5, \"ax\")] \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/containers/latest/doc/html/Data-Map-Lazy.html#v:map'>map</a> &#x2237; (a &#x2192; b) &#x2192; Map k a &#x2192; Map k b</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>containers</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.Map.Lazy</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>O(n). Map a function over all values in the map.\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-code'>> map (++ \"x\") (fromList [(5,\"a\"), (3,\"b\")]) == fromList [(3, \"bx\"), (5, \"ax\")] \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/containers/latest/doc/html/Data-Set.html#v:map'>map</a> &#x2237; Ord b &#x21D2; (a &#x2192; b) &#x2192; Set a &#x2192; Set b</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>containers</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.Set</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>O(n*log n). map f s is the set obtained by applying f to each element of s.\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>It's worth noting that the size of the result may be smaller if, for some (x,y), x /= y && f x == f y \n",
"</div>\n",
"</div>\n"
],
"metadata": {},
"output_type": "display_data"
} }
], ],
"prompt_number": 2 "prompt_number": 4
}, },
{ {
"cell_type": "code", "cell_type": "code",
......
...@@ -45,6 +45,16 @@ data WhichIPython ...@@ -45,6 +45,16 @@ data WhichIPython
ipythonProfile :: String ipythonProfile :: String
ipythonProfile = "haskell" ipythonProfile = "haskell"
-- | The current IPython profile version.
-- This must be the same as the file in the profile.tar.
-- The filename used is @profileVersionFile@.
profileVersion :: String
profileVersion = "0.3.0.5"
-- | Filename in the profile where the version ins kept.
profileVersionFile :: FilePath
profileVersionFile = ".profile_version"
-- | Run IPython with any arguments. -- | Run IPython with any arguments.
ipython :: WhichIPython -- ^ Which IPython to use (user-provided or IHaskell-installed). ipython :: WhichIPython -- ^ Which IPython to use (user-provided or IHaskell-installed).
-> Bool -- ^ Whether to suppress output. -> Bool -- ^ Whether to suppress output.
...@@ -229,12 +239,13 @@ runIHaskell which profile app args = void $ do ...@@ -229,12 +239,13 @@ runIHaskell which profile app args = void $ do
errExit False $ ipython which True ["locate", "profile", pack profile] errExit False $ ipython which True ["locate", "profile", pack profile]
-- If the profile doesn't exist, create it. -- If the profile doesn't exist, create it.
-- We have an ugly hack that removes the profile whenever the IPython
-- version is updated. This means profiles get updated with IPython.
exitCode <- lastExitCode exitCode <- lastExitCode
when (exitCode /= 0) $ liftIO $ do if exitCode /= 0
then liftIO $ do
putStrLn "Creating IPython profile." putStrLn "Creating IPython profile."
setupIPythonProfile which profile setupIPythonProfile which profile
-- If the profile exists, update it if necessary.
else updateIPythonProfile which profile
-- Run the IHaskell command. -- Run the IHaskell command.
ipython which False $ map pack $ [app, "--profile", profile] ++ args ipython which False $ map pack $ [app, "--profile", profile] ++ args
...@@ -280,18 +291,29 @@ setupIPythonProfile which profile = shelly $ do ...@@ -280,18 +291,29 @@ setupIPythonProfile which profile = shelly $ do
liftIO $ copyProfile profileDir liftIO $ copyProfile profileDir
insertIHaskellPath profileDir insertIHaskellPath profileDir
removeIPythonProfile :: WhichIPython -> String -> Sh () -- | Update the IPython profile.
removeIPythonProfile which profile = do updateIPythonProfile :: WhichIPython
-- Try to locate the profile. Do not die if it doesn't exist. -> String -- ^ IHaskell profile name.
errExit False $ ipython which True ["locate", "profile", pack profile] -> Sh ()
updateIPythonProfile which profile = do
-- If the profile exists, delete it. -- Find out whether the profile exists.
dir <- pack <$> rstrip <$> errExit False (ipython which True ["locate", "profile", pack profile])
exitCode <- lastExitCode exitCode <- lastExitCode
dir <- pack <$> rstrip <$> ipython which True ["locate"] updated <- if exitCode == 0 && dir /= ""
when (exitCode == 0 && dir /= "") $ do then do
let versionFile = fpFromText dir </> profileVersionFile
fileExists <- test_f versionFile
if not fileExists
then return False
else liftIO $ do
contents <- StrictIO.readFile $ fpToString versionFile
return $ strip contents == profileVersion
else return False
when (not updated) $ do
putStrLn "Updating IPython profile." putStrLn "Updating IPython profile."
let profileDir = dir ++ "/profile_" ++ pack profile ++ "/" liftIO $ copyProfile dir
rm_rf $ fromText profileDir insertIHaskellPath $ dir ++ "/"
-- | Copy the profile files into the IPython profile. -- | Copy the profile files into the IPython profile.
copyProfile :: Text -> IO () copyProfile :: Text -> IO ()
......
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