Skip to content

Commit cb83c51

Browse files
committed
try to set the filename as URI
1 parent 28c3d5e commit cb83c51

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

Lines changed: 8 additions & 2 deletions
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.net.URI;
2930
import java.net.URL;
3031
import java.text.MessageFormat;
3132
import java.util.ArrayList;
@@ -88,6 +89,7 @@
8889
import com.oracle.truffle.api.object.ObjectType;
8990
import com.oracle.truffle.api.object.Shape;
9091
import com.oracle.truffle.api.source.Source;
92+
import com.oracle.truffle.api.source.Source.LiteralBuilder;
9193
import com.oracle.truffle.api.source.Source.SourceBuilder;
9294
import com.oracle.truffle.api.source.SourceSection;
9395

@@ -422,9 +424,13 @@ public static TruffleLogger getLogger() {
422424
return TruffleLogger.getLogger(ID);
423425
}
424426

425-
public static Source newSource(PythonContext ctxt, String src, String name) {
427+
public static Source newSource(PythonContext ctxt, String src, String name, URI uri) {
426428
try {
427-
return newSource(ctxt, Source.newBuilder(ID, src, name), name);
429+
LiteralBuilder sourceBuilder = Source.newBuilder(ID, src, name);
430+
if (uri != null) {
431+
sourceBuilder.uri(uri);
432+
}
433+
return newSource(ctxt, sourceBuilder, name);
428434
} catch (IOException e) {
429435
throw new AssertionError();
430436
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
import java.io.PrintStream;
7575
import java.io.PrintWriter;
7676
import java.math.BigInteger;
77+
import java.net.URI;
78+
import java.net.URISyntaxException;
7779
import java.nio.CharBuffer;
7880
import java.util.List;
7981
import java.util.function.Supplier;
@@ -720,7 +722,12 @@ PCode compile(OpaqueBytes source, String filename, String mode, Object kwFlags,
720722
@Specialization
721723
@TruffleBoundary
722724
PCode compile(String expression, String filename, String mode, Object kwFlags, Object kwDontInherit, Object kwOptimize) {
723-
Source source = PythonLanguage.newSource(getContext(), expression, filename);
725+
URI uri = null;
726+
try {
727+
uri = new URI("file://" + filename);
728+
} catch (URISyntaxException e) {
729+
}
730+
Source source = PythonLanguage.newSource(getContext(), expression, filename, uri);
724731
ParserMode pm;
725732
if (mode.equals("exec")) {
726733
pm = ParserMode.File;

0 commit comments

Comments
 (0)