简单配置
mariobros的Python项目详细描述
mariobros是一个python模块,用于以类似makefile的方式配置Spotify-Luigi。
spotify luigi是一个python模块,它帮助您构建批处理作业的复杂管道。 它处理依赖解析、工作流管理、可视化等。 配置文件将称为mariofiles。
主分支状态:
编写mariofile
mariofile在几个部分中被构造,表示各种任务。
任务定义
任务定义的一个例子是:
[task_name] target: source1 source2 source3 task_command
任务名称在方括号中定义。目标和源被两点分割。 下面一行是task命令。 在task_命令中,可以使用${TARGET}和${SOURCES[i]}调用目标名称和源名称,其中i 是索引或python切片。 在大括号中,您可以使用上面定义的变量执行python代码。 可以使用python正则表达式语法将目标名称的部分与源名称的部分匹配。 例如:
[task_name] (*.)-(*.)-(*.).txt: \1.txt \2.txt \3.txt task_command --output ${TARGET} --first-input ${SOURCES[0]} --other-inputs ${SOURCES[1:]}
此任务将first-second-third.txt等目标与名为first.txt、second.txt和third.txt的3个源文件匹配。 \1表示第一个匹配,\2表示第二个匹配,\3表示第三个匹配。
您还可以定义任务变量并在下面使用它们。您必须在任务名称下面定义它们,如下所示:
[task_name] variable1 = value1 variable2 = value2 target: source task_command -o ${TARGET} -i ${SOURCES} --par1 ${variable1} --par2 ${variable2}
默认部分
默认部分是在文件顶部定义的,不指定名称。在本节中有全局变量的定义 以及默认任务的定义。未请求其他任务时执行默认任务:
global_variable1 = value1 global_variable2 = value2 default_target: source1 source2 default_task_command
在文件顶部,您可以使用以下方式将其他mariofile包含在路径中:
include mariofile_path.ini
包含的mariofile的全局变量将添加到mariofile的顶部。 包含mariofile的任务将添加到mariofile的末尾。 如果存在同名的变量或任务,则只包含顶级变量或任务。
总之,典型的mariofile将如下所示:
include included_mariofile.ini global_var1 = value1 global_var2 = value2 (*.)-main_target.out: \1-\1-task1 default_task -o ${SOURCES} -i ${TARGET} [task_1] RESOURCES_CPU = 4 (*.)-(*.)-task1: source1 source2 task_1 -o ${TARGET} -i ${SOURCES} -j ${RESOURCES_CPU}
执行mario
mario命令行是:
$ mario --help Usage: mario [OPTIONS] [TARGETS]... Options: -f, --file, --mariofile PATH Main configuration file --workers INTEGER Set the number of workers --local-scheduler Run local scheduler. --print-ns Print namespaces: Print the MarioFile with the included tasks and variables -n, --dry-run Don't actually run any commands; just print them. --help Show this message and exit.
使用:
- All the mario options and arguments are optional.
- The default task request is ^{tt11}$.
- The default mariofile is ^{tt12}$.
- With ^{tt13}$ flag it print the whole MarioFile with the included tasks and variables.
- With ^{tt14}$ flag it doesn’t actually run any commands; just print them.
使用外部调度程序
首先,您必须运行luigid:
$ luigid
然后可以使用上面描述的命令行运行mario脚本:
$ mario
这样,mario将以mario.ini作为mariofile执行默认目标。 您还可以使用与mario.ini不同的mariofile请求特定目标,如下所示:
$ mario -f my_mariofile.ini target.out
您可以在localhost:8082地址中可视化调度程序。 将有一个任务列表和一个处理的树状图。
本地调度器
如果不需要可视化调度程序,则可以运行mario,而不运行luigid,本地调度程序如下:
$ mario --local-scheduler
Luigi配置文件
luigi可以存储处理的统计信息并管理资源。 必须配置luigi写入client.cfg文件,然后从client.cfg目录启动luigid。
在数据库中写入统计信息
在client.cfg文件中,可以为统计信息配置数据库路径。client.cfg的一个例子是:
[scheduler] record_task_history = True state_path = /path/to/luigi-state.pickle [task_history] db_connection = sqlite:////path/to/db/luigi-task-hist.db
资源管理
您还可以为单个任务指定所需的资源。
必须在定义[resources]部分的client.cfg文件中定义可用资源,如下所示:
[resources] cpus = 64
您可以为设置本地任务变量的单个任务指定所需的资源RESOURCES_RESOURCE_NAME 其中RESOURCE_NAME是在client.cfg中定义的资源的名称,例如:
[task_name] RESOURCES_cpus = 4 target: sources task_command -j ${RESOURCES_cpus}
对于^{tt24},请求资源是4。$是的。
安装
在当前python环境中安装:
pip install mariobros