Package jep

Class JepConfig

java.lang.Object
jep.JepConfig

public class JepConfig extends Object

A configuration object for constructing a Jep instance, corresponding to the configuration of the particular Python sub-interpreter. This class is intended to make constructing Jep instances easier while maintaining compatible APIs between releases.

Since:
3.5
  • Constructor Details

    • JepConfig

      public JepConfig()
  • Method Details

    • setIncludePath

      public JepConfig setIncludePath(String includePath)
      Sets a path of directories separated by File.pathSeparator that will be appended to the sub-intepreter's sys.path
      Parameters:
      includePath - directory or directories to include on sys.path
      Returns:
      a reference to this JepConfig
    • addIncludePaths

      public JepConfig addIncludePaths(String... includePaths)
      Adds a path of directories separated by File.pathSeparator that will be appended to the sub-intepreter's sys.path
      Parameters:
      includePaths - directories to include on sys.path
      Returns:
      a reference to this JepConfig
    • setClassLoader

      public JepConfig setClassLoader(ClassLoader classLoader)
      Sets the ClassLoader to use when importing Java classes from Python
      Parameters:
      classLoader - the initial ClassLoader for the Jep instance
      Returns:
      a reference to this JepConfig
    • setClassEnquirer

      public JepConfig setClassEnquirer(ClassEnquirer classEnquirer)
      Sets a ClassEnquirer to determine which imports are Python vs Java, or null for the default ClassList
      Parameters:
      classEnquirer - the ClassEnquirer for the Jep instance
      Returns:
      a reference to this JepConfig
    • redirectStdout

      public JepConfig redirectStdout(OutputStream outputStream)
      Redirects the Python interpreter's sys.stdout to the provided OutputStream.
      Parameters:
      outputStream - the Java OutputStream to redirect Python stdout to
      Returns:
      a reference to this JepConfig
      Since:
      4.0
    • redirectStdErr

      public JepConfig redirectStdErr(OutputStream outputStream)
      Redirects the Python interpreter's sys.stderr to the provided OutputStream.
      Parameters:
      outputStream - the Java OutputStream to redirect Python stderr to
      Returns:
      a reference to this JepConfig
      Since:
      4.0
    • setSharedModules

      public JepConfig setSharedModules(Set<String> sharedModules)
      Sets the names of modules which should be shared with other Jep sub-interpreters. This can make it possible to use modules which are not designed for use from Python sub-interpreters. This should not be necessary for any module written in Python but is intended for extensions that use the c-api. For a complete discussion of the types of problems that can require shared modules see the documentation on shared_modules_hook.py. Note that shared modules cannot be used in a sub-interpreter that has its own allocation state which also means shared modules cannot be used in a sub-interpreter with its own GIL.
      Parameters:
      sharedModules - a set of module names that should be shared
      Returns:
      a reference to this JepConfig
      Since:
      3.6
    • addSharedModules

      public JepConfig addSharedModules(String... sharedModule)
      Adds module names to the set of shared modules
      Parameters:
      sharedModule - a set of module names that should be shared
      Returns:
      a reference to this JepConfig
      Since:
      3.6
      See Also:
    • setSubInterpreterOptions

      public JepConfig setSubInterpreterOptions(SubInterpreterOptions subInterpOptions)
      Set the configuration options for a sub-interpreter. These options are only used in Python version 3.12 or later, when using earlier versions of Python these options are ignored. These options are only used for SubInterpreter and should not be set when configuring SharedInterpreter.
      Parameters:
      subInterpOptions - the sub-interpreter options
      Returns:
      a reference to this JepConfig
      Since:
      4.2
    • createSubInterpreter

      public SubInterpreter createSubInterpreter() throws JepException
      Creates a new Jep instance and its associated sub-interpreter with this JepConfig.
      Throws:
      JepException - if an error occurs
      Since:
      3.9
    • toString

      public String toString()
      Overrides:
      toString in class Object