@@ -15,6 +15,7 @@ import { which } from "../path.ts";
15
15
16
16
import { JupyterCapabilities , JupyterKernelspec } from "./types.ts" ;
17
17
import { warnOnce } from "../log.ts" ;
18
+ import { debug } from "../../deno_ral/log.ts" ;
18
19
19
20
// cache capabilities per language
20
21
const kNoLanguage = "(none)" ;
@@ -24,11 +25,19 @@ export async function jupyterCapabilities(kernelspec?: JupyterKernelspec) {
24
25
const language = kernelspec ?. language || kNoLanguage ;
25
26
26
27
if ( ! jupyterCapsCache . has ( language ) ) {
28
+ debug (
29
+ "Looking for Python binaries and Jupyter capabilities" +
30
+ ( language === kNoLanguage ? "." : ` for language '${ language } '.` ) ,
31
+ ) ;
32
+
27
33
// if we are targeting julia then prefer the julia installed miniconda
28
34
let juliaCaps : JupyterCapabilities | undefined ;
29
35
if ( language === "julia" ) {
30
36
juliaCaps = await getVerifiedJuliaCondaJupyterCapabilities ( ) ;
31
37
if ( juliaCaps ) {
38
+ debug (
39
+ `Using Jupyter capabilities from Julia conda at '${ juliaCaps . executable } '` ,
40
+ ) ;
32
41
jupyterCapsCache . set ( language , juliaCaps ) ;
33
42
return juliaCaps ;
34
43
}
@@ -37,6 +46,9 @@ export async function jupyterCapabilities(kernelspec?: JupyterKernelspec) {
37
46
// if there is an explicit python requested then use it
38
47
const quartoCaps = await getQuartoJupyterCapabilities ( ) ;
39
48
if ( quartoCaps ) {
49
+ debug (
50
+ `Python found using QUARTO_PYTHON at '${ quartoCaps . executable } '` ,
51
+ ) ;
40
52
jupyterCapsCache . set ( language , quartoCaps ) ;
41
53
return quartoCaps ;
42
54
}
@@ -45,28 +57,43 @@ export async function jupyterCapabilities(kernelspec?: JupyterKernelspec) {
45
57
if ( isWindows && pyPython ( ) ) {
46
58
const pyLauncherCaps = await getPyLauncherJupyterCapabilities ( ) ;
47
59
if ( pyLauncherCaps ) {
60
+ debug (
61
+ `Python found via "py.exe" at ${ pyLauncherCaps . executable } .` ,
62
+ ) ;
48
63
jupyterCapsCache . set ( language , pyLauncherCaps ) ;
49
64
}
50
65
}
51
66
52
67
// default handling (also a fallthrough if launcher didn't work out)
53
68
if ( ! jupyterCapsCache . has ( language ) ) {
54
69
// look for python from conda (conda doesn't provide python3 on windows or mac)
70
+ debug ( "Looking for Jupyter capabilities from conda 'python' binary" ) ;
55
71
const condaCaps = await getJupyterCapabilities ( [ "python" ] ) ;
56
72
if ( condaCaps ?. conda ) {
73
+ debug (
74
+ `Python found using conda at '${ condaCaps . executable } '` ,
75
+ ) ;
57
76
jupyterCapsCache . set ( language , condaCaps ) ;
58
77
} else {
59
78
const caps = isWindows
60
79
? await getPyLauncherJupyterCapabilities ( )
61
80
: await getJupyterCapabilities ( [ "python3" ] ) ;
62
81
if ( caps ) {
82
+ debug (
83
+ `Python found at '${ caps . executable } '` ,
84
+ ) ;
63
85
jupyterCapsCache . set ( language , caps ) ;
64
86
}
65
87
}
66
88
67
89
// if the version we discovered doesn't have jupyter and we have a julia provided
68
90
// jupyter then go ahead and use that
69
91
if ( ! jupyterCapsCache . get ( language ) ?. jupyter_core && juliaCaps ) {
92
+ debug (
93
+ `No Jupyter capabilities found for '${ language } ' in ${
94
+ jupyterCapsCache . get ( language ) ?. executable
95
+ } , falling back to Julia conda at '${ juliaCaps . executable } '`,
96
+ ) ;
70
97
jupyterCapsCache . set ( language , juliaCaps ) ;
71
98
}
72
99
}
@@ -80,6 +107,7 @@ export async function jupyterCapabilities(kernelspec?: JupyterKernelspec) {
80
107
const S_IXUSR = 0o100 ;
81
108
82
109
async function getVerifiedJuliaCondaJupyterCapabilities ( ) {
110
+ debug ( "Looking for Jupyter capabilities from Julia conda" ) ;
83
111
let juliaHome = Deno . env . get ( "JULIA_HOME" ) ;
84
112
if ( ! juliaHome ) {
85
113
const home = isWindows ? Deno . env . get ( "USERPROFILE" ) : Deno . env . get ( "HOME" ) ;
@@ -100,8 +128,12 @@ async function getVerifiedJuliaCondaJupyterCapabilities() {
100
128
pythonBin ,
101
129
) ;
102
130
if ( existsSync ( juliaPython ) ) {
131
+ debug ( `Checking Jupyter capabilities for '${ juliaPython } '` ) ;
103
132
const caps = await getJupyterCapabilities ( [ juliaPython ] ) ;
104
133
if ( caps ?. jupyter_core ) {
134
+ debug (
135
+ `Python with Jupyter found at '${ caps . executable } ' from Julia conda` ,
136
+ ) ;
105
137
return caps ;
106
138
}
107
139
}
@@ -117,8 +149,12 @@ async function getVerifiedJuliaCondaJupyterCapabilities() {
117
149
if ( ! ( file . isFile && file . mode && ( file . mode & S_IXUSR ) ) ) {
118
150
continue ;
119
151
}
152
+ debug ( `Checking Jupyter capabilities for '${ path . path } '` ) ;
120
153
const caps = await getJupyterCapabilities ( [ path . path ] ) ;
121
154
if ( caps ?. jupyter_core ) {
155
+ debug (
156
+ `Python with Jupyter found at '${ caps . executable } ' from Julia conda` ,
157
+ ) ;
122
158
return caps ;
123
159
}
124
160
}
@@ -128,27 +164,34 @@ async function getVerifiedJuliaCondaJupyterCapabilities() {
128
164
async function getQuartoJupyterCapabilities ( ) {
129
165
let quartoJupyter = Deno . env . get ( "QUARTO_PYTHON" ) ;
130
166
if ( quartoJupyter ) {
167
+ debug ( `Checking QUARTO_PYTHON set to '${ quartoJupyter } '` ) ;
131
168
// if the path is relative then resolve it
132
169
if ( ! isAbsolute ( quartoJupyter ) ) {
133
170
const path = await which ( quartoJupyter ) ;
134
171
if ( path ) {
135
172
quartoJupyter = path ;
173
+ debug ( `Resolved QUARTO_PYTHON to '${ quartoJupyter } '` ) ;
136
174
}
137
175
}
138
176
if ( existsSync ( quartoJupyter ) ) {
139
177
let quartoJupyterBin : string | undefined = quartoJupyter ;
140
178
if ( Deno . statSync ( quartoJupyter ) . isDirectory ) {
179
+ debug (
180
+ `QUARTO_PYTHON '${ quartoJupyter } ' is a directory, looking for python binary` ,
181
+ ) ;
141
182
const bin = [ "python3" , "python" , "python3.exe" , "python.exe" ]
142
183
. find ( ( bin ) => {
143
184
return existsSync ( join ( quartoJupyter ! , bin ) ) ;
144
185
} ) ;
145
186
if ( bin ) {
187
+ debug ( `Found python binary '${ bin } ' in QUARTO_PYTHON` ) ;
146
188
quartoJupyterBin = join ( quartoJupyter , bin ) ;
147
189
} else {
148
190
quartoJupyterBin = undefined ;
149
191
}
150
192
}
151
193
if ( quartoJupyterBin ) {
194
+ debug ( `Checking Jupyter capabilities for '${ quartoJupyterBin } '` ) ;
152
195
return getJupyterCapabilities ( [ quartoJupyterBin ] ) ;
153
196
}
154
197
} else {
@@ -197,6 +240,7 @@ function pyPython() {
197
240
}
198
241
199
242
function getPyLauncherJupyterCapabilities ( ) {
243
+ debug ( "Using 'py.exe' to get Jupyter capabilities" ) ;
200
244
return getJupyterCapabilities ( [ "py" ] , true ) ;
201
245
}
202
246
0 commit comments