一个简单的任务执行者。

dut的Python项目详细描述


职责

cidocumentationpypi version

一个简单的任务执行者。在

灵感来自Invoke。在

demo

要求

职责要求Python3.6或更高版本。在

<详细信息>要安装python3.6,我建议使用^{}
# install pyenv
git clone https://github.com/pyenv/pyenv ~/.pyenv

# setup pyenv (you should also put these three lines in .bashrc or similar)exportPATH="${HOME}/.pyenv/bin:${PATH}"exportPYENV_ROOT="${HOME}/.pyenv"eval"$(pyenv init -)"# install Python 3.6
pyenv install 3.6.12

# make it available globally
pyenv global system 3.6.12

安装

使用pip

^{pr2}$

使用^{}

python3.6 -m pip install --user pipx

pipx install --python python3.6 duty

快速入门

将很快提供适当的文档页。在

配置

在存储库的根目录下创建一个duties.py文件。在

使用duty.duty修饰符将每个任务声明为“职责”。在

fromdutyimportduty@dutydefdocs(ctx):ctx.run("mkdocs build",title="Building documentation")

ctx参数是职责的“上下文”。 它会自动创建并传递给您的函数。在

它只有一个用途:用它的run方法运行命令。 run方法接受字符串、字符串列表,甚至Python可调用项。在

上述责任可改写为:

fromdutyimportduty@dutydefdocs(ctx):ctx.run(["mkdocs","build"],title="Building documentation")# avoid the overhead of an extra shell process

或者:

fromdutyimportdutyfrommkdocsimportbuild,config@dutydefdocs(ctx):ctx.run(build.build,args=[config.load_config()],title="Building documentation")# avoid the overhead of an extra Python process

run方法接受各种选项, 主要来自于其潜在的依赖性: ^{}。在

run方法的参数:

NameTypeDescriptionDefault
cmd^{}, ^{}, or Python callableThe command to run.required
args^{}Arguments to pass to the callable.^{}
kwargs^{}Keyword arguments to pass to the callable.^{}
number^{}The command number (useful for the ^{} format).^{}
output_type^{}The type of output: ^{}, ^{}, ^{} or ^{}^{}
title^{}The command title.cmd as a shell command or Python statement
fmt^{}The output format as a Jinja template: ^{}, ^{} or ^{}^{}
pty^{}Whether to run in a PTY.^{}
progress^{}Whether to show progress.^{}
nofail^{}Whether to always succeed.^{}
quiet^{}Don't print the command output, even if it failed.^{}
silent^{}Don't print anything.^{}

silent选项的用法示例:

@dutydefclean(ctx):ctx.run("find . -type d -name __pycache__ | xargs rm -rf",silent=True)

现在假设你有一个以上的命令,你想让所有命令静音:

@duty(silent=True)defclean(ctx):ctx.run("rm -rf .coverage*")ctx.run("rm -rf .mypy_cache")ctx.run("rm -rf .pytest_cache")ctx.run("rm -rf build")ctx.run("rm -rf dist")ctx.run("rm -rf pip-wheel-metadata")ctx.run("rm -rf site")ctx.run("find . -type d -name __pycache__ | xargs rm -rf")ctx.run("find . -name '*.rej' -delete")

运行

要执行任务,只需使用:

duty clean

如果您正在使用Poetry

poetry run duty clean

您可以在一个命令中传递多个职责:

duty clean docs

如果你的职责之一接受争论, 也可以在命令行上传递它们:

@dutydefdocs(ctx,serve=False):command="serve"ifserveelse"build"ctx.run(f"mkdocs {command}")
duty docs serve=1

!!!笔记 请注意,参数不是类型强制转换的: 他们总是被认为是职责的附加条件。在

托多

  • 更好地处理缺失职责的争论。 可能只需打印错误而不进行回溯: release() missing 1 required positional argument: 'version'
  • 参数类型转换,最好基于类型注释!在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何通过解决错误“活动无法转换为片段”将片段传递给类构造函数?   Java中清理Code39条码数据的regex帮助   将java转换为C++   java无法在Android Studio中生成签名的apk,出现错误   从数学方程出发   MySQL和Java内存问题   如何强制Java抛出算术异常?   java为什么JDBC将零端口视为空(默认)端口?   java如何在没有“changelog主题”的情况下加入KStream和KTable   排序我尝试合并两个排序的数组,但得到的是java。lang.ArrayIndexOutofBounds异常:5无法找出原因   如何在java中求大长度矩阵的逆?   基于maven构建的java生成类路径字符串   java每20个字符分割一个字符串,然后将每个部分打印到控制台   将字符串数字字转换为字符串数字:Java   在特定区域使用混合类型的java填充字节数组   尽管java类在开关块中实例化,但它只能调用接口方法