-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removed mechanism that change $PATH #148
Conversation
the error on CI for python 3.3 says: any thoughts? It seems it is done for review. |
@xmnlab Your PR looks good. It looks like master is failing CI: https://travis-ci.org/jupyter/jupyter_core/builds/443142041 @minrk Any ideas? |
We need to make sure that this doesn't change the resolution of executables, which it looks like it does, currently. I think this change currently requires all jupyter-foo to be in the same directory as The behavior should be the same as if One option, I believe, should be to use with mock.patch($PATH with self):
abs_exe = shutil.which(jupyter-foo)
if abs_exe:
exec(abs_exe) |
thanks @minrk for the feedback. I hope to have captured your thoughts. let me know if I understood that correctly. |
regarding to |
it is done for a new review. |
jupyter_core/command.py
Outdated
# set new PATH with self | ||
os.environ['PATH'] = os.pathsep.join(_path_with_self()) | ||
# get the real path for the jupyter-<subcommand> | ||
real_path = find_executable('{}-{}'.format(path, subcommand)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shutil.which is not available for py2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But good news, this repo already has a backport - from .utils.shutil_which import which
. This is a bit more complex than find_executable
, e.g. it handles PATHEXT on Windows, so it would be good to use that (and the real shutil.which
on Python 3, of course).
any feedback? |
hey everyone, any feedback about this PR? |
hey everyone! any thoughts here? |
@takluyver Would you care to review? |
Yup, I'll review. While we're looking at this repository, can I encourage people to consider PR #143? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, the idea looks fine, but I've left a few notes about the implementation.
jupyter_core/command.py
Outdated
# set new PATH with self | ||
os.environ['PATH'] = os.pathsep.join(_path_with_self()) | ||
# get the real path for the jupyter-<subcommand> | ||
real_path = find_executable('{}-{}'.format(path, subcommand)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But good news, this repo already has a backport - from .utils.shutil_which import which
. This is a bit more complex than find_executable
, e.g. it handles PATHEXT on Windows, so it would be good to use that (and the real shutil.which
on Python 3, of course).
jupyter_core/command.py
Outdated
@@ -113,9 +115,24 @@ def _execvp(cmd, argv): | |||
os.execvp(cmd, argv) | |||
|
|||
|
|||
def _jupyter_realpath(path, subcommand): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have a brief docstring to explain what it is.
thanks for the feedback @takluyver i will work on that! |
00a623c
to
7fe4c25
Compare
@takluyver @minrk @gnestor it is done for a new review :) |
jupyter_core/command.py
Outdated
|
||
command = 'jupyter-' + subcommand | ||
|
||
command = _jupyter_abspath(sys.argv[0], subcommand) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we always want to be looking up jupyter-xyz
, regardless of what sys.argv[0]
is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@takluyver I changed that considering the follow case reported by @mlucool
Setup:
- Set your PATH to have python 2 as your default version of python (prepend the path)
- Run jupyterlab from a python 3 location (e.g. `path/to/python-3/bin/jupyterlab')
- In a python 2 kernel run the following:
import sys print(sys.version) import os print(os.environ['PATH'])
As expected, sys.version will be python 2. But now you can see that the PATH is modified with python3 in preprended. So if I were to do:
import subprocess print(subprocess.Popen("python -c 'import sys; print(sys.version)'", shell=True, stdout=subprocess.PIPE).stdout.read())
This would show python 3.
This is really just a problem as we are migrating from python 2 to 3 and we want to run the server with 3 (as we want to use latest) but anything that is called via subprocess should use whatever you had in your PATH. We are planning to locally path
ipykernel_launcher.py
in a hacky way. This is suboptiomal so we'd like to revert this as soon as we can.
maybe it will not be a problem considering that there is no jupyterlab for py2 .. but if path/to/python-3/bin/jupyterlab
is not in $PATH
even if I run jupyerlab
using the full path it will not be found.
do you have any thoughts here, considering this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with not modifying $PATH
.
The sys.argv[0]
that you pass in here is only used, as far as I can see, in this line:
jupyter_subcommand = '{}-{}'.format(path, subcommand)
If sys.argv[0]
is, e.g. /home/takluyver/.local/bin/jupyter
, then you construct a subcommand like /home/takluyver/.local/bin/jupyter-notebook
. That short-circuits shutil.which()
, so it will only work if that's the location of jupyter-notebook
.
If the subcommand is notebook
, then we should always be looking up jupyter-notebook
, not {sys.argv[0]}-notebook
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see .. OK .. so maybe related to the scenario presented by @mlucool the workaround should be call /path/jupyterlab-subcommand
directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@takluyver it is done for a new review! thanks!
7fe4c25
to
b229405
Compare
jupyter_core/command.py
Outdated
# get env PATH with self | ||
search_path = os.pathsep.join(_path_with_self()) | ||
# get the abs path for the jupyter-<subcommand> | ||
jupyter_subcommand = '{}-{}'.format(path, subcommand) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Now you don't need to pass an argument, you can just hardcode it in this line. That's one less thing to follow around when reading the code. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok :) done!
jupyter_core/command.py
Outdated
@@ -113,9 +119,29 @@ def _execvp(cmd, argv): | |||
os.execvp(cmd, argv) | |||
|
|||
|
|||
def _jupyter_abspath(subcommand): | |||
"""This method get the abspath of jupyter with no changes on ENV.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: "...the abspath of a specified jupyter-subcommand..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok! done! thanks for the feedback!
resolves #145