Syntax ¶
RKD is elastic. Different syntax allows to choose between ease of usage and extended possibilities.
YAML ¶
-
Best choice to start with RKD, perfect for simpler usage
-
Gives clear view on what is defined, has obvious structure
-
Created tasks are not possible to be shared as part of Python package
version: org.riotkit.rkd/yaml/v1
tasks:
:hello1:
extends: rkd.core.standardlib.syntax.PythonSyntaxTask
arguments:
"--name":
required: True
help: "Allows to specify a name"
description: Prints your name
execute: |
self.io().info_msg(f'Hello {ctx.get_arg("--name")}, I\'m talking from YAML, and you?')
return True
Simplified Python ¶
-
Practical replacement for YAML syntax, good choice for more advanced tasks
-
Has more flexibility on the structure, tasks and other code can be placed in different files and packages
-
Created tasks are not possible to be shared as part of Python package, or at least difficult and should not be
from argparse import ArgumentParser
from rkd.core.api.contract import ExecutionContext
from rkd.core.api.decorators import extends
from rkd.core.api.syntax import ExtendedTaskDeclaration
from rkd.core.standardlib.syntax import PythonSyntaxTask
@extends(PythonSyntaxTask)
def hello_task():
"""
Prints your name
"""
def configure_argparse(task: PythonSyntaxTask, parser: ArgumentParser):
parser.add_argument('--name', required=True, help='Allows to specify a name')
def execute(task: PythonSyntaxTask, ctx: ExecutionContext):
task.io().info_msg(f'Hello {ctx.get_arg("--name")}, I\'m talking in Python, and you?')
return True
return [configure_argparse, execute]
IMPORTS = [
ExtendedTaskDeclaration(hello_task, name=':hello2')
]
Classic Python ¶
-
Provides a full control without any limits on tasks extending
-
Has more flexibility on the structure, tasks and other code can be placed in different files and packages
-
Best fits for creating shareable tasks using local and remote Python packages
from argparse import ArgumentParser
from rkd.core.api.contract import TaskInterface, ExecutionContext
from rkd.core.api.syntax import TaskDeclaration
class HelloFromPythonTask(TaskInterface):
"""
Prints your name
"""
def get_name(self) -> str:
return ':hello3'
def get_group_name(self) -> str:
return ''
def configure_argparse(self, parser: ArgumentParser):
parser.add_argument('--name', required=True, help='Allows to specify a name')
def execute(self, ctx: ExecutionContext) -> bool:
self.io().info_msg(f'Hello {ctx.get_arg("--name")}, I\'m talking classic Python syntax, and you?')
return True
IMPORTS = [
TaskDeclaration(HelloFromPythonTask()),
]
Syntax reference ¶
Simplified Python |
Python Class |
YAML |
Description |
---|---|---|---|
get_steps(task: MultiStepLanguageAgnosticTask) -> List[str]: |
get_steps |
steps: [“”] |
List of steps in any language (only if extending MultiStep LanguageAgnosticTask) |
stdin() |
N/A |
input: “” |
Standard input text |
@extends(ClassName) decorator on a main method |
ClassName(BaseClass) |
extends: package.name.ClassName |
Which Base Task should be extended |
execute(task: BaseClassNameTask, ctx: ExecutionContext): |
execute(self, ctx: ExecutionContext) |
execute: “” |
Python code to execute |
inner_execute(task: BaseClassNameTask, ctx: ExecutionContext): |
inner_execute(self, ctx: ExecutionContext) |
inner_execute: “” |
Python code to execute inside inner_execute (if implemented by Base Task) |
compile(task: BaseClassNameTask, event: CompilationLifecycleEvent): |
compile(self, event: CompilationLifecycleEvent): |
N/A |
Python code to execute during Context compilation process |
configure(task: BaseClassNameTask, event: ConfigurationLifecycleEvent): |
configure(self, event: ConfigurationLifecycleEvent): |
configure: “” |
Python code to execute during Task configuration process |
get_description() |
get_description(self) |
description: “” |
Task description |
get_group_name() |
get_group_name() |
N/A |
Group name |
internal=True in TaskDeclaration |
internal=True in TaskDeclaration |
internal: False |
Is task considered internal? (hidden on :tasks list) |
become in TaskDeclaration (or commandline switch) |
become in TaskDeclaration (or commandline switch) |
become: root |
Change user for task execution time |
workdir in TaskDeclaration |
workdir in TaskDeclaration |
workdir: /some/path |
Change working directory for task execution time |
configure_argparse(task: BaseClassNameTask, parser: ArgumentParser) |
configure_argparse(self, parser: ArgumentParser) |
arguments: {} |
Configure argparse.ArgumentParser object |