一个受npm脚本启发的小任务运行器。
pyxcute的Python项目详细描述
一个受npm脚本启发的小任务运行器。
功能
- 像setuptools一样使用它。
- 使用_pre,_err,_post,_fin后缀链接任务。
- 一个内置的bump任务,可以用semver来bump版本。
- 一组跨平台的小程序。
用法
基本
创建一个cute.py文件:
fromxcuteimportcutecute(hello='echo hello xcute!')
然后运行:
$ cute hello
> Task: hello
> Cmd: echo hello xcute!
hello xcute!
If you got a “not a command” error, see How do I make Python scripts executable?)
“hello”是应该执行的任务的名称。如果cute.py在没有任务名的情况下执行,它将运行“默认”任务。
提供其他参数:
$ cute hello 123 > Task: hello > Cmd: echo hello xcute! 123 hello xcute! 123
参数将传递给执行器,在本例中是xcute.Cmd.__call__。
任务
它可以是str:
fromxcuteimportcutecute(hello='echo hello')
如果与另一个任务的名称匹配,pyxcute将执行该任务:
fromxcuteimportcutecute(hello='world',# execute "world" task when "hello" task is executedworld='echo I am world task')
使用列表:
fromxcuteimportcutecute(hello=['echo task1','echo task2'])
使用异常将使任务失败:
fromxcuteimportcutecute(hello=Exception("error message"))
使用任何可调用的内容:
fromxcuteimportcutecute(hello=lambda:print('say hello'))
实际上,当您将不可调用的值指定为任务时,pyxcute会根据其类型将其转换为可调用的值。
任务链
用_pre,_err,_post,_fin后缀定义工作流:
fromxcuteimportcutecute(hello_pre='echo _pre runs before the task',hello='echo say hello',hello_err='echo _err runs if there is an error in task, i.e, an uncaught exception or non-zero return code',hello_post='echo _post runs after the task if task successfully returned',hello_fin='echo _fin always runs after _post, _err just like finally')
当任务执行时,任务运行器首先尝试执行_pre任务,然后是任务本身,然后是_post任务。如果任务引发异常,则它将转到_err任务。_fin无论任务是否失败,都将执行任务。
伪代码:
run(name+"_pre")try:run(name,args)exceptException:run(name+"_err")else:run(name+"_post")finally:run(name+"_fin")
格式字符串
pyxcute使用xcute.conf字典扩展命令字符串。扩展在运行时发生:
fromxcuteimportconf,cuteconf["my_name"]="world"defchange_my_name():conf["my_name"]="bad world"cute(hello=["echo hello {my_name}",change_my_name,"echo hello {my_name}"])
$ cute hello > Task: hello > Cmd: echo hello world hello world > Cmd: echo hello bad world hello bad world
实例
检查pyxcute本身的the cute file。
更改日志
- 0.5.2(2018年6月14日)
- 添加:在Bump中支持bumper参数。
- 添加:支持Python3.4。删除subprocess32。
- 0.5.1(2018年5月12日)
- 添加:conf["py"]变量。
- 0.5.0(2018年5月11日)
- 添加:支持python 2。
- 添加:文档。
- 添加:Skip,run_task,task_converter。
- add:`bump`任务现在更新'setup.cfg'中的版本号。
- 修复:由于shell=True并将args作为列表传递,在UNIX上,Cmd任务失败。
- change:`cmd'的命令现在已被记录。日志消息也已更改。
- drop:`noop`.
- 0.4.1(2017年4月3日)
- 更好地描述x-clean。
- 修复X-Pipe中的断管错误。
- 0.4.0(2017年3月28日)
- 切换到setup.cfg。
- 添加日志,exc,noop,throw,try。
{STR 1 } $ EXC退出,< /强> - 添加x-*utils。
- 从{pkg_name}/__pkginfo__.py中查找版本。
- 添加pkg_name任务。
- 添加默认任务bump,version。
- 添加表示finally子句的_fin标记。
- 将pre移出try子句。
- bump dev状态。
- 第一次释放。