Class PythonBytecodeCompiler

java.lang.Object
io.micronaut.python.compiler.PythonBytecodeCompiler
All Implemented Interfaces:
AutoCloseable

@Internal public final class PythonBytecodeCompiler extends Object implements AutoCloseable
Produces GraalPy-compatible, hash-based Python bytecode without requiring a Python launcher or a writable Python filesystem.
Since:
5.2.0
Author:
Micronaut
  • 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

      public PythonBytecodeCompiler.Result compile(String source, String filename)
      Compile source text to a checked-hash .pyc payload.
      Parameters:
      source - The Python source text
      filename - The logical source filename used for bytecode cache naming and tracebacks
      Returns:
      The cache filename selected by GraalPy and its bytecode bytes
    • main

      public static void main(String[] args) throws IOException
      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

      public static void compileVfsResources(Path resourceRoot, Path filesListPath) throws IOException
      Compile Python resources listed in a VFS fileslist.txt and append the cache entries.
      Parameters:
      resourceRoot - The physical root of the processed VFS resource directory
      filesListPath - The file list path relative to resourceRoot
      Throws:
      IOException - If an input or output resource cannot be read or written
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable