Skip to content

Commit 8051b5f

Browse files
committed
[GR-14627] Update PythonFileDetector to implement TruffleFile.FileTypeDectector.
1 parent 3a3602c commit 8051b5f

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

graalpython/com.oracle.graal.python/.checkstyle_checks.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</module>
3636
<module name="RedundantImport"/>
3737
<module name="LineLength">
38-
<property name="max" value="255"/>
38+
<property name="max" value="300"/>
3939
</module>
4040
<module name="MethodParamPad"/>
4141
<module name="NoWhitespaceAfter">

graalpython/com.oracle.graal.python/src/META-INF/services/java.nio.file.spi.FileTypeDetector

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,22 @@
4141
package com.oracle.graal.python;
4242

4343
import java.io.IOException;
44-
import java.nio.file.Path;
45-
import java.nio.file.spi.FileTypeDetector;
44+
import com.oracle.truffle.api.TruffleFile;
45+
import java.nio.charset.Charset;
46+
47+
public final class PythonFileDetector implements TruffleFile.FileTypeDetector {
4648

47-
public final class PythonFileDetector extends FileTypeDetector {
4849
@Override
49-
public String probeContentType(Path path) throws IOException {
50-
Path fileName = path.getFileName();
51-
if (fileName != null && fileName.toString().endsWith(".py")) {
50+
public String findMimeType(TruffleFile file) throws IOException {
51+
String fileName = file.getName();
52+
if (fileName != null && fileName.endsWith(".py")) {
5253
return PythonLanguage.MIME_TYPE;
5354
}
5455
return null;
5556
}
57+
58+
@Override
59+
public Charset findEncoding(TruffleFile file) throws IOException {
60+
return null;
61+
}
5662
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191

9292
import org.graalvm.options.OptionDescriptors;
9393

94-
@TruffleLanguage.Registration(id = PythonLanguage.ID, name = PythonLanguage.NAME, version = PythonLanguage.VERSION, characterMimeTypes = PythonLanguage.MIME_TYPE, interactive = true, internal = false, contextPolicy = TruffleLanguage.ContextPolicy.SHARED)
94+
@TruffleLanguage.Registration(id = PythonLanguage.ID, name = PythonLanguage.NAME, version = PythonLanguage.VERSION, characterMimeTypes = PythonLanguage.MIME_TYPE, interactive = true, internal = false, contextPolicy = TruffleLanguage.ContextPolicy.SHARED, fileTypeDetectors = PythonFileDetector.class)
9595
@ProvidedTags({StandardTags.CallTag.class, StandardTags.StatementTag.class, StandardTags.RootTag.class, StandardTags.TryBlockTag.class, StandardTags.ExpressionTag.class,
9696
DebuggerTags.AlwaysHalt.class})
9797
public final class PythonLanguage extends TruffleLanguage<PythonContext> {

0 commit comments

Comments
 (0)