From da5b6d9a4d4ff49ec0d73d4f20bd53c1b75057c1 Mon Sep 17 00:00:00 2001 From: Koncopd Date: Sat, 8 Mar 2025 16:04:03 +0100 Subject: [PATCH 1/2] Fix __vsc_ipynb_file__ unaccessible through user_ns --- nbproject/dev/_jupyter_communicate.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/nbproject/dev/_jupyter_communicate.py b/nbproject/dev/_jupyter_communicate.py index eab463c..f5085d2 100644 --- a/nbproject/dev/_jupyter_communicate.py +++ b/nbproject/dev/_jupyter_communicate.py @@ -1,4 +1,5 @@ import os +import sys from itertools import chain from pathlib import PurePath from urllib import request @@ -90,6 +91,15 @@ def notebook_path(return_env=False): logger.warning("Can not import get_ipython.") return None + # vs code specific + if "__main__" in sys.modules: + main_module = sys.modules["__main__"] + if hasattr(main_module, "__vsc_ipynb_file__"): + nb_path = main_module.__vsc_ipynb_file__ + return ( + (nb_path, "vs_code" if env is None else env) if return_env else nb_path + ) + ipython_instance = get_ipython() # not in an ipython kernel @@ -97,12 +107,6 @@ def notebook_path(return_env=False): logger.warning("The IPython instance is empty.") return None - # vs code specific - user_ns = ipython_instance.__dict__.get("user_ns", {}) - if "__vsc_ipynb_file__" in user_ns: - nb_path = PurePath(user_ns["__vsc_ipynb_file__"]) - return (nb_path, "vs_code" if env is None else env) if return_env else nb_path - config = ipython_instance.config # not in a jupyter notebook if "IPKernelApp" not in config: From 9d486d70721834f7067f40f4ac011d4d5fecc86c Mon Sep 17 00:00:00 2001 From: Koncopd Date: Sat, 8 Mar 2025 16:07:52 +0100 Subject: [PATCH 2/2] fix --- noxfile.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/noxfile.py b/noxfile.py index 38dc104..816326c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,8 +1,6 @@ import nox from laminci.nox import build_docs, run_pre_commit, run_pytest -nox.options.default_backend = "none" - @nox.session def lint(session: nox.Session) -> None: