Class PythonProcessingSession

java.lang.Object
io.micronaut.python.processing.PythonProcessingSession
All Implemented Interfaces:
AutoCloseable

public final class PythonProcessingSession extends Object implements AutoCloseable
Owns the initialized GraalPy processing context across multiple serialized compilations.

A session is not thread safe. Callers must serialize compilations that share it.

Since:
5.2.0
  • Constructor Details

    • PythonProcessingSession

      public PythonProcessingSession()
  • Method Details

    • classLoader

      @Internal public ClassLoader classLoader(List<File> classpath, Supplier<ClassLoader> factory)
      Obtains the annotation processor class loader associated with this processing session.

      The GraalPy context retains its host class loader. Reusing the context while creating a different processor class loader for every compilation makes annotation types loaded by Python incompatible with the visitors loaded for the current compilation. The class loader must therefore have the same lifetime as the context.

      Parameters:
      classpath - The effective annotation processor classpath
      factory - Creates the class loader when the classpath changes
      Returns:
      The session class loader
    • parser

      @Internal public PythonAstParser parser(ClassLoader classLoader, boolean incremental)
      Obtains the parser for a compilation, initializing GraalPy on first use.
      Parameters:
      classLoader - The annotation processor class loader
      incremental - Whether the compilation is incremental
      Returns:
      The session parser
    • initialized

      public boolean initialized()
      Reports whether GraalPy has been initialized.
      Returns:
      Whether GraalPy has been initialized for this session
    • close

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