public class PythonUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
PythonUtils.RawPythonCode |
Modifier and Type | Field and Description |
---|---|
static Class<?>[] |
ALLOWED_PARAMETER_CLASSES |
Modifier and Type | Method and Description |
---|---|
static void |
addPostprocessorCode(StringBuilder code,
List<JIPipeOutputDataSlot> outputSlots) |
static void |
annotationsToPython(StringBuilder code,
Collection<JIPipeTextAnnotation> annotations)
Converts annotations into Python code.
|
static void |
cleanup(Map<String,Path> inputSlotPaths,
Map<String,Path> outputSlotPaths,
JIPipeProgressInfo progressInfo) |
static String |
escapeString(String value)
Escapes a string to be used within Python code
Will not add quotes around the string
|
static void |
extractOutputs(JIPipeDataBatch dataBatch,
Map<String,Path> outputSlotPaths,
List<JIPipeOutputDataSlot> outputSlots,
JIPipeTextAnnotationMergeMode annotationMergeStrategy,
JIPipeProgressInfo progressInfo) |
static void |
extractOutputs(JIPipeMergingDataBatch dataBatch,
Map<String,Path> outputSlotPaths,
List<JIPipeOutputDataSlot> outputSlots,
JIPipeTextAnnotationMergeMode annotationMergeStrategy,
JIPipeProgressInfo progressInfo) |
static void |
extractOutputs(Map<String,Path> outputSlotPaths,
List<JIPipeOutputDataSlot> outputSlots,
JIPipeProgressInfo progressInfo) |
static void |
inputSlotsToPython(StringBuilder code,
Map<String,Path> inputSlotPaths) |
static void |
installAdapterCodeIfNeeded(StringBuilder pythonCode) |
static Map<String,Path> |
installInputSlots(StringBuilder code,
JIPipeDataBatch dataBatch,
JIPipeGraphNode node,
List<JIPipeInputDataSlot> effectiveInputSlots,
Path workDirectory,
JIPipeProgressInfo progressInfo) |
static Map<String,Path> |
installInputSlots(StringBuilder code,
JIPipeMergingDataBatch dataBatch,
JIPipeGraphNode node,
List<JIPipeInputDataSlot> effectiveInputSlots,
Path workDirectory,
JIPipeProgressInfo progressInfo) |
static Map<String,Path> |
installInputSlots(StringBuilder code,
List<JIPipeInputDataSlot> effectiveInputSlots,
Path workDirectory,
JIPipeProgressInfo progressInfo) |
static Map<String,Path> |
installOutputSlots(StringBuilder code,
List<JIPipeOutputDataSlot> outputSlots,
Path workDirectory,
JIPipeProgressInfo progressInfo) |
static String |
listToPythonArray(Collection<Object> items,
boolean withSurroundingBrackets)
Converts a collection into a Python array
|
static String |
mapToPythonArguments(Map<String,Object> parameters)
Converts a dictionary into a set of Python function arguments
|
static String |
mapToPythonDict(Map<String,Object> parameters)
Converts a dictionary into a set of Python function arguments
|
static String |
objectToPython(Object object)
Converts the object into valid Python code
|
static void |
outputSlotsToPython(StringBuilder code,
List<JIPipeOutputDataSlot> outputSlots,
Map<String,Path> outputSlotPaths) |
static void |
parametersToPython(StringBuilder code,
JIPipeParameterCollection parameterCollection)
Converts parameters into Python code.
|
static PythonUtils.RawPythonCode |
rawPythonCode(String code) |
static void |
runPython(Path scriptFile,
PythonEnvironment environment,
List<Path> libraryPaths,
JIPipeProgressInfo progressInfo)
Runs a Python script file
|
static void |
runPython(String[] arguments,
PythonEnvironment environment,
List<Path> libraryPaths,
Map<String,String> additionalEnvironmentVariables,
JIPipeProgressInfo progressInfo)
Runs Python with a set of arguments
|
static void |
runPython(String code,
PythonEnvironment environment,
List<Path> libraryPaths,
JIPipeProgressInfo progressInfo) |
static void |
setupLogger(org.apache.commons.exec.CommandLine commandLine,
org.apache.commons.exec.DefaultExecutor executor,
JIPipeProgressInfo progressInfo) |
public static Class<?>[] ALLOWED_PARAMETER_CLASSES
public static void annotationsToPython(StringBuilder code, Collection<JIPipeTextAnnotation> annotations)
code
- the codeannotations
- the annotationspublic static void parametersToPython(StringBuilder code, JIPipeParameterCollection parameterCollection)
code
- the codeparameterCollection
- the parameterspublic static void installAdapterCodeIfNeeded(StringBuilder pythonCode)
public static void inputSlotsToPython(StringBuilder code, Map<String,Path> inputSlotPaths)
public static void outputSlotsToPython(StringBuilder code, List<JIPipeOutputDataSlot> outputSlots, Map<String,Path> outputSlotPaths)
public static void addPostprocessorCode(StringBuilder code, List<JIPipeOutputDataSlot> outputSlots)
public static Map<String,Path> installInputSlots(StringBuilder code, JIPipeDataBatch dataBatch, JIPipeGraphNode node, List<JIPipeInputDataSlot> effectiveInputSlots, Path workDirectory, JIPipeProgressInfo progressInfo)
public static Map<String,Path> installInputSlots(StringBuilder code, List<JIPipeInputDataSlot> effectiveInputSlots, Path workDirectory, JIPipeProgressInfo progressInfo)
public static Map<String,Path> installInputSlots(StringBuilder code, JIPipeMergingDataBatch dataBatch, JIPipeGraphNode node, List<JIPipeInputDataSlot> effectiveInputSlots, Path workDirectory, JIPipeProgressInfo progressInfo)
public static void runPython(String code, PythonEnvironment environment, List<Path> libraryPaths, JIPipeProgressInfo progressInfo)
public static void extractOutputs(JIPipeDataBatch dataBatch, Map<String,Path> outputSlotPaths, List<JIPipeOutputDataSlot> outputSlots, JIPipeTextAnnotationMergeMode annotationMergeStrategy, JIPipeProgressInfo progressInfo)
public static void extractOutputs(JIPipeMergingDataBatch dataBatch, Map<String,Path> outputSlotPaths, List<JIPipeOutputDataSlot> outputSlots, JIPipeTextAnnotationMergeMode annotationMergeStrategy, JIPipeProgressInfo progressInfo)
public static void extractOutputs(Map<String,Path> outputSlotPaths, List<JIPipeOutputDataSlot> outputSlots, JIPipeProgressInfo progressInfo)
public static void setupLogger(org.apache.commons.exec.CommandLine commandLine, org.apache.commons.exec.DefaultExecutor executor, JIPipeProgressInfo progressInfo)
public static void runPython(Path scriptFile, PythonEnvironment environment, List<Path> libraryPaths, JIPipeProgressInfo progressInfo)
scriptFile
- the script fileenvironment
- the environmentlibraryPaths
- additional library pathsprogressInfo
- the progress infopublic static void runPython(String[] arguments, PythonEnvironment environment, List<Path> libraryPaths, Map<String,String> additionalEnvironmentVariables, JIPipeProgressInfo progressInfo)
arguments
- the argumentsenvironment
- the environmentlibraryPaths
- additional library pathsadditionalEnvironmentVariables
- additional environment variablesprogressInfo
- the progress infopublic static String escapeString(String value)
value
- unescaped stringpublic static String objectToPython(Object object)
object
- the objectpublic static String listToPythonArray(Collection<Object> items, boolean withSurroundingBrackets)
items
- the itemswithSurroundingBrackets
- if enabled, surrounding brackets are addedpublic static String mapToPythonDict(Map<String,Object> parameters)
parameters
- the parameterspublic static String mapToPythonArguments(Map<String,Object> parameters)
parameters
- the parameterspublic static void cleanup(Map<String,Path> inputSlotPaths, Map<String,Path> outputSlotPaths, JIPipeProgressInfo progressInfo)
public static Map<String,Path> installOutputSlots(StringBuilder code, List<JIPipeOutputDataSlot> outputSlots, Path workDirectory, JIPipeProgressInfo progressInfo)
public static PythonUtils.RawPythonCode rawPythonCode(String code)
Copyright © 2020–2022 Leibniz Institute for Natural Product Research and Infection Biology - Hans Knöll Institute (HKI). All rights reserved.