@@ -15,6 +15,7 @@ import { which } from "../path.ts";
1515
1616import  {  JupyterCapabilities ,  JupyterKernelspec  }  from  "./types.ts" ; 
1717import  {  warnOnce  }  from  "../log.ts" ; 
18+ import  {  debug  }  from  "../../deno_ral/log.ts" ; 
1819
1920// cache capabilities per language 
2021const  kNoLanguage  =  "(none)" ; 
@@ -24,11 +25,19 @@ export async function jupyterCapabilities(kernelspec?: JupyterKernelspec) {
2425  const  language  =  kernelspec ?. language  ||  kNoLanguage ; 
2526
2627  if  ( ! jupyterCapsCache . has ( language ) )  { 
28+     debug ( 
29+       "Looking for Python binaries and Jupyter capabilities"  + 
30+         ( language  ===  kNoLanguage  ? "."  : ` for language '${ language }  ) , 
31+     ) ; 
32+ 
2733    // if we are targeting julia then prefer the julia installed miniconda 
2834    let  juliaCaps : JupyterCapabilities  |  undefined ; 
2935    if  ( language  ===  "julia" )  { 
3036      juliaCaps  =  await  getVerifiedJuliaCondaJupyterCapabilities ( ) ; 
3137      if  ( juliaCaps )  { 
38+         debug ( 
39+           `Using Jupyter capabilities from Julia conda at '${ juliaCaps . executable }  , 
40+         ) ; 
3241        jupyterCapsCache . set ( language ,  juliaCaps ) ; 
3342        return  juliaCaps ; 
3443      } 
@@ -37,6 +46,9 @@ export async function jupyterCapabilities(kernelspec?: JupyterKernelspec) {
3746    // if there is an explicit python requested then use it 
3847    const  quartoCaps  =  await  getQuartoJupyterCapabilities ( ) ; 
3948    if  ( quartoCaps )  { 
49+       debug ( 
50+         `Python found using QUARTO_PYTHON at '${ quartoCaps . executable }  , 
51+       ) ; 
4052      jupyterCapsCache . set ( language ,  quartoCaps ) ; 
4153      return  quartoCaps ; 
4254    } 
@@ -45,28 +57,43 @@ export async function jupyterCapabilities(kernelspec?: JupyterKernelspec) {
4557    if  ( isWindows  &&  pyPython ( ) )  { 
4658      const  pyLauncherCaps  =  await  getPyLauncherJupyterCapabilities ( ) ; 
4759      if  ( pyLauncherCaps )  { 
60+         debug ( 
61+           `Python found via "py.exe" at ${ pyLauncherCaps . executable }  , 
62+         ) ; 
4863        jupyterCapsCache . set ( language ,  pyLauncherCaps ) ; 
4964      } 
5065    } 
5166
5267    // default handling (also a fallthrough if launcher didn't work out) 
5368    if  ( ! jupyterCapsCache . has ( language ) )  { 
5469      // look for python from conda (conda doesn't provide python3 on windows or mac) 
70+       debug ( "Looking for Jupyter capabilities from conda 'python' binary" ) ; 
5571      const  condaCaps  =  await  getJupyterCapabilities ( [ "python" ] ) ; 
5672      if  ( condaCaps ?. conda )  { 
73+         debug ( 
74+           `Python found using conda at '${ condaCaps . executable }  , 
75+         ) ; 
5776        jupyterCapsCache . set ( language ,  condaCaps ) ; 
5877      }  else  { 
5978        const  caps  =  isWindows 
6079          ? await  getPyLauncherJupyterCapabilities ( ) 
6180          : await  getJupyterCapabilities ( [ "python3" ] ) ; 
6281        if  ( caps )  { 
82+           debug ( 
83+             `Python found at '${ caps . executable }  , 
84+           ) ; 
6385          jupyterCapsCache . set ( language ,  caps ) ; 
6486        } 
6587      } 
6688
6789      // if the version we discovered doesn't have jupyter and we have a julia provided 
6890      // jupyter then go ahead and use that 
6991      if  ( ! jupyterCapsCache . get ( language ) ?. jupyter_core  &&  juliaCaps )  { 
92+         debug ( 
93+           `No Jupyter capabilities found for '${ language } ${  
94+             jupyterCapsCache . get ( language ) ?. executable  
95+           }  , falling back to Julia conda at '${ juliaCaps . executable } , 
96+         ) ; 
7097        jupyterCapsCache . set ( language ,  juliaCaps ) ; 
7198      } 
7299    } 
@@ -80,6 +107,7 @@ export async function jupyterCapabilities(kernelspec?: JupyterKernelspec) {
80107const  S_IXUSR  =  0o100 ; 
81108
82109async  function  getVerifiedJuliaCondaJupyterCapabilities ( )  { 
110+   debug ( "Looking for Jupyter capabilities from Julia conda" ) ; 
83111  let  juliaHome  =  Deno . env . get ( "JULIA_HOME" ) ; 
84112  if  ( ! juliaHome )  { 
85113    const  home  =  isWindows  ? Deno . env . get ( "USERPROFILE" )  : Deno . env . get ( "HOME" ) ; 
@@ -100,8 +128,12 @@ async function getVerifiedJuliaCondaJupyterCapabilities() {
100128        pythonBin , 
101129      ) ; 
102130      if  ( existsSync ( juliaPython ) )  { 
131+         debug ( `Checking Jupyter capabilities for '${ juliaPython }  ) ; 
103132        const  caps  =  await  getJupyterCapabilities ( [ juliaPython ] ) ; 
104133        if  ( caps ?. jupyter_core )  { 
134+           debug ( 
135+             `Python with Jupyter found at '${ caps . executable }  , 
136+           ) ; 
105137          return  caps ; 
106138        } 
107139      } 
@@ -117,8 +149,12 @@ async function getVerifiedJuliaCondaJupyterCapabilities() {
117149      if  ( ! ( file . isFile  &&  file . mode  &&  ( file . mode  &  S_IXUSR ) ) )  { 
118150        continue ; 
119151      } 
152+       debug ( `Checking Jupyter capabilities for '${ path . path }  ) ; 
120153      const  caps  =  await  getJupyterCapabilities ( [ path . path ] ) ; 
121154      if  ( caps ?. jupyter_core )  { 
155+         debug ( 
156+           `Python with Jupyter found at '${ caps . executable }  , 
157+         ) ; 
122158        return  caps ; 
123159      } 
124160    } 
@@ -128,27 +164,34 @@ async function getVerifiedJuliaCondaJupyterCapabilities() {
128164async  function  getQuartoJupyterCapabilities ( )  { 
129165  let  quartoJupyter  =  Deno . env . get ( "QUARTO_PYTHON" ) ; 
130166  if  ( quartoJupyter )  { 
167+     debug ( `Checking QUARTO_PYTHON set to '${ quartoJupyter }  ) ; 
131168    // if the path is relative then resolve it 
132169    if  ( ! isAbsolute ( quartoJupyter ) )  { 
133170      const  path  =  await  which ( quartoJupyter ) ; 
134171      if  ( path )  { 
135172        quartoJupyter  =  path ; 
173+         debug ( `Resolved QUARTO_PYTHON to '${ quartoJupyter }  ) ; 
136174      } 
137175    } 
138176    if  ( existsSync ( quartoJupyter ) )  { 
139177      let  quartoJupyterBin : string  |  undefined  =  quartoJupyter ; 
140178      if  ( Deno . statSync ( quartoJupyter ) . isDirectory )  { 
179+         debug ( 
180+           `QUARTO_PYTHON '${ quartoJupyter }  , 
181+         ) ; 
141182        const  bin  =  [ "python3" ,  "python" ,  "python3.exe" ,  "python.exe" ] 
142183          . find ( ( bin )  =>  { 
143184            return  existsSync ( join ( quartoJupyter ! ,  bin ) ) ; 
144185          } ) ; 
145186        if  ( bin )  { 
187+           debug ( `Found python binary '${ bin }  ) ; 
146188          quartoJupyterBin  =  join ( quartoJupyter ,  bin ) ; 
147189        }  else  { 
148190          quartoJupyterBin  =  undefined ; 
149191        } 
150192      } 
151193      if  ( quartoJupyterBin )  { 
194+         debug ( `Checking Jupyter capabilities for '${ quartoJupyterBin }  ) ; 
152195        return  getJupyterCapabilities ( [ quartoJupyterBin ] ) ; 
153196      } 
154197    }  else  { 
@@ -197,6 +240,7 @@ function pyPython() {
197240} 
198241
199242function  getPyLauncherJupyterCapabilities ( )  { 
243+   debug ( "Using 'py.exe' to get Jupyter capabilities" ) ; 
200244  return  getJupyterCapabilities ( [ "py" ] ,  true ) ; 
201245} 
202246
0 commit comments