Skip to content

Commit 4294544

Browse files
committed
adapt default verbosity and logging behaviour of python
1 parent 4dbbdbb commit 4294544

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,13 @@ protected void launch(Builder contextBuilder) {
163163
// setting this to make sure our TopLevelExceptionHandler calls the excepthook
164164
// to print Python exceptions
165165
contextBuilder.option("python.AlwaysRunExcepthook", "true");
166+
contextBuilder.option("log.level", "WARNING");
166167
if (inspectFlag) {
167168
contextBuilder.option("python.InspectFlag", "true");
168169
}
169170
if (verboseFlag) {
170171
contextBuilder.option("python.VerboseFlag", "true");
172+
contextBuilder.option("log.python.level", "FINE");
171173
}
172174

173175
ConsoleHandler consoleHandler = createConsoleHandler(System.in, System.out);

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import com.oracle.graal.python.nodes.control.TopLevelExceptionHandler;
5050
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5151
import com.oracle.graal.python.nodes.object.GetClassNode;
52-
import com.oracle.graal.python.nodes.statement.ImportNode;
5352
import com.oracle.graal.python.parser.PythonParserImpl;
5453
import com.oracle.graal.python.runtime.PythonContext;
5554
import com.oracle.graal.python.runtime.PythonCore;
@@ -216,29 +215,31 @@ protected CallTarget parse(ParsingRequest request) throws Exception {
216215
PythonContext context = this.getContextReference().get();
217216
PythonCore pythonCore = context.getCore();
218217
Source source = request.getSource();
218+
CompilerDirectives.transferToInterpreter();
219219
if (pythonCore.isInitialized()) {
220220
context.initializeMainModule(source.getPath());
221221

222222
// if we are running the interpreter, module 'site' is automatically imported
223223
if (source.isInteractive()) {
224-
CompilerAsserts.neverPartOfCompilation();
225-
// no frame required
226-
new ImportNode("site").execute(null);
224+
Truffle.getRuntime().createCallTarget(new TopLevelExceptionHandler(this, doParse(pythonCore, Source.newBuilder(ID, "import site", "<site import>").build()))).call();
227225
}
228226
}
229-
RootNode root;
227+
RootNode root = doParse(pythonCore, source);
228+
if (pythonCore.isInitialized()) {
229+
return Truffle.getRuntime().createCallTarget(new TopLevelExceptionHandler(this, root));
230+
} else {
231+
return Truffle.getRuntime().createCallTarget(root);
232+
}
233+
}
234+
235+
private RootNode doParse(PythonCore pythonCore, Source source) {
230236
try {
231-
root = (RootNode) pythonCore.getParser().parse(source.isInteractive() ? ParserMode.InteractiveStatement : ParserMode.File, pythonCore, source, null);
237+
return (RootNode) pythonCore.getParser().parse(source.isInteractive() ? ParserMode.InteractiveStatement : ParserMode.File, pythonCore, source, null);
232238
} catch (PException e) {
233239
// handle PException during parsing (PIncompleteSourceException will propagate through)
234240
Truffle.getRuntime().createCallTarget(new TopLevelExceptionHandler(this, e)).call();
235241
throw e;
236242
}
237-
if (pythonCore.isInitialized()) {
238-
return Truffle.getRuntime().createCallTarget(new TopLevelExceptionHandler(this, root));
239-
} else {
240-
return Truffle.getRuntime().createCallTarget(root);
241-
}
242243
}
243244

244245
@Override
@@ -370,7 +371,7 @@ protected String toString(PythonContext context, Object value) {
370371
}
371372

372373
public static TruffleLogger getLogger() {
373-
return TruffleLogger.getLogger(ID, PythonLanguage.class);
374+
return TruffleLogger.getLogger(ID);
374375
}
375376

376377
public static Source newSource(PythonContext ctxt, String src, String name) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ public final class Python3Core implements PythonCore {
162162
"method",
163163
"code",
164164
"_warnings",
165+
"posix",
166+
"_io",
165167
"_frozen_importlib_external",
166168
"_frozen_importlib",
167-
"posix",
168169
"classes",
169170
"_weakref",
170-
"_io",
171171
"set",
172172
"itertools",
173173
"base_exception",

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
7272
import com.oracle.graal.python.runtime.PythonContext;
7373
import com.oracle.graal.python.runtime.PythonCore;
74+
import com.oracle.graal.python.runtime.PythonOptions;
7475
import com.oracle.graal.python.runtime.exception.PException;
7576
import com.oracle.graal.python.runtime.exception.PythonErrorType;
7677
import com.oracle.truffle.api.CompilerDirectives;
@@ -159,7 +160,7 @@ public void initialize(PythonCore core) {
159160
false, // no_user_site
160161
false, // optimize
161162
false, // quiet
162-
false, // verbose
163+
PythonOptions.getOption(core.getContext(), PythonOptions.VerboseFlag).booleanValue(), // verbose
163164
}));
164165
// the default values taken from JPython
165166
builtinConstants.put("float_info", core.factory().createTuple(new Object[]{

0 commit comments

Comments
 (0)