From 3dde262d3c9b8b9729828f52094767440c5b8071 Mon Sep 17 00:00:00 2001 From: Kwankyu Lee Date: Tue, 4 Nov 2025 22:15:00 +0900 Subject: [PATCH 1/6] Make checking robust --- src/sage/repl/ipython_kernel/install.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sage/repl/ipython_kernel/install.py b/src/sage/repl/ipython_kernel/install.py index 9fd8dd477e4..23e5966c353 100644 --- a/src/sage/repl/ipython_kernel/install.py +++ b/src/sage/repl/ipython_kernel/install.py @@ -257,13 +257,14 @@ def check(cls): try: spec = get_kernel_spec(ident) except NoSuchKernel: - warnings.warn(f'no kernel named {ident} is accessible; ' + warnings.warn(f'No kernel named {ident} is accessible; ' 'check your Jupyter configuration ' '(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html)') else: + import sys, shutil from pathlib import Path - if Path(spec.argv[0]).resolve() != Path(os.path.join(SAGE_VENV, 'bin', 'sage')).resolve(): - warnings.warn(f'the kernel named {ident} does not seem to correspond to this ' + if Path(shutil.which(spec.argv[0])).resolve() != Path(sys.executable).resolve(): + warnings.warn(f'The kernel named "{ident}" does not seem to correspond to this ' 'installation of SageMath; check your Jupyter configuration ' '(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html)') From 3fa454abe0c8a4a8358310a63a48bac33cd03232 Mon Sep 17 00:00:00 2001 From: Kwankyu Lee Date: Tue, 4 Nov 2025 22:18:06 +0900 Subject: [PATCH 2/6] Go without quotation marks --- src/sage/repl/ipython_kernel/install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/repl/ipython_kernel/install.py b/src/sage/repl/ipython_kernel/install.py index 23e5966c353..648f96db0c9 100644 --- a/src/sage/repl/ipython_kernel/install.py +++ b/src/sage/repl/ipython_kernel/install.py @@ -264,7 +264,7 @@ def check(cls): import sys, shutil from pathlib import Path if Path(shutil.which(spec.argv[0])).resolve() != Path(sys.executable).resolve(): - warnings.warn(f'The kernel named "{ident}" does not seem to correspond to this ' + warnings.warn(f'The kernel named {ident} does not seem to correspond to this ' 'installation of SageMath; check your Jupyter configuration ' '(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html)') From 053f5cac858e65a4da26faec5c0b2245fe4219ba Mon Sep 17 00:00:00 2001 From: Kwankyu Lee Date: Tue, 4 Nov 2025 22:22:56 +0900 Subject: [PATCH 3/6] Soothe ruff --- src/sage/repl/ipython_kernel/install.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sage/repl/ipython_kernel/install.py b/src/sage/repl/ipython_kernel/install.py index 648f96db0c9..5e91fe62b57 100644 --- a/src/sage/repl/ipython_kernel/install.py +++ b/src/sage/repl/ipython_kernel/install.py @@ -261,7 +261,8 @@ def check(cls): 'check your Jupyter configuration ' '(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html)') else: - import sys, shutil + import sys + import shutil from pathlib import Path if Path(shutil.which(spec.argv[0])).resolve() != Path(sys.executable).resolve(): warnings.warn(f'The kernel named {ident} does not seem to correspond to this ' From cf58a7b05f30e2401e15a772d28adc6ac84cb1d4 Mon Sep 17 00:00:00 2001 From: Kwankyu Lee Date: Wed, 5 Nov 2025 19:49:16 +0900 Subject: [PATCH 4/6] Add a period at the end of message --- src/sage/repl/ipython_kernel/install.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/repl/ipython_kernel/install.py b/src/sage/repl/ipython_kernel/install.py index 5e91fe62b57..d5585840896 100644 --- a/src/sage/repl/ipython_kernel/install.py +++ b/src/sage/repl/ipython_kernel/install.py @@ -259,7 +259,7 @@ def check(cls): except NoSuchKernel: warnings.warn(f'No kernel named {ident} is accessible; ' 'check your Jupyter configuration ' - '(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html)') + '(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html).') else: import sys import shutil @@ -267,7 +267,7 @@ def check(cls): if Path(shutil.which(spec.argv[0])).resolve() != Path(sys.executable).resolve(): warnings.warn(f'The kernel named {ident} does not seem to correspond to this ' 'installation of SageMath; check your Jupyter configuration ' - '(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html)') + '(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html).') def have_prerequisites(debug=True) -> bool: From 0b3f7b9b0e551238b6a32605799cea3d77726688 Mon Sep 17 00:00:00 2001 From: Kwankyu Lee Date: Sun, 9 Nov 2025 16:50:52 +0900 Subject: [PATCH 5/6] Deal with the case that no kernel executable is available --- src/sage/repl/ipython_kernel/install.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sage/repl/ipython_kernel/install.py b/src/sage/repl/ipython_kernel/install.py index d5585840896..6366e6e1192 100644 --- a/src/sage/repl/ipython_kernel/install.py +++ b/src/sage/repl/ipython_kernel/install.py @@ -264,7 +264,12 @@ def check(cls): import sys import shutil from pathlib import Path - if Path(shutil.which(spec.argv[0])).resolve() != Path(sys.executable).resolve(): + kernel_executable = shutil.which(spec.argv[0]) + if not kernel_executable: + warnings.warn(f'The kernel named {ident} does not seem to be runnable; ' + 'check your Jupyter configuration ' + '(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html).') + if Path(kernel_executable).resolve() != Path(sys.executable).resolve(): warnings.warn(f'The kernel named {ident} does not seem to correspond to this ' 'installation of SageMath; check your Jupyter configuration ' '(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html).') From c1570574677482a4e07159a2cce067a3a800cbb5 Mon Sep 17 00:00:00 2001 From: Kwankyu Lee Date: Mon, 10 Nov 2025 09:36:25 +0900 Subject: [PATCH 6/6] Add missing return statement --- src/sage/repl/ipython_kernel/install.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sage/repl/ipython_kernel/install.py b/src/sage/repl/ipython_kernel/install.py index 6366e6e1192..1af211be936 100644 --- a/src/sage/repl/ipython_kernel/install.py +++ b/src/sage/repl/ipython_kernel/install.py @@ -269,6 +269,7 @@ def check(cls): warnings.warn(f'The kernel named {ident} does not seem to be runnable; ' 'check your Jupyter configuration ' '(see https://docs.jupyter.org/en/latest/use/jupyter-directories.html).') + return if Path(kernel_executable).resolve() != Path(sys.executable).resolve(): warnings.warn(f'The kernel named {ident} does not seem to correspond to this ' 'installation of SageMath; check your Jupyter configuration '