From 3eac83ad7aba87294afd426bd2a17c10307f80e3 Mon Sep 17 00:00:00 2001 From: Anna Geller Date: Sun, 19 Nov 2023 21:11:01 +0100 Subject: [PATCH] namespace files --- .../plugin/scripts/python/Commands.java | 55 +++++++++++++------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/plugin-script-python/src/main/java/io/kestra/plugin/scripts/python/Commands.java b/plugin-script-python/src/main/java/io/kestra/plugin/scripts/python/Commands.java index 0a9b7779..9548da6f 100644 --- a/plugin-script-python/src/main/java/io/kestra/plugin/scripts/python/Commands.java +++ b/plugin-script-python/src/main/java/io/kestra/plugin/scripts/python/Commands.java @@ -26,6 +26,44 @@ title = "Execute one or more Python scripts from a Command Line Interface." ) @Plugin(examples = { + @Example( + full = true, + title = """ + Execute a Python script in a Conda virtual environment. First, add the following script in the embedded VS Code editor and name it `etl_script.py`: + + ```python + import argparse + + parser = argparse.ArgumentParser() + + parser.add_argument("--num", type=int, default=42, help="Enter an integer") + + args = parser.parse_args() + result = args.num * 2 + print(result) + ``` + + Then, make sure to set the `enabled` flag of the `namespaceFiles` property to `true` to enable [namespace files](https://kestra.io/docs/developer-guide/namespace-files). + ``` + + This flow uses a `PROCESS` runner and Conda virtual environment for process isolation and dependency management. However, note that, by default, Kestra runs tasks in a Docker container (i.e. a `DOCKER` runner), and you can use the `docker` property to customize many options, such as the Docker image to use. + """, + code = """ +id: python_venv +namespace: dev + +tasks: + - id: hello + type: io.kestra.plugin.scripts.python.Commands + namespaceFiles: + enabled: true + runner: PROCESS + beforeCommands: + - conda activate myCondaEnv + commands: + - python etl_script.py + """ + ), @Example( full = true, title = "Execute a Python script from Git in a Docker container and output a file", @@ -65,23 +103,6 @@ from: "{{outputs.outputFile.uris['orders.csv']}}" """ ), - @Example( - full = true, - title = "Execute a Python script in a Conda virtual environment", - code = """ -id: localPythonScript -namespace: dev - -tasks: - - id: hello - type: io.kestra.plugin.scripts.python.Commands - runner: PROCESS - beforeCommands: - - conda activate myCondaEnv - commands: - - python /Users/you/scripts/etl_script.py - """ - ), @Example( full = true, title = "Execute a Python script on a remote worker with a GPU",