Closed nils-werner closed 3 years ago
Thanks for taking the time to research this, @nils-werner!
What do you think is a good approach for solving this? It seems like the catch-all else statement is probably working against us here.
Alternatively, the guessSysPrefix
function has been giving us a lot of trouble in the nteract desktop app so we might consider replacing this part of our code.
I don't have too deep an insight into the remainder of the code, or how other OSes besides Linux behave here, but my first guess is that
fs.realpathSync(exe)
is not really needed at all. To my understanding, this function does two things:
.
and ..
to return an absolute pathMy thought is: We probably need the first, but do we need the second? In some cases there are multiple interpreters with their version names present, where most of them are symlinks:
*python
*python3 -> python
*python3.6 -> python
In this case, resolving the symlink is not really necessary. These files are all in the same directory, and we're interested in the path.dirname()
of the executable anyways. Besides that I cannot think of another scenario in which symlink resolution is necessary.
So if we allow to get rid of that, we could replace
fs.realpathSync(exe)
with
path.resolve(exe)
which only does .
, ..
resolution, but no symlink following.
Thanks for posting the explainer. I'm fine with replacing path.resolve
over fs.realpathSync
. The use of realPath has been in the codebase for around four years and I'm not sure if there is strong reasoning for it. @rgbkrk might be able to chime in here.
Absent that, we can cut a PR with this change then validate it locally on the nteract desktop app and the Atom extension.
Would you be interested in submitting a PR with this change so we can start testing it?
No idea why the code was using realpath
instead of resolve
. I'll go check out your PR @nils-werner!
Closing this as it seems it is fixed.
I believe
guessSysPrefix()
causes an issue in Hydrogen in virtualenvs wherepython
is a symlink.If you create two virtualenvs, one with symlinked and one with copied executables:
and double-check the executables
And then run
in the two respective virtualenvs you will see two different results.
Two paths are different or missing in the linked virtualenv
which yields
and
While the lines are correct in the copied virtualenv
which yields
and
I believe this behaviour due to
fs.realpathSync()
in this lineIt "escapes" the virtualenv by following the symlink to
/usr/bin/python
and then searching for data and config dirs in/usr
and/
.