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

Pure JS implementation #6

Closed rgbkrk closed 8 years ago

rgbkrk commented 8 years ago

Closing down on #5 and #4.

Will be a work in progress as I first bring in the original implementation that was a direct Python -> JS port, followed by a cleaner API like in ipython-paths.

rgbkrk commented 8 years ago

screenshot 2016-01-20 19 22 42

FML

Note: This is due to my system python and Jupyter's python being different.

rgbkrk commented 8 years ago

We're going to have a problem here. sys.prefix as reported by shelling out to python is based on your current python version. For jupyter, it's based on which python installed jupyter_core.

rgbkrk commented 8 years ago

Cool, tested and partially specced against jupyter console.

n-riesco commented 8 years ago

On 21/01/16 01:14, Kyle Kelley wrote:

We're going to have a problem here. |sys.prefix| as reported by shelling out to |python| is based on your current |python| version. For |jupyter|, it's based on which python installed |jupyter_core|.

What I had in mind is that, in the absence of jupyter_core and python, sys-prefix-promise would return a safe default, so that it would be possible to install a kernel on a location, that later on, Hydrogen could find (even if jupyter_core and python are not present).

rgbkrk commented 8 years ago

We can always install to the non sys prefixed directories and have it picked up. The way this module works right now is that you have to explicitly ask to include the sys prefixed path.

n-riesco commented 8 years ago

That sounds good to me.

rgbkrk commented 8 years ago

Finally came back to this. In v1.0.0, you get a promise back when setting withSysPrefix to true in opts.

> jp.dataDirs({ withSysPrefix: true })
Promise { <pending> }
> jp.dataDirs({ withSysPrefix: true }).then(console.log)
Promise { <pending> }
> [ '/Users/rgbkrk/Library/Jupyter',
  '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/share/jupyter',
  '/usr/share/jupyter',
  '/usr/local/share/jupyter' ]

If someone doesn't want to rely on sys prefix, they get an immediate return:

> jp.dataDirs()
[ '/Users/rgbkrk/Library/Jupyter',
  '/usr/share/jupyter',
  '/usr/local/share/jupyter' ]
n-riesco commented 8 years ago

If what you want is to call python only once, how about use execSync() and store the result in a private variable?

rgbkrk commented 8 years ago

We can do that, assuming that sys.prefix doesn't change over the lifetime of a run. In the case of composition, since a user can change their default installed Python this value can change (e.g. make python3 the default python when python2 was python before). We would not be able to detect a change based on environment variables once loaded though.

I was actually thinking about making another opt for which python is used to run sys.prefix, since, as the image above shows they can be wildly different.

rgbkrk commented 8 years ago

Here's sys-prefix-promise by the way.

n-riesco commented 8 years ago

On 22/01/16 17:56, Kyle Kelley wrote:

We can do that, assuming that |sys.prefix| doesn't change over the lifetime of a run.

In this case, I would call execSync() each time, and let the user cache the value only when they think it necessary.

rgbkrk commented 8 years ago

I'd prefer that the user cache it in those cases. Also happy to expose a Sync() method if that works better for IJavascript's codebase. I tend to prefer relying on Promises for single valued things that can block.