mirror of
https://github.com/IHaskell/IHaskell.git
synced 2025-04-16 03:16:20 +00:00
Added simple mechanism for updating profile versions automatically.
Closes #141.
This commit is contained in:
parent
2762da3e3e
commit
75cff70fe5
2
build.sh
2
build.sh
@ -16,7 +16,7 @@ INSTALLS=""
|
||||
# Make the profile
|
||||
cd profile
|
||||
rm -f profile.tar
|
||||
tar -cvf profile.tar *
|
||||
tar -cvf profile.tar * .profile_version
|
||||
cd ..
|
||||
|
||||
# Remove my profile
|
||||
|
@ -3,7 +3,7 @@
|
||||
"celltoolbar": "Hiding",
|
||||
"language": "haskell",
|
||||
"name": "",
|
||||
"signature": "sha256:bfb92bc59c8c3f67da7b83650a8f51392e6267254808a7bba3df4f09cbad6081"
|
||||
"signature": "sha256:7262ddac633b02f026eb4bc29633234f9f8327226256b7f1660e72296f21935b"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
@ -36,18 +36,7 @@
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"infixl 3 <<>>\n",
|
||||
"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"
|
||||
":doc map"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {
|
||||
@ -56,13 +45,59 @@
|
||||
"outputs": [
|
||||
{
|
||||
"metadata": {},
|
||||
"output_type": "display_data",
|
||||
"text": [
|
||||
"18"
|
||||
]
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"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> ∷ (a → b) → [a] → [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> ∷ (Char → Char) → ByteString → 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> ∷ (Char → Char) → Text → 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> ∷ (Key → Key) → IntSet → 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> ∷ (Word8 → Word8) → ByteString → 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> ∷ (Word8 → Word8) → ByteString → 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> ∷ (a → b) → IntMap a → 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> ∷ (a → b) → Map k a → 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> ∷ Ord b ⇒ (a → b) → Set a → 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",
|
||||
|
1
profile/.profile_version
Normal file
1
profile/.profile_version
Normal file
@ -0,0 +1 @@
|
||||
0.3.0.5
|
@ -45,6 +45,16 @@ data WhichIPython
|
||||
ipythonProfile :: String
|
||||
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.
|
||||
ipython :: WhichIPython -- ^ Which IPython to use (user-provided or IHaskell-installed).
|
||||
-> Bool -- ^ Whether to suppress output.
|
||||
@ -229,12 +239,13 @@ runIHaskell which profile app args = void $ do
|
||||
errExit False $ ipython which True ["locate", "profile", pack profile]
|
||||
|
||||
-- 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
|
||||
when (exitCode /= 0) $ liftIO $ do
|
||||
if exitCode /= 0
|
||||
then liftIO $ do
|
||||
putStrLn "Creating IPython profile."
|
||||
setupIPythonProfile which profile
|
||||
-- If the profile exists, update it if necessary.
|
||||
else updateIPythonProfile which profile
|
||||
|
||||
-- Run the IHaskell command.
|
||||
ipython which False $ map pack $ [app, "--profile", profile] ++ args
|
||||
@ -280,18 +291,29 @@ setupIPythonProfile which profile = shelly $ do
|
||||
liftIO $ copyProfile profileDir
|
||||
insertIHaskellPath profileDir
|
||||
|
||||
removeIPythonProfile :: WhichIPython -> String -> Sh ()
|
||||
removeIPythonProfile which profile = do
|
||||
-- Try to locate the profile. Do not die if it doesn't exist.
|
||||
errExit False $ ipython which True ["locate", "profile", pack profile]
|
||||
|
||||
-- If the profile exists, delete it.
|
||||
-- | Update the IPython profile.
|
||||
updateIPythonProfile :: WhichIPython
|
||||
-> String -- ^ IHaskell profile name.
|
||||
-> Sh ()
|
||||
updateIPythonProfile which profile = do
|
||||
-- Find out whether the profile exists.
|
||||
dir <- pack <$> rstrip <$> errExit False (ipython which True ["locate", "profile", pack profile])
|
||||
exitCode <- lastExitCode
|
||||
dir <- pack <$> rstrip <$> ipython which True ["locate"]
|
||||
when (exitCode == 0 && dir /= "") $ do
|
||||
updated <- if exitCode == 0 && dir /= ""
|
||||
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."
|
||||
let profileDir = dir ++ "/profile_" ++ pack profile ++ "/"
|
||||
rm_rf $ fromText profileDir
|
||||
liftIO $ copyProfile dir
|
||||
insertIHaskellPath $ dir ++ "/"
|
||||
|
||||
-- | Copy the profile files into the IPython profile.
|
||||
copyProfile :: Text -> IO ()
|
||||
|
Loading…
x
Reference in New Issue
Block a user