nteract / jupyter-paths

:city_sunrise: Pure JavaScript implementation of jupyter --paths --json
BSD 3-Clause "New" or "Revised" License
9 stars 11 forks source link

fix(dataDirs): fix crash when python is not in path #26

Closed Jaykul closed 7 years ago

Jaykul commented 7 years ago

Properly handle the case when guessSysPrefix can't find anything (i.e.: when python isn't installed)

rgbkrk commented 7 years ago

Welcome to the nteract party! 🎉

rgbkrk commented 7 years ago

Tests fail locally on my system, though I'm not sure if/what I should change.

$ npm t

> jupyter-paths@1.1.0 test /Users/kylek/code/src/github.com/nteract/jupyter-paths
> mocha

  dataDirs
    1) returns a promise that resolves to a list of directories that exist
    ✓ works even in the absence of python
    ✓ returns a promise that resolves to a list of directories that exist (104ms)
    2) returns immediately with a guess by default

  runtimeDir
    ✓ returns the directory where runtime data is stored

  configDirs
    3) returns a promise that resolves to a list of directories that exist
    ✓ returns a promise that resolves to a list of directories that exist
    4) returns immediately with a guess by default

  4 passing (129ms)
  4 failing

  1) dataDirs returns a promise that resolves to a list of directories that exist:

      AssertionError: expected [ Array(4) ] to deeply equal [ Array(4) ]
      + expected - actual

       [
         "/users/kylek/library/jupyter"
      -  "/usr/local/cellar/python/2.7.13/frameworks/python.framework/versions/2.7/share/jupyter"
      +  "/usr/local/cellar/python3/3.6.1/frameworks/python.framework/versions/3.6/share/jupyter"
         "/usr/local/share/jupyter"
         "/usr/share/jupyter"
       ]

      at Proxy.assertEqual (node_modules/chai/lib/chai/core/assertions.js:1012:19)
      at Proxy.methodWrapper (node_modules/chai/lib/chai/utils/addMethod.js:57:25)
      at jp.dataDirs.then (test/jupyter_paths_spec.js:28:37)
      at <anonymous>

  2) dataDirs returns immediately with a guess by default:

      AssertionError: expected [ Array(4) ] to deeply equal [ Array(4) ]
      + expected - actual

       [
         "/users/kylek/library/jupyter"
      -  "/usr/local/cellar/python/2.7.13/frameworks/python.framework/versions/2.7/share/jupyter"
      +  "/usr/local/cellar/python3/3.6.1/frameworks/python.framework/versions/3.6/share/jupyter"
         "/usr/local/share/jupyter"
         "/usr/share/jupyter"
       ]

      at Proxy.assertEqual (node_modules/chai/lib/chai/core/assertions.js:1012:19)
      at Proxy.methodWrapper (node_modules/chai/lib/chai/utils/addMethod.js:57:25)
      at Context.it (test/jupyter_paths_spec.js:67:26)

  3) configDirs returns a promise that resolves to a list of directories that exist:

      AssertionError: expected [ Array(4) ] to deeply equal [ Array(4) ]
      + expected - actual

       [
         "/users/kylek/.jupyter"
      -  "/usr/local/cellar/python/2.7.13/frameworks/python.framework/versions/2.7/etc/jupyter"
      +  "/usr/local/cellar/python3/3.6.1/frameworks/python.framework/versions/3.6/etc/jupyter"
         "/usr/local/etc/jupyter"
         "/etc/jupyter"
       ]

      at Proxy.assertEqual (node_modules/chai/lib/chai/core/assertions.js:1012:19)
      at Proxy.methodWrapper (node_modules/chai/lib/chai/utils/addMethod.js:57:25)
      at jp.configDirs.then (test/jupyter_paths_spec.js:86:37)
      at <anonymous>

  4) configDirs returns immediately with a guess by default:

      AssertionError: expected [ Array(4) ] to deeply equal [ Array(4) ]
      + expected - actual

       [
         "/users/kylek/.jupyter"
      -  "/usr/local/cellar/python/2.7.13/frameworks/python.framework/versions/2.7/etc/jupyter"
      +  "/usr/local/cellar/python3/3.6.1/frameworks/python.framework/versions/3.6/etc/jupyter"
         "/usr/local/etc/jupyter"
         "/etc/jupyter"
       ]

      at Proxy.assertEqual (node_modules/chai/lib/chai/core/assertions.js:1012:19)
      at Proxy.methodWrapper (node_modules/chai/lib/chai/utils/addMethod.js:57:25)
      at Context.it (test/jupyter_paths_spec.js:107:26)
rgbkrk commented 7 years ago

"My" jupyter is the python3 one whereas the expected is the Python2 jupyter. I think we'll ship with this as a major bump and assume that's just a me thing.

rgbkrk commented 7 years ago
$ npm version major && npm publish && git push && git push --tags
v2.0.0
+ jupyter-paths@2.0.0
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 2.87 KiB | 0 bytes/s, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:nteract/jupyter-paths.git
   d6e574c..e8d440b  master -> master
Counting objects: 1, done.
Writing objects: 100% (1/1), 155 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To github.com:nteract/jupyter-paths.git
 * [new tag]         v2.0.0 -> v2.0.0
rgbkrk commented 7 years ago

@lgeiger ^^

Shipped a new jupyter-paths as a major release.

lgeiger commented 7 years ago

@rgbkrk I'll test it on my system tomorrow.

Jaykul commented 7 years ago

@rgbkrk So the difference between guessSysPrefix and what jupyter --paths actually returns is obviously because the first python in your path is not the same version where you actually have jupyter installed (or at least, not the same python as the first place in your path where jupyter exists?).

In any case --in my lack of experience with this-- I would guess the fix would be to search for jupyter instead of python 😉