Skip to content

Commit ca2e71c

Browse files
committed
use -v verbose flag to print information about context initialization, too
1 parent c4b594f commit ca2e71c

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public static void main(String[] args) {
6565
private String commandString = null;
6666
private String inputFile = null;
6767
private boolean inspectFlag = false;
68+
private boolean verboseFlag = false;
6869
private boolean runCC = false;
6970
private boolean runLD = false;
7071
private VersionAction versionAction = VersionAction.None;
@@ -81,6 +82,9 @@ protected List<String> preprocessArguments(List<String> arguments, Map<String, S
8182
case "-B":
8283
System.out.println("Warning: " + arg + " does nothing on GraalPython.");
8384
break;
85+
case "-v":
86+
verboseFlag = true;
87+
break;
8488
case "-V":
8589
case "--version":
8690
versionAction = VersionAction.PrintAndExit;
@@ -160,7 +164,10 @@ protected void launch(Builder contextBuilder) {
160164
// to print Python exceptions
161165
contextBuilder.option("python.AlwaysRunExcepthook", "true");
162166
if (inspectFlag) {
163-
contextBuilder.option("python.PythonInspectFlag", "true");
167+
contextBuilder.option("python.InspectFlag", "true");
168+
}
169+
if (verboseFlag) {
170+
contextBuilder.option("python.VerboseFlag", "true");
164171
}
165172

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

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package com.oracle.graal.python;
2727

2828
import java.io.IOException;
29+
import java.text.MessageFormat;
2930
import java.util.ArrayList;
3031

3132
import org.graalvm.options.OptionDescriptors;
@@ -117,7 +118,13 @@ private static boolean optionsAllowPreInitializedContext(PythonContext context,
117118
// Verify that the option for using a shared core is the same as
118119
// at image building time
119120
final boolean useSharedCore = newEnv.getOptions().get(PythonOptions.SharedCore);
120-
return context.getCore().hasSingletonContext() == !useSharedCore;
121+
boolean canUsePreinitializedContext = context.getCore().hasSingletonContext() == !useSharedCore;
122+
if (canUsePreinitializedContext) {
123+
PythonCore.writeInfo(newEnv, "Using preinitialized context.");
124+
} else {
125+
PythonCore.writeInfo(newEnv, "Not using preinitialized context.");
126+
}
127+
return canUsePreinitializedContext;
121128
}
122129

123130
@Override
@@ -137,6 +144,12 @@ private void ensureHomeInOptions(Env env) {
137144
String coreHome = env.getOptions().get(PythonOptions.CoreHome);
138145
String stdLibHome = env.getOptions().get(PythonOptions.StdLibHome);
139146

147+
PythonCore.writeInfo(env, (MessageFormat.format("Initial locations:" +
148+
"\n\tLanguage home: {0}" +
149+
"\n\tSysPrefix: {1}" +
150+
"\n\tCoreHome: {2}" +
151+
"\n\tStdLibHome: {3}", languageHome, sysPrefix, coreHome, stdLibHome)));
152+
140153
TruffleFile home = null;
141154
if (languageHome != null) {
142155
home = env.getTruffleFile(languageHome);
@@ -187,6 +200,12 @@ private void ensureHomeInOptions(Env env) {
187200
}
188201
env.getOptions().set(PythonOptions.StdLibHome, stdLibHome);
189202
}
203+
204+
PythonCore.writeInfo(env, (MessageFormat.format("Updated locations:" +
205+
"\n\tLanguage home: {0}" +
206+
"\n\tSysPrefix: {1}" +
207+
"\n\tCoreHome: {2}" +
208+
"\n\tStdLibHome: {3}", home.getPath(), sysPrefix, coreHome, stdLibHome)));
190209
}
191210
}
192211

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonCore.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,23 @@ public interface PythonCore {
124124
public PythonContext getContext();
125125

126126
static void writeWarning(TruffleLanguage.Env env, String warning) {
127-
if (!LIBPOLYGLOT) {
128-
try {
129-
env.err().write("[python] WARNING: ".getBytes());
130-
env.err().write(warning.getBytes());
131-
env.err().write('\n');
132-
} catch (IOException e) {
133-
}
127+
if (!LIBPOLYGLOT || env.getOptions().get(PythonOptions.VerboseFlag)) {
128+
write(env, "WARNING: " + warning);
129+
}
130+
}
131+
132+
static void writeInfo(TruffleLanguage.Env env, String warning) {
133+
if (env.getOptions().get(PythonOptions.VerboseFlag)) {
134+
write(env, warning);
135+
}
136+
}
137+
138+
static void write(TruffleLanguage.Env env, String warning) {
139+
try {
140+
env.err().write("[python] ".getBytes());
141+
env.err().write(warning.getBytes());
142+
env.err().write('\n');
143+
} catch (IOException e) {
134144
}
135145
}
136146

@@ -155,7 +165,7 @@ public static String getSysPrefix(TruffleLanguage.Env env) {
155165
String sysPrefix = env.getOptions().get(PythonOptions.SysPrefix);
156166
if (sysPrefix.isEmpty()) {
157167
writeWarning(env, NO_PREFIX_WARNING);
158-
env.getOptions().set(PythonOptions.CoreHome, PREFIX);
168+
env.getOptions().set(PythonOptions.SysPrefix, PREFIX);
159169
return LIB_GRAALPYTHON;
160170
}
161171
return sysPrefix;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,14 @@ private PythonOptions() {
9898
public static final OptionKey<Boolean> AlwaysRunExcepthook = new OptionKey<>(false);
9999

100100
@Option(category = OptionCategory.USER, help = "") //
101-
public static final OptionKey<Boolean> PythonInspectFlag = new OptionKey<>(false);
101+
public static final OptionKey<Boolean> InspectFlag = new OptionKey<>(false);
102102

103103
@Option(category = OptionCategory.USER, help = "Remove assert statements and any code conditional on the value of __debug__.") public static final OptionKey<Boolean> PythonOptimizeFlag = new OptionKey<>(
104104
false);
105105

106+
@Option(category = OptionCategory.DEBUG, help = "Turn on verbose mode") //
107+
public static final OptionKey<Boolean> VerboseFlag = new OptionKey<>(false);
108+
106109
public static OptionDescriptors createDescriptors() {
107110
return new PythonOptionsOptionDescriptors();
108111
}

0 commit comments

Comments
 (0)