Commit 666484d7 authored by Andrew Gibiansky's avatar Andrew Gibiansky

adding support for running from a sandbox

parent c7708acc
...@@ -116,9 +116,19 @@ interpret allowedStdin action = runGhc (Just libdir) $ do ...@@ -116,9 +116,19 @@ interpret allowedStdin action = runGhc (Just libdir) $ do
-- Set the dynamic session flags -- Set the dynamic session flags
originalFlags <- getSessionDynFlags originalFlags <- getSessionDynFlags
let dflags = xopt_set originalFlags Opt_ExtendedDefaultRules let dflags = xopt_set originalFlags Opt_ExtendedDefaultRules
-- If we're in a sandbox, add the relevant package database
sandboxPackages <- liftIO getSandboxPackageConf
let pkgConfs = case sandboxPackages of
Nothing -> extraPkgConfs dflags
Just path ->
let pkg = PkgConfFile path in
(pkg:) . extraPkgConfs dflags
void $ setSessionDynFlags $ dflags { hscTarget = HscInterpreted, void $ setSessionDynFlags $ dflags { hscTarget = HscInterpreted,
ghcLink = LinkInMemory, ghcLink = LinkInMemory,
pprCols = 300 } pprCols = 300,
extraPkgConfs = pkgConfs }
initializeImports initializeImports
......
...@@ -12,6 +12,7 @@ module IHaskell.IPython ( ...@@ -12,6 +12,7 @@ module IHaskell.IPython (
readInitInfo, readInitInfo,
defaultConfFile, defaultConfFile,
getIHaskellDir, getIHaskellDir,
getSandboxPackageConf,
nbconvert, nbconvert,
ViewFormat(..), ViewFormat(..),
) where ) where
...@@ -23,7 +24,7 @@ import System.Argv0 ...@@ -23,7 +24,7 @@ import System.Argv0
import System.Directory import System.Directory
import qualified Filesystem.Path.CurrentOS as FS import qualified Filesystem.Path.CurrentOS as FS
import Data.List.Utils (split) import Data.List.Utils (split)
import Data.String.Utils (rstrip) import Data.String.Utils (rstrip, endswith)
import Text.Printf import Text.Printf
import qualified System.IO.Strict as StrictIO import qualified System.IO.Strict as StrictIO
...@@ -391,3 +392,19 @@ getIHaskellPath = do ...@@ -391,3 +392,19 @@ getIHaskellPath = do
-- If it's actually a relative path, make it absolute. -- If it's actually a relative path, make it absolute.
cd <- liftIO getCurrentDirectory cd <- liftIO getCurrentDirectory
return $ FS.encodeString $ FS.decodeString cd FS.</> f return $ FS.encodeString $ FS.decodeString cd FS.</> f
getSandboxPackageConf :: IO (Maybe String)
getSandboxPackageConf = shellyNoDir $ do
myPath <- getIHaskellPath
let sandboxName = ".cabal-sandbox"
if not $ sandboxName`isInfixOf` myPath
then return Nothing
else do
let pieces = split "/" myPath
sandboxDir = intercalate "/" $ (takeWhile (/= sandboxName) pieces) ++ [sandboxName]
subdirs <- ls $ fpFromString sandboxDir
let confdirs = filter (endswith "packages.conf.d") $ map fpToString subdirs
case confdirs of
[] -> return Nothing
dir:_ ->
return $ Just dir
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