-
Notifications
You must be signed in to change notification settings - Fork 296
feat: added --missing
flag to list and remove subcommands
#1056
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
base: main
Are you sure you want to change the base?
feat: added --missing
flag to list and remove subcommands
#1056
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! This sounds like a useful feature. I think we should should have it.
Can you add a test that makes sure a kernel with e.g. "bash"
(no path) as argv[0]
doesn't get deleted?
jupyter_client/kernelspecapp.py
Outdated
for k, v in specs.items() | ||
# If have kernel installed from current environment | ||
# Probably not the best way to do this, but it works in edge cases I've run into. | ||
if (prog := v["spec"]["argv"][0]) != "python" and not Path(prog).exists() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use shutil.which
to resolve things on $PATH, since it is not a requirement that argv[0]
is an absolute path.
Now use `shutil.which` to check missing kernels. This catches things like "python" or "bash"
missing: dict[str, t.Any] = {} | ||
for name, data in specs.items(): | ||
exe = data["spec"]["argv"][0] | ||
# if exe exists or is on the path, keep it | ||
if Path(exe).exists() or which(exe): | ||
continue | ||
missing[name] = data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should address if the path exists or is on the path.
Addresses #1018.
This adds a flag
--missing
tolist
andremove
subcommands ofjupyter kernelspec
. By "missing", we mean that the interpreter (the first argument of spec["spec"]["argv"] of the json specification) does not exist. This simplifies removing kernels pointing to missing environments.I'm not sure how best to test this functionality. Basic smoke tests seem to work. I'm happy to put some more work into this if it seems worthwhile to include in
jupyter-client
.Thanks!