Package name.jurgenei.gradle.python
Class PythonRunnerTask
java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
name.jurgenei.gradle.python.PythonRunnerTask
- All Implemented Interfaces:
Comparable<org.gradle.api.Task>,org.gradle.api.internal.DynamicObjectAware,org.gradle.api.internal.TaskInternal,org.gradle.api.Named,org.gradle.api.plugins.ExtensionAware,org.gradle.api.Task,org.gradle.util.Configurable<org.gradle.api.Task>
public class PythonRunnerTask
extends org.gradle.api.DefaultTask
Gradle task that executes a Python script from a project directory.
Execution model:
- Creates a virtual environment under
.venvif it does not exist. - Optionally installs dependencies from
requirements.txt. - Skips dependency installation when the requirements file hash is unchanged.
- Runs the configured script and fails the task on non-zero exit code.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordProcess result for a script execution.Nested classes/interfaces inherited from interface org.gradle.api.Named
org.gradle.api.Named.Namer -
Field Summary
Fields inherited from interface org.gradle.api.Task
TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetArgs()Returns positional arguments passed to the script.Returns the Python executable used to create the virtual environment.Returns the requirements file used for dependency installation.Returns the script file to execute.Returns the working directory used for command execution and venv storage.Returns the configured working directory path for incremental input tracking.voidTask entry point that prepares the environment and executes the script.voidSets positional arguments passed to the script.voidsetPythonExecutable(String pythonExecutable) Sets the Python executable used to create the virtual environment.voidsetRequirements(File requirements) Sets the requirements file for dependency installation.voidSets the script file to execute.voidsetWorkDir(File workDir) Sets the working directory used for command execution and venv storage.Methods inherited from class org.gradle.api.DefaultTask
compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesServiceMethods inherited from class org.gradle.api.internal.AbstractTask
acceptServiceReferences, appendParallelSafeAction, doNotTrackState, getAsDynamicObject, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, setImpliesSubProjectsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gradle.api.Task
doNotTrackState, notCompatibleWithConfigurationCache
-
Constructor Details
-
PythonRunnerTask
public PythonRunnerTask()
-
-
Method Details
-
runPython
Task entry point that prepares the environment and executes the script.- Throws:
Exception- if environment setup or script execution fails
-
getScript
Returns the script file to execute.- Returns:
- configured Python script
-
setScript
Sets the script file to execute.- Parameters:
script- Python script path
-
getRequirements
Returns the requirements file used for dependency installation.- Returns:
- requirements file or
null
-
setRequirements
Sets the requirements file for dependency installation.- Parameters:
requirements- requirements file path
-
getWorkDir
Returns the working directory used for command execution and venv storage.- Returns:
- working directory or
nullwhen default resolution is used
-
getWorkDirPath
Returns the configured working directory path for incremental input tracking.- Returns:
- absolute path of configured workDir, or
nullwhen unset
-
setWorkDir
Sets the working directory used for command execution and venv storage.- Parameters:
workDir- task working directory
-
getArgs
Returns positional arguments passed to the script.- Returns:
- script arguments
-
setArgs
Sets positional arguments passed to the script.- Parameters:
args- script arguments;nullis treated as empty
-
getPythonExecutable
Returns the Python executable used to create the virtual environment.- Returns:
- Python executable path or command
-
setPythonExecutable
Sets the Python executable used to create the virtual environment.- Parameters:
pythonExecutable- executable path or command
-