Skip to content

Commit

Permalink
Merge pull request #248 from bnavigator/subcommand-argv0
Browse files Browse the repository at this point in the history
set proper sys.argv[0] for subcommand
  • Loading branch information
jasongrout committed Nov 4, 2021
2 parents 1778a44 + e84f3b1 commit 2ccb576
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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:])
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

0 comments on commit 2ccb576

Please sign in to comment.