Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

wpk-nist-gov
Copy link

Addresses #1018.

This adds a flag --missing to list and remove subcommands of jupyter 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!

@wpk-nist-gov wpk-nist-gov marked this pull request as draft February 24, 2025 21:58
Copy link
Member

@minrk minrk left a 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?

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()
Copy link
Member

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.

@wpk-nist-gov wpk-nist-gov marked this pull request as ready for review May 1, 2025 15:42
Comment on lines +377 to +383
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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants