Package adams.flow.standalone
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PythonEnvironment.PythonPathUpdateType
How to update the environment varibale.
-
Field Summary
Fields Modifier and Type Field Description protected String
m_ActualPip
the actual pip executable.protected String
m_ActualPython
the actual python executable.protected String
m_ActualPythonPath
the actual python path env var (null if not to use).protected PlaceholderFile
m_Pip
the pip executable.protected PlaceholderFile
m_Python
the python executable.protected BaseString[]
m_PythonPathEnvVar
the PYTHONPATH environment variable.protected PythonEnvironment.PythonPathUpdateType
m_PythonPathUpdateType
how to update the PYTHONPATH environment variable.protected String
m_Suffix
the suffix to append to the executable.static String
PYTHONPATH
the placeholder for the environment variable.-
Fields inherited from class adams.flow.core.AbstractActor
m_Annotations, m_BackupState, m_DetectedObjectVariables, m_DetectedVariables, m_ErrorHandler, m_Executed, m_Executing, m_ExecutionListeningSupporter, m_FullName, m_LoggingPrefix, m_Name, m_Parent, m_ScopeHandler, m_Self, m_Silent, m_Skip, m_StopFlowOnError, m_StopMessage, m_Stopped, m_StorageHandler, m_VariablesUpdated
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
Fields inherited from interface adams.flow.core.Actor
FILE_EXTENSION, FILE_EXTENSION_GZ
-
-
Constructor Summary
Constructors Constructor Description PythonEnvironment()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
defineOptions()
Adds options to the internal list of options.protected String
doExecute()
Executes the flow item.String
getActualBinDir()
Returns the directory with the binaries, uses either the parent directory of the actual python or pip executable to determine that.String
getActualPip()
Returns the actual pip executable.String
getActualPython()
Returns the actual python executable.String
getActualPythonPath()
Returns the actual PYTHONPATH environment variable.PlaceholderFile
getPip()
Returns the pip executable, uses one on path if pointing to directory.PlaceholderFile
getPython()
Returns the python executable, uses one on path if pointing to directory.BaseString[]
getPythonPathEnvVar()
Returns the path(s) for the PYTHONPATH environment variable.PythonEnvironment.PythonPathUpdateType
getPythonPathUpdateType()
Returns how to update the PYTHONPATH environment variable.String
getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.String
getSuffix()
Returns the suffix to append to the system-wide executables.String
globalInfo()
Returns a string describing the object.String
pipTipText()
Returns the tip text for this property.String
pythonPathEnvVarTipText()
Returns the tip text for this property.String
pythonPathUpdateTypeTipText()
Returns the tip text for this property.String
pythonTipText()
Returns the tip text for this property.protected void
reset()
Resets the scheme.void
setPip(PlaceholderFile value)
Sets the pip executable, uses one on path if pointing to directory.void
setPython(PlaceholderFile value)
Sets the python executable, uses one on path if pointing to directory.void
setPythonPathEnvVar(BaseString[] value)
Sets the path(s) for the PYTHONPATH environment variable.void
setPythonPathUpdateType(PythonEnvironment.PythonPathUpdateType value)
Sets how to update the PYTHONPATH environment variable.void
setSuffix(String value)
Sets the suffix to append to the system-wide executables.String
suffixTipText()
Returns the tip text for this property.void
updatePythonPath(Map<String,String> env)
Updates the PYTHONPATH value in the environment if necessary.-
Methods inherited from class adams.flow.standalone.AbstractStandalone
preExecute
-
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, backupState, canInspectOptions, canPerformSetUpCheck, cleanUp, compareTo, configureLogger, destroy, equals, execute, finalUpdateVariables, findVariables, findVariables, forceVariables, forCommandLine, forName, forName, getAdditionalInformation, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowActors, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, handleException, hasErrorHandler, hasStopMessage, index, initialize, isBackedUp, isExecuted, isExecuting, isFinished, isHeadless, isStopped, nameTipText, performSetUpChecks, performVariableChecks, postExecute, pruneBackup, pruneBackup, restoreState, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setUp, setVariables, shallowCopy, shallowCopy, silentTipText, sizeOf, skipTipText, stopExecution, stopExecution, stopFlowOnErrorTipText, updateDetectedVariables, updatePrefix, updateVariables, variableChanged, wrapUp
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.flow.core.Actor
toCommandLine
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel, setLoggingLevel
-
Methods inherited from interface adams.core.logging.LoggingSupporter
getLogger, isLoggingEnabled
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager
-
-
-
-
Field Detail
-
PYTHONPATH
public static final String PYTHONPATH
the placeholder for the environment variable.- See Also:
- Constant Field Values
-
m_PythonPathEnvVar
protected BaseString[] m_PythonPathEnvVar
the PYTHONPATH environment variable.
-
m_PythonPathUpdateType
protected PythonEnvironment.PythonPathUpdateType m_PythonPathUpdateType
how to update the PYTHONPATH environment variable.
-
m_ActualPythonPath
protected String m_ActualPythonPath
the actual python path env var (null if not to use).
-
m_Python
protected PlaceholderFile m_Python
the python executable.
-
m_ActualPython
protected String m_ActualPython
the actual python executable.
-
m_Pip
protected PlaceholderFile m_Pip
the pip executable.
-
m_ActualPip
protected String m_ActualPip
the actual pip executable.
-
m_Suffix
protected String m_Suffix
the suffix to append to the executable.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractActor
-
reset
protected void reset()
Resets the scheme.- Overrides:
reset
in classAbstractActor
-
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
-
getPythonPathUpdateType
public PythonEnvironment.PythonPathUpdateType getPythonPathUpdateType()
Returns how to update the PYTHONPATH environment variable.- Returns:
- 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.
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.- Specified by:
getQuickInfo
in interfaceActor
- Specified by:
getQuickInfo
in interfaceQuickInfoSupporter
- Overrides:
getQuickInfo
in classAbstractActor
- Returns:
- null if no info available, otherwise short string
-
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 classAbstractActor
- Returns:
- null if everything is fine, otherwise error message
-
-