@@ -88,6 +88,7 @@ public static void main(String[] args) {
88
88
private boolean wantsExperimental = false ;
89
89
private Map <String , String > enginePolyglotOptions ;
90
90
private boolean dontWriteBytecode = false ;
91
+ private String warnOptions = null ;
91
92
92
93
@ Override
93
94
protected List <String > preprocessArguments (List <String > givenArgs , Map <String , String > polyglotOptions ) {
@@ -153,6 +154,20 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
153
154
case "-S" :
154
155
noSite = true ;
155
156
break ;
157
+ case "-W" :
158
+ i += 1 ;
159
+ if (warnOptions == null ) {
160
+ warnOptions = "" ;
161
+ } else {
162
+ warnOptions += "," ;
163
+ }
164
+ if (i < arguments .size ()) {
165
+ warnOptions += arguments .get (i );
166
+ } else {
167
+ print ("Argument expected for the -W option" );
168
+ printShortHelp ();
169
+ }
170
+ break ;
156
171
case "-X" :
157
172
i ++;
158
173
if (i < arguments .size ()) {
@@ -230,6 +245,14 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
230
245
inputFile = arg ;
231
246
programArgs .add (inputFile );
232
247
break ;
248
+ } else if (arg .startsWith ("-W" )) {
249
+ // alternate allowed form
250
+ if (warnOptions == null ) {
251
+ warnOptions = "" ;
252
+ } else {
253
+ warnOptions += "," ;
254
+ }
255
+ warnOptions += arg .substring (2 );
233
256
} else if (!arg .startsWith ("--" ) && arg .length () > 2 ) {
234
257
// short arguments can be given together
235
258
String [] split = arg .substring (1 ).split ("" );
@@ -372,12 +395,17 @@ protected void launch(Builder contextBuilder) {
372
395
verboseFlag = verboseFlag || System .getenv ("PYTHONVERBOSE" ) != null ;
373
396
unbufferedIO = unbufferedIO || System .getenv ("PYTHONUNBUFFERED" ) != null ;
374
397
dontWriteBytecode = dontWriteBytecode || System .getenv ("PYTHONDONTWRITEBYTECODE" ) != null ;
398
+ if (warnOptions == null ) {
399
+ warnOptions = System .getenv ("PYTHONWARNINGS" );
400
+ }
375
401
String cachePrefix = System .getenv ("PYTHONPYCACHEPREFIX" );
376
402
if (cachePrefix != null ) {
377
403
contextBuilder .option ("python.PyCachePrefix" , cachePrefix );
378
404
}
379
405
}
380
-
406
+ if (warnOptions == null || warnOptions .isEmpty ()) {
407
+ warnOptions = "default" ;
408
+ }
381
409
String executable = getContextOptionIfSetViaCommandLine ("python.Executable" );
382
410
if (executable != null ) {
383
411
contextBuilder .option ("python.ExecutableList" , executable );
@@ -394,6 +422,7 @@ protected void launch(Builder contextBuilder) {
394
422
contextBuilder .option ("python.InspectFlag" , Boolean .toString (inspectFlag ));
395
423
contextBuilder .option ("python.VerboseFlag" , Boolean .toString (verboseFlag ));
396
424
contextBuilder .option ("python.IsolateFlag" , Boolean .toString (isolateFlag ));
425
+ contextBuilder .option ("python.WarnOptions" , warnOptions );
397
426
contextBuilder .option ("python.DontWriteBytecodeFlag" , Boolean .toString (dontWriteBytecode ));
398
427
if (verboseFlag ) {
399
428
contextBuilder .option ("log.python.level" , "FINE" );
@@ -581,9 +610,8 @@ protected void printHelp(OptionCategory maxCategory) {
581
610
"-V : print the Python version number and exit (also --version)\n " +
582
611
" when given twice, print more information about the build\n " +
583
612
"-X opt : CPython implementation-specific options. Ignored on GraalPython\n " +
584
- // "-W arg : warning control; arg is
585
- // action:message:category:module:lineno\n" +
586
- // " also PYTHONWARNINGS=arg\n" +
613
+ "-W arg : warning control; arg is action:message:category:module:lineno\n " +
614
+ " also PYTHONWARNINGS=arg\n " +
587
615
// "-x : skip first line of source, allowing use of non-Unix forms of
588
616
// #!cmd\n" +
589
617
// "-3 : warn about Python 3.x incompatibilities that 2to3 cannot trivially
0 commit comments