Skip to content

Commit b11c1b5

Browse files
author
Release Manager
committed
gh-41132: Check sagemath kernel integrity robustly <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes #12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes #12345". --> Fix a bug discussed in https://groups.google.com/g/sage- devel/c/rxfhmspCeuw ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #41132 Reported by: Kwankyu Lee Reviewer(s):
2 parents 1c11c14 + c157057 commit b11c1b5

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/sage/repl/ipython_kernel/install.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,23 @@ def check(cls):
257257
try:
258258
spec = get_kernel_spec(ident)
259259
except NoSuchKernel:
260-
warnings.warn(f'no kernel named {ident} is accessible; '
260+
warnings.warn(f'No kernel named {ident} is accessible; '
261261
'check your Jupyter configuration '
262-
'(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html)')
262+
'(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html).')
263263
else:
264+
import sys
265+
import shutil
264266
from pathlib import Path
265-
if Path(spec.argv[0]).resolve() != Path(os.path.join(SAGE_VENV, 'bin', 'sage')).resolve():
266-
warnings.warn(f'the kernel named {ident} does not seem to correspond to this '
267+
kernel_executable = shutil.which(spec.argv[0])
268+
if not kernel_executable:
269+
warnings.warn(f'The kernel named {ident} does not seem to be runnable; '
270+
'check your Jupyter configuration '
271+
'(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html).')
272+
return
273+
if Path(kernel_executable).resolve() != Path(sys.executable).resolve():
274+
warnings.warn(f'The kernel named {ident} does not seem to correspond to this '
267275
'installation of SageMath; check your Jupyter configuration '
268-
'(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html)')
276+
'(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html).')
269277

270278

271279
def have_prerequisites(debug=True) -> bool:

0 commit comments

Comments
 (0)