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

Conversation

bnavigator
Copy link
Contributor

Hi,

In openSUSE/libalternatives#11 we noticed that jupyter subcommand calls jupyter-subcommand with an argv[0]=subcommand instead of the proper executable name jupyter-subcommand.

Most subcommands do not care, because the first thing they do, is strip sys.argv[0] from the parsing:

if argv is None:
argv = sys.argv[1:]
if argv:
subc = self._find_subcommand(argv[0])

From the Python Doc: os.execv*():

In either case, the arguments to the child process should start with the name of the command being run, but this is not enforced.

So nothing mandates argv[0] to be set to the name, but it is good practise and libalternatives relies on it.

You already do the same for subcommands of JupyterApps:

def start(self):
"""Start the whole thing"""
if self.subcommand:
os.execv(self.subcommand, [self.subcommand] + self.argv[1:])

@jasongrout
Copy link
Member

Thanks! Can we also add a test in https://github.com/jupyter/jupyter_core/blob/master/jupyter_core/tests/test_command.py to make sure we don't break this in the future?

@jasongrout
Copy link
Member

@bnavigator - does the test I added look good to you?

@bnavigator
Copy link
Contributor Author

LGTM

@jasongrout jasongrout merged commit 2ccb576 into jupyter:master Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants