Skip to content

Commit 3c125e8

Browse files
committed
Fix #63
1 parent 38a3e52 commit 3c125e8

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

tests/app/Spec/Tests/R.hs

+6-9
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@ kernelSpec = NixKernelSpec {
2323
}
2424

2525
tests :: LanguageSpec
26-
tests = describe "R" $ introduceNixEnvironment [kernelSpec] [] "R" $ introduceJupyterRunner $
27-
-- TODO: remove the need for introduceNothingBubblewrap
28-
-- https://github.com/codedownio/codedown-languages/issues/63
29-
introduceNothingBubblewrap $ do
30-
testKernelSearchersNonempty "R"
31-
testHasExpectedFields "R"
32-
33-
testKernelStdout "R" [__i|cat("hi")|] "hi"
34-
testKernelStdout "R" [__i|print("hi")|] [i|[1] "hi"\n|]
26+
tests = describe "R" $ introduceNixEnvironment [kernelSpec] [] "R" $ introduceJupyterRunner $ do
27+
testKernelSearchersNonempty "R"
28+
testHasExpectedFields "R"
29+
30+
testKernelStdout "R" [__i|cat("hi")|] "hi"
31+
testKernelStdout "R" [__i|print("hi")|] [i|[1] "hi"\n|]
3532

3633

3734
main :: IO ()

tests/src/TestLib/JupyterRunnerContext.hs

+18-17
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Control.Monad.Logger
1111
import Control.Monad.Reader
1212
import Control.Monad.Trans.Control (MonadBaseControl)
1313
import qualified Data.Aeson as A
14-
import Data.ByteString.Lazy.Char8 as BL
14+
import Data.ByteString.Lazy.Char8 as BL8
1515
import qualified Data.List as L
1616
import Data.Map (Map)
1717
import qualified Data.Map as M
@@ -28,8 +28,6 @@ import TestLib.Util
2828
import UnliftIO.Directory
2929
import UnliftIO.Process
3030

31-
-- import qualified Data.ByteString.Lazy.Char8 as BL8
32-
3331

3432
introduceJupyterRunner :: (
3533
HasBaseContext context, MonadIO m, MonadMask m, MonadUnliftIO m, MonadBaseControl IO m
@@ -221,7 +219,7 @@ runKernelCode kernel code cb = do
221219
Just _ -> (innerRunDir </>)
222220
Nothing -> (outerRunDir </>)
223221

224-
liftIO $ BL.writeFile (relativeToOuterRunDir notebook) (A.encode (notebookWithCode kernel code))
222+
liftIO $ BL8.writeFile (relativeToOuterRunDir notebook) (A.encode (notebookWithCode kernel code))
225223

226224
let papermillArgs = [
227225
"notebook.ipynb", "out.ipynb"
@@ -235,25 +233,27 @@ runKernelCode kernel code cb = do
235233

236234
cp <- case maybeBwrap of
237235
Just bwrap -> do
236+
-- Provide some core utils on the PATH. For example, the R kernel needs this:
238237
-- https://github.com/codedownio/codedown-languages/issues/63
239-
-- binPathsJson <- readCreateProcessWithLogging (
240-
-- proc "nix" ["build"
241-
-- , "--impure"
242-
-- , "--expr", [i|with import <nixpkgs> {}; symlinkJoin { name = "base-paths"; paths = [which coreutils]; }|]
243-
-- , "--json"
244-
-- ]) ""
245-
-- binPaths <- case parseNixBuildJson <$> (A.eitherDecode (BL8.pack binPathsJson)) of
246-
-- Left err -> expectationFailure [i|Failed to parse bin paths: #{err}. JSON: #{binPathsJson}|]
247-
-- Right Nothing -> expectationFailure [i|Didn't find Nix output in: #{binPathsJson}|]
248-
-- Right (Just output) -> pure $ T.unpack output
249-
-- info [i|PATH: #{binPaths </> "bin"}|]
238+
binDirJson <- readCreateProcessWithLogging (
239+
proc "nix" ["build"
240+
, "--impure"
241+
, "--expr", [i|with import <nixpkgs> {}; pkgsStatic.busybox|]
242+
, "--json"
243+
, "--no-link"
244+
]) ""
245+
binDir <- case parseNixBuildJson <$> (A.eitherDecode (BL8.pack binDirJson)) of
246+
Left err -> expectationFailure [i|Failed to parse bin paths: #{err}. JSON: #{binDirJson}|]
247+
Right Nothing -> expectationFailure [i|Didn't find Nix output in: #{binDirJson}|]
248+
Right (Just output) -> pure ((T.unpack output) </> "bin")
249+
info [i|PATH: #{binDir </> "bin"}|]
250250

251251
-- Get the full closure of the Nix environment and jupyter runner
252252
fullClosure <- (Prelude.filter (/= "") . T.splitOn "\n" . T.pack) <$> readCreateProcessWithLogging (
253253
proc "nix" (["path-info", "-r"
254254
, jr
255255
, nixEnv
256-
-- , binPaths
256+
, binDir
257257
])
258258
) ""
259259

@@ -265,7 +265,8 @@ runKernelCode kernel code cb = do
265265
, "--setenv", "JUPYTER_PATH", jupyterPath
266266
, "--chdir", innerRunDir
267267

268-
-- , "--setenv", "PATH", binPaths </> "bin"
268+
, "--ro-bind", binDir, "/bin"
269+
, "--setenv", "PATH", "/bin"
269270

270271
, "--proc", "/proc"
271272
, "--dev", "/dev"

0 commit comments

Comments
 (0)