Skip to content

Commit a7e222a

Browse files
committed
[roottest] Inherit python executable from main process in nbdiff.py
This makes sure that we're using the exact Python version in the notebook tests that ROOT was built against.
1 parent e829075 commit a7e222a

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

roottest/python/JupyROOT/nbdiff.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,7 @@
77
import tempfile
88

99
nbExtension = ".ipynb"
10-
convCmdTmpl = (
11-
"%s nbconvert "
12-
"--to notebook "
13-
"--ExecutePreprocessor.kernel_name=%s "
14-
"--ExecutePreprocessor.enabled=True "
15-
"--ExecutePreprocessor.timeout=3600 "
16-
"--ExecutePreprocessor.startup_timeout=180 "
17-
"%s "
18-
"--output %s"
19-
)
20-
pythonInterpName = "python3"
10+
pythonInterpName = sys.executable
2111

2212
rootKernelFileContent = (
2313
"""{
@@ -154,23 +144,32 @@ def getInterpreterName():
154144
yes, return its name else return 'ipython'
155145
"""
156146
ret = subprocess.call("type jupyter", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
157-
return "jupyter" if ret == 0 else "i%s" % pythonInterpName
147+
return "jupyter nbconvert" if ret == 0 else "nbconvert"
158148

159149

160150
def getKernelName(inNBName):
161151
with open(inNBName) as f:
162152
nbj = json.load(f)
163153
if nbj["metadata"]["kernelspec"]["language"] == "python":
164-
return pythonInterpName
154+
return "python3"
165155
else: # we support only Python and C++
166156
return "root"
167157

168158

169-
def canReproduceNotebook(inNBName, kernelName, needsCompare):
159+
def canReproduceNotebook(inNBName, needsCompare):
170160
tmpDir = addEtcToEnvironment(os.path.dirname(inNBName))
171161
outNBName = inNBName.replace(nbExtension, "_out" + nbExtension)
172162
interpName = getInterpreterName()
173-
convCmd = convCmdTmpl % (interpName, kernelName, inNBName, outNBName)
163+
convCmd = (
164+
"%s -m %s "
165+
"--to notebook "
166+
"--ExecutePreprocessor.kernel_name=%s "
167+
"--ExecutePreprocessor.enabled=True "
168+
"--ExecutePreprocessor.timeout=3600 "
169+
"--ExecutePreprocessor.startup_timeout=180 "
170+
"%s "
171+
"--output %s" % (pythonInterpName, interpName, getKernelName(inNBName), inNBName, outNBName)
172+
)
174173
exitStatus = os.system(convCmd) # we use system to inherit the environment in os.environ
175174
shutil.rmtree(tmpDir)
176175
if needsCompare:
@@ -206,7 +205,5 @@ def isInputNotebookFileName(filename):
206205
except:
207206
raise ImportError("Cannot import jupyter")
208207

209-
kernelName = getKernelName(nbFileName)
210-
211-
retCode = canReproduceNotebook(nbFileName, kernelName, needsCompare)
208+
retCode = canReproduceNotebook(nbFileName, needsCompare)
212209
sys.exit(retCode)

0 commit comments

Comments
 (0)