Skip to content

Commit 1caf8a0

Browse files
committed
run sys.__interactivehook__ if it is defined
1 parent cb7bc0d commit 1caf8a0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ protected CallTarget parse(ParsingRequest request) throws Exception {
231231

232232
// if we are running the interpreter, module 'site' is automatically imported
233233
if (source.isInteractive()) {
234-
Truffle.getRuntime().createCallTarget(new TopLevelExceptionHandler(this, doParse(pythonCore, Source.newBuilder(ID, "import site", "<site import>").build()))).call();
234+
runInteractiveStartup(pythonCore);
235235
}
236236
}
237237
RootNode root = doParse(pythonCore, source);
@@ -242,6 +242,12 @@ protected CallTarget parse(ParsingRequest request) throws Exception {
242242
}
243243
}
244244

245+
static final String interactiveStartup = "import site\nimport sys\ngetattr(sys, '__interactivehook__', lambda: None)()";
246+
247+
private void runInteractiveStartup(PythonCore pythonCore) {
248+
Truffle.getRuntime().createCallTarget(new TopLevelExceptionHandler(this, doParse(pythonCore, Source.newBuilder(ID, interactiveStartup, "<site import>").build()))).call();
249+
}
250+
245251
private RootNode doParse(PythonCore pythonCore, Source source) {
246252
try {
247253
return (RootNode) pythonCore.getParser().parse(source.isInteractive() ? ParserMode.InteractiveStatement : ParserMode.File, pythonCore, source, null);

0 commit comments

Comments
 (0)