Skip to content
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

set proper sys.argv[0] for subcommand #248

Merged
merged 3 commits into from Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion jupyter_core/command.py
Expand Up @@ -303,7 +303,7 @@ def main():
sys.exit(e)

try:
_execvp(command, sys.argv[1:])
_execvp(command, [command] + sys.argv[2:])
jasongrout marked this conversation as resolved.
Show resolved Hide resolved
except OSError as e:
sys.exit("Error executing Jupyter command %r: %s" % (subcommand, e))

Expand Down
24 changes: 24 additions & 0 deletions jupyter_core/tests/test_command.py
Expand Up @@ -201,3 +201,27 @@ def test_path_priority(tmpdir):
env[str('PATHEXT')] = '.EXE'
out = check_output([sys.executable, str(jupyter), 'witness'], env=env)
assert b'WITNESS A' in out

def test_argv0(tmpdir):
a = tmpdir.mkdir("a")
jupyter = a.join('jupyter')
jupyter.write(
'from jupyter_core import command; command.main()'
)
jupyter.chmod(0o700)
witness_a = a.join('jupyter-witness')
witness_a_src = f'''#!{sys.executable}
import sys
print(sys.argv[0])
'''
write_executable(witness_a, witness_a_src)

env = {}
if 'SYSTEMROOT' in os.environ: # Windows http://bugs.python.org/issue20614
env[str('SYSTEMROOT')] = os.environ['SYSTEMROOT']
if sys.platform == 'win32':
env[str('PATHEXT')] = '.EXE'
out = check_output([sys.executable, str(jupyter), 'witness'], env=env)

# Make sure the first argv is the full path to the executing script
assert f'{jupyter}-witness'.encode() in out