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

Allow use ~/ in the kernel's command or it's arguments #589

Merged
merged 1 commit into from
Nov 16, 2020

Conversation

svetlyak40wt
Copy link
Contributor

After this patch you'll be able to do this
in a kernel spec:

{
    "argv": ["~/the-project/jupyter/kernel/run", "-f", "{connection_file}"],
    "display_name": "The Project (dev)",
    "language": "python"
}

This can be useful when you are installing kernel with --user option
into /home/my-name/.local/share/jupyter/kernels/ and having your jupyter
notebooks in different subdirectories of ~/the-project/ folder.

In this case kernel for each notebook is started in the notebook's
subdirectory and without ~/ in the spec Jupyter is unable to find a
file for running a custom kernel.

After this patch you'll be able to do this
in a kernel spec:

    {
        "argv": ["~/the-project/jupyter/kernel/run", "-f", "{connection_file}"],
        "display_name": "The Project (dev)",
        "language": "python"
    }

This can be useful when you are installing kernel with --user option
into /home/my-name/.local/share/jupyter/kernels/ and having your jupyter
notebooks in different subdirectories of ~/the-project/ folder.

In this case kernel for each notebook is started in the notebook's
subdirectory and without ~/ in the spec Jupyter is unable to find a
file for running custom kernel.
@davidbrochart
Copy link
Member

Thanks for the PR!
Does it mean every part of the command is treated as a potential path? Isn't there a chance we change something that was not a path?

@svetlyak40wt
Copy link
Contributor Author

os.path.expanduser expands ~ only at the beginning of the string:

In [1]: import os.path

In [2]: os.path.expanduser('~/bin')
Out[2]: '/Users/art/bin'

In [3]: os.path.expanduser('Some~/bin')
Out[3]: 'Some~/bin'

In [4]: os.path.expanduser('Some~/bin~')
Out[4]: 'Some~/bin~'

There is only a very small probability that somebody will create a command-line program which wants arguments like ~some not being path names.

@davidbrochart davidbrochart merged commit 90e13de into jupyter:master Nov 16, 2020
@davidbrochart
Copy link
Member

Thanks!

@svetlyak40wt
Copy link
Contributor Author

👍

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.

2 participants