Class PythonBytecodeCompiler
java.lang.Object
io.micronaut.python.compiler.PythonBytecodeCompiler
- All Implemented Interfaces:
AutoCloseable
Produces GraalPy-compatible, hash-based Python bytecode without requiring a Python launcher
or a writable Python filesystem.
- Since:
- 5.2.0
- Author:
- Micronaut
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA generated bytecode payload. -
Constructor Summary
ConstructorsConstructorDescriptionCreate an embedded GraalPy bytecode compiler.PythonBytecodeCompiler(org.graalvm.polyglot.Context context) Create a bytecode compiler that reuses an existing GraalPy context. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Compile source text to a checked-hash.pycpayload.static voidcompileVfsResources(Path resourceRoot, Path filesListPath) Compile Python resources listed in a VFSfileslist.txtand append the cache entries.static voidCompile all Python source entries listed by a GraalPy VFS file list.
-
Constructor Details
-
PythonBytecodeCompiler
public PythonBytecodeCompiler()Create an embedded GraalPy bytecode compiler. -
PythonBytecodeCompiler
public PythonBytecodeCompiler(org.graalvm.polyglot.Context context) Create a bytecode compiler that reuses an existing GraalPy context. Closing this compiler does not close the supplied context.- Parameters:
context- The existing context
-
-
Method Details
-
compile
Compile source text to a checked-hash.pycpayload.- Parameters:
source- The Python source textfilename- The logical source filename used for bytecode cache naming and tracebacks- Returns:
- The cache filename selected by GraalPy and its bytecode bytes
-
main
Compile all Python source entries listed by a GraalPy VFS file list.- Parameters:
args- The VFS resource root followed by the relative file list path- Throws:
IOException- If an input or output resource cannot be read or written
-
compileVfsResources
Compile Python resources listed in a VFSfileslist.txtand append the cache entries.- Parameters:
resourceRoot- The physical root of the processed VFS resource directoryfilesListPath- The file list path relative toresourceRoot- Throws:
IOException- If an input or output resource cannot be read or written
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-