Skip to content

Commit ceec310

Browse files
author
Release Manager
committed
sagemathgh-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 sagemath#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 sagemath#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, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#41132 Reported by: Kwankyu Lee Reviewer(s):
2 parents 507bb81 + 0b3f7b9 commit ceec310

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/sage/repl/ipython_kernel/install.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,22 @@ 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+
if Path(kernel_executable).resolve() != Path(sys.executable).resolve():
273+
warnings.warn(f'The kernel named {ident} does not seem to correspond to this '
267274
'installation of SageMath; check your Jupyter configuration '
268-
'(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html)')
275+
'(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html).')
269276

270277

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

0 commit comments

Comments
 (0)