Class PythonAstParser

java.lang.Object
io.micronaut.python.processing.PythonAstParser

public final class PythonAstParser extends Object
Parses Python source files into the internal Python processing model.
  • Field Details

  • Constructor Details

    • PythonAstParser

      public PythonAstParser()
  • Method Details

    • parse

      public PythonEnvironment parse(String sources)
    • parse

      public PythonEnvironment parse(String sources, String packageName)
    • parse

      public PythonEnvironment parse(String sources, String packageName, VisitorContext visitorContext)
    • parse

      public PythonEnvironment parse(List<org.graalvm.polyglot.Source> sources, String srcDir)
      Parse the given sources located within the given source directory.
      Parameters:
      sources - The sources
      srcDir - The source directory
      Returns:
      The parsed environment
    • parse

      public PythonEnvironment parse(List<org.graalvm.polyglot.Source> sources, List<String> srcDirs, VisitorContext visitorContext)
      Parse the given sources located within the given source directory.
      Parameters:
      sources - The sources
      srcDirs - The source directories
      visitorContext - The visitor context for constant resolution
      Returns:
      The parsed environment
    • getPackageNameOfSource

      public static String getPackageNameOfSource(String srcDir, org.graalvm.polyglot.Source source)
    • transform

      public PythonAstParser.TransformResult transform(VisitorContext visitorContext, String sources)
    • extractCalls

      public List<PythonCall> extractCalls(org.graalvm.polyglot.Source source)
      Extracts call metadata from Python source without executing it.
      Parameters:
      source - Python source
      Returns:
      discovered calls
    • transform

      @NotNull public @NotNull List<PythonAstParser.TransformResult> transform(VisitorContext visitorContext, org.graalvm.polyglot.Source... pythonSource)
    • transform

      @NotNull public @NotNull List<PythonAstParser.TransformResult> transform(VisitorContext visitorContext, List<String> srcDirs, org.graalvm.polyglot.Source... pythonSource)
      Transforms the given sources located within the given source directories. A source of a source directory is transformed with its package known, so the transformer can resolve the imports of sibling modules of that directory; a module found in one of the directories is a Python module, never a Java import that has to resolve on the compile classpath.
      Parameters:
      visitorContext - The visitor context
      srcDirs - The source directories
      pythonSource - The sources
      Returns:
      The transformed sources, in the order of the sources
    • process

      public PythonEnvironment process(String sources, VisitorContext visitorContext)
    • process

      public PythonEnvironment process(String sources, String packageName, VisitorContext visitorContext)
    • close

      public void close()