Skip to content

Commit

Permalink
Available kernels func
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaGanzin committed Dec 14, 2015
1 parent d48da81 commit 8431e22
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/paths.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ ipythonDataDir = ->

jupyterResolve = _.memoize (category) ->
match = child_process.spawnSync('jupyter', ['--paths']).stdout.toString()
_.filter (_.map (
///#{category}:\n(\s+.*\n)+///gim.exec(match)[0].split('\n')
), (e) -> e.replace(///#{category}:///,'').trim()), _.negate(_.isEmpty)
_.map ///#{category}:\n(\s+.*\n)+///gim.exec(match)[0].split('\n')[1...-1], (x) -> x.trim()


jupyterPath = _.memoize (subdirs...) ->
Expand All @@ -22,6 +20,12 @@ jupyterPath = _.memoize (subdirs...) ->
paths = (path.join(p, subdirs...) for p in paths)
_.filter paths, (x) -> try fs.statSync(x).isDirectory() catch e

kernels = _.memoize ->
stdout = child_process.spawnSync('ipython',['kernelspec','list']).stdout.toString()
_.map /Available kernels:(\s+.+\s+.+\n)+/.exec(stdout)[0].split('\n')[1...-1], (x) ->
/\/.*/.exec(x)[0]

module.exports =
jupyterResolve: jupyterResolve
jupyterPath: jupyterPath
availableKernels: kernels

0 comments on commit 8431e22

Please sign in to comment.