Commit 719a46e5 authored by Julien Puydt's avatar Julien Puydt

Import jupyter-core_4.2.0.orig.tar.gz

parent 4a7eaee7
......@@ -15,3 +15,4 @@ __pycache__
Changes in jupyter-core
GitHub <>`__
- Make :command:`jupyter` directory top priority in search path for subcommands,
so that :command:`jupyter-subcommand` next to :command:`jupyter` will always be picked if present.
- Avoid using ``shell=True`` for subcommand dispatch on Windows.
......@@ -93,7 +93,16 @@ def _execvp(cmd, argv):
Python provides execvp on Windows, but its behavior is problematic (Python bug#9148).
if sys.platform.startswith('win'):
p = Popen([cmd] + argv[1:], shell=True)
# PATH is ignored when shell=False,
# so rely on shutil.which
from shutil import which
except ImportError:
from .utils.shutil_which import which
cmd = which(cmd)
if cmd is None:
raise OSError('%r not found' % cmd, errno.ENOENT)
p = Popen([cmd] + argv[1:])
# Don't raise KeyboardInterrupt in the parent process.
# Set this after spawning, to avoid subprocess inheriting handler.
import signal
......@@ -105,20 +114,26 @@ def _execvp(cmd, argv):
def _path_with_self():
"""Ensure `jupyter`'s dir is on PATH"""
"""Put `jupyter`'s dir at the front of PATH
Ensures that /path/to/jupyter subcommand
will do /path/to/jupyter-subcommand
even if /other/jupyter-subcommand is ahead of it on PATH
scripts = [sys.argv[0]]
if os.path.islink(scripts[0]):
# include realpath, if `jupyter` is a symlink
path_list = (os.environ.get('PATH') or os.defpath).split(os.pathsep)
for script in scripts:
bindir = os.path.dirname(script)
if (os.path.isdir(bindir)
and bindir not in path_list
and os.access(script, os.X_OK) # only if it's a script
# ensure executable's dir is on PATH
# avoids missing subcommands when jupyter is run via absolute path
path_list.insert(0, bindir)
os.environ['PATH'] = os.pathsep.join(path_list)
return path_list
......@@ -115,3 +115,26 @@ def test_not_on_path(tmpdir):
out = check_output([sys.executable, str(jupyter), 'witness'], env={'PATH': ''})
assert b'WITNESS' in out
def test_path_priority(tmpdir):
a = tmpdir.mkdir("a")
jupyter = a.join('jupyter')
'from jupyter_core import command; command.main()'
witness_cmd = 'jupyter-witness'
if sys.platform == 'win32':
witness_cmd += '.py'
witness_a = a.join(witness_cmd)
witness_a.write('#!%s\n%s\n' % (sys.executable, 'print("WITNESS A")'))
b = tmpdir.mkdir("b")
witness_b = b.join(witness_cmd)
witness_b.write('#!%s\n%s\n' % (sys.executable, 'print("WITNESS B")'))
out = check_output([sys.executable, str(jupyter), 'witness'], env={'PATH': str(b)})
assert b'WITNESS A' in out
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
version_info = (4, 1, 1)
version_info = (4, 2, 0)
__version__ = '.'.join(map(str, version_info))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment