@@ -44,32 +44,27 @@ async def pre_launch(self, **kwargs: Any) -> dict[str, Any]:
4444
4545 env : dict [str , str ] = kwargs .get ("env" , os .environ .copy ())
4646
47+ # If a new notebook is saved with the Pixi-kernel environment selection panel opened, the
48+ # environment field in the Notebook metadata could become an empty string.
49+ # https://github.com/renan-r-santos/pixi-kernel/issues/43#issuecomment-2676320749
50+ environment_name = ""
51+
4752 # https://github.com/jupyterlab/jupyterlab/issues/16282
4853 notebook_path = env .get ("JPY_SESSION_NAME" )
4954 if notebook_path is None :
50- self .log .error (
51- "Failed to get notebook path from JPY_SESSION_NAME variable."
52- "Falling back to the default environment."
53- )
54- environment_name = "default"
55+ self .log .error ("Failed to get notebook path from JPY_SESSION_NAME variable." )
5556 else :
5657 try :
5758 # Set encoding to utf-8 to avoid issues on Windows
5859 # https://github.com/renan-r-santos/pixi-kernel/issues/55
5960 notebook = json .loads (Path (notebook_path ).read_text (encoding = "utf-8" ))
6061 environment_name = notebook ["metadata" ]["pixi-kernel" ]["environment" ]
6162 except Exception :
62- self .log .exception (
63- "Failed to get Pixi environment name from notebook metadata."
64- "Falling back to default environment."
65- )
66- environment_name = "default"
63+ self .log .exception ("Failed to get Pixi environment name from notebook metadata." )
6764
68- # If a new notebook is saved with the Pixi-kernel environment selection panel opened, the
69- # environment field in the Notebook metadata could become an empty string.
70- # https://github.com/renan-r-santos/pixi-kernel/issues/43#issuecomment-2676320749
7165 if environment_name == "" :
72- environment_name = "default"
66+ environment_name = os .environ .get ("PIXI_KERNEL_DEFAULT_ENVIRONMENT" , "default" )
67+ self .log .info (f"Falling back to the '{ environment_name } ' Pixi environment." )
7368
7469 result = await verify_env_readiness (
7570 environment_name = environment_name ,
0 commit comments