Class PythonEnvironment

  • All Implemented Interfaces:
    AdditionalInformationHandler, CleanUpHandler, Destroyable, GlobalInfoSupporter, LoggingLevelHandler, LoggingSupporter, OptionHandler, QuickInfoSupporter, ShallowCopySupporter<Actor>, SizeOfHandler, Stoppable, StoppableWithFeedback, VariablesInspectionHandler, VariableChangeListener, Actor, ErrorHandler, Serializable, Comparable

    public class PythonEnvironment
    extends AbstractStandalone
    Defines what Python executables to use within this context.
    On Linux, you can enforce using the system-wide Python 3 executables by supplying '3' as suffix, which gets appended to the executables.

    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -name <java.lang.String> (property: name)
        The name of the actor.
        default: PythonEnvironment
     
    -annotation <adams.core.base.BaseAnnotation> (property: annotations)
        The annotations to attach to this actor.
        default:
     
    -skip <boolean> (property: skip)
        If set to true, transformation is skipped and the input token is just forwarded
        as it is.
        default: false
     
    -stop-flow-on-error <boolean> (property: stopFlowOnError)
        If set to true, the flow execution at this level gets stopped in case this
        actor encounters an error; the error gets propagated; useful for critical
        actors.
        default: false
     
    -silent <boolean> (property: silent)
        If enabled, then no errors are output in the console; Note: the enclosing
        actor handler must have this enabled as well.
        default: false
     
    -python-path-env-var <adams.core.base.BaseString> [-python-path-env-var ...] (property: pythonPathEnvVar)
        The paths to use for the PYTHONPATH environment variable.
        default:
     
    -python-path-update-type <NO_UPDATE|REPLACE|APPEND|PREPEND> (property: pythonPathUpdateType)
        Determines how to update the PYTHONPATH environment variable.
        default: NO_UPDATE
     
    -python <adams.core.io.PlaceholderFile> (property: python)
        The python executable, uses one on path if pointing to a directory.
        default: ${CWD}
     
    -pip <adams.core.io.PlaceholderFile> (property: pip)
        The pip executable, uses one on path if pointing to a directory.
        default: ${CWD}
     
    -suffix <java.lang.String> (property: suffix)
        The suffix (not extension!) to append to the executable when using the system-wide
        ones; eg on Linux use '3' to enforce Python 3.
        default:
     
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_PythonPathEnvVar

        protected BaseString[] m_PythonPathEnvVar
        the PYTHONPATH environment variable.
      • m_ActualPythonPath

        protected String m_ActualPythonPath
        the actual python path env var (null if not to use).
      • m_ActualPython

        protected String m_ActualPython
        the actual python executable.
      • m_ActualPip

        protected String m_ActualPip
        the actual pip executable.
      • m_Suffix

        protected String m_Suffix
        the suffix to append to the executable.
    • Constructor Detail

      • PythonEnvironment

        public PythonEnvironment()
    • Method Detail

      • reset

        protected void reset()
        Resets the scheme.
        Overrides:
        reset in class AbstractActor
      • setPythonPathEnvVar

        public void setPythonPathEnvVar​(BaseString[] value)
        Sets the path(s) for the PYTHONPATH environment variable.
        Parameters:
        value - the path(s)
      • getPythonPathEnvVar

        public BaseString[] getPythonPathEnvVar()
        Returns the path(s) for the PYTHONPATH environment variable.
        Returns:
        the path(s)
      • pythonPathEnvVarTipText

        public String pythonPathEnvVarTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setPythonPathUpdateType

        public void setPythonPathUpdateType​(PythonEnvironment.PythonPathUpdateType value)
        Sets how to update the PYTHONPATH environment variable.
        Parameters:
        value - the update type
      • pythonPathUpdateTypeTipText

        public String pythonPathUpdateTypeTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setPython

        public void setPython​(PlaceholderFile value)
        Sets the python executable, uses one on path if pointing to directory.
        Parameters:
        value - the executable
      • getPython

        public PlaceholderFile getPython()
        Returns the python executable, uses one on path if pointing to directory.
        Returns:
        the executable
      • pythonTipText

        public String pythonTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setPip

        public void setPip​(PlaceholderFile value)
        Sets the pip executable, uses one on path if pointing to directory.
        Parameters:
        value - the executable
      • getPip

        public PlaceholderFile getPip()
        Returns the pip executable, uses one on path if pointing to directory.
        Returns:
        the executable
      • pipTipText

        public String pipTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setSuffix

        public void setSuffix​(String value)
        Sets the suffix to append to the system-wide executables.
        Parameters:
        value - the suffix
      • getSuffix

        public String getSuffix()
        Returns the suffix to append to the system-wide executables.
        Returns:
        the suffix
      • suffixTipText

        public String suffixTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • getActualPythonPath

        public String getActualPythonPath()
        Returns the actual PYTHONPATH environment variable.
        Returns:
        the variable, null if not yet configured or not to be used
      • updatePythonPath

        public void updatePythonPath​(Map<String,​String> env)
        Updates the PYTHONPATH value in the environment if necessary.
        Parameters:
        env - the environment to update
      • getActualPython

        public String getActualPython()
        Returns the actual python executable.
        Returns:
        the executable, null if not yet configured
      • getActualPip

        public String getActualPip()
        Returns the actual pip executable.
        Returns:
        the executable, null if not yet configured
      • getActualBinDir

        public String getActualBinDir()
        Returns the directory with the binaries, uses either the parent directory of the actual python or pip executable to determine that.
        Returns:
        the binary dir
      • doExecute

        protected String doExecute()
        Executes the flow item.
        Specified by:
        doExecute in class AbstractActor
        Returns:
        null if everything is fine, otherwise error message