tasks
¶
此模块包含核心 Task
用于生成新任务的类和便利修饰符。
- class invoke.tasks.Call(task: Task, called_as: str | None = None, args: Tuple[str, ...] | None = None, kwargs: Dict[str, Any] | None = None)¶
表示调用/执行
Task
具有给定(Kw)个参数。类似于
partial
增加了一些功能(比如对内部任务的委托,以及可选的跟踪调用它的名称)。在 1.0 版本加入.
- __hash__ = None¶
- __init__(task: Task, called_as: str | None = None, args: Tuple[str, ...] | None = None, kwargs: Dict[str, Any] | None = None) None ¶
创建新的
Call
对象。
- __weakref__¶
对象的弱引用列表
- clone(into: Type[Call] | None = None, with_: Dict[str, Any] | None = None) Call ¶
返回此调用的独立副本。
在对任务执行进行参数化时很有用。
- 参数:
into -- 要生成的子类,而不是当前类。可选的。
with (dict) -- 创建新克隆时使用的其他关键字参数的词典;通常在克隆时使用
into
在基类顶部具有额外参数的子类。可选的。。。注::本词典用于.update()
原始对象的数据(从其clone_data
),因此在发生冲突时,with_
都会胜出。
在 1.0 版本加入.
在 1.1 版本发生变更: 添加了
with_
科瓦格。
- class invoke.tasks.Task(body: Callable, name: str | None = None, aliases: Iterable[str] = (), positional: Iterable[str] | None = None, optional: Iterable[str] = (), default: bool = False, auto_shortflags: bool = True, help: Dict[str, Any] | None = None, pre: List[str] | str | None = None, post: List[str] | str | None = None, autoprint: bool = False, iterable: Iterable[str] | None = None, incrementable: Iterable[str] | None = None)¶
表示可执行任务的核心对象及其参数规范。
在很大程度上,此对象是可能提供给的所有数据的交换所
@task
装饰品,如name
,aliases
,positional
等,它们显示为属性。此外,实例化从提供的
body
对象,如__doc__
,__name__
和__module__
,让它“看起来像是”body
就大多数意图和目的而言。在 1.0 版本加入.
- __call__(*args: Any, **kwargs: Any) T ¶
将self作为函数调用。
- __init__(body: Callable, name: str | None = None, aliases: Iterable[str] = (), positional: Iterable[str] | None = None, optional: Iterable[str] = (), default: bool = False, auto_shortflags: bool = True, help: Dict[str, Any] | None = None, pre: List[str] | str | None = None, post: List[str] | str | None = None, autoprint: bool = False, iterable: Iterable[str] | None = None, incrementable: Iterable[str] | None = None) None ¶
- __weakref__¶
对象的弱引用列表
- invoke.tasks.call(task: Task, *args: Any, **kwargs: Any) Call ¶
描述如何执行
Task
,通常带有预先提供的参数。适用于设置 pre/post task invocations 。实际上,它只是一个方便的包装器
Call
类,如果需要,可以直接使用它。例如,下面是两个类似生成的任务,它们都引用了
setup
预任务,没有内置参数值(因此不需要使用call
),以及切换布尔标志的一个::@task def setup(c, clean=False): if clean: c.run("rm -rf target") # ... setup things here ... c.run("tar czvf target.tgz target") @task(pre=[setup]) def build(c): c.run("build, accounting for leftover files...") @task(pre=[call(setup, clean=True)]) def clean_build(c): c.run("build, assuming clean slate...")
请参阅的构造函数文档
Call
有关详细信息-此函数的args
和kwargs
直接映射到与该方法中相同的参数。在 1.0 版本加入.
- invoke.tasks.task(*args: Any, **kwargs: Any) Callable ¶
将包装的可调用对象标记为有效的调用任务。
如果不需要指定额外的选项,则可以不带括号地调用。否则,括号形式中允许使用以下关键字参数:
name
:绑定到Collection
。有助于避免出现Python命名空间问题(即,当所需的CLI级别名称不能或不应该用作Python级别名称时)。aliases
: Specify one or more aliases for this task, allowing it to be invoked as multiple different names. For example, a task namedmytask
with a simple@task
wrapper may only be invoked as"mytask"
. Changing the decorator to be@task(aliases=['myothertask'])
allows invocation as"mytask"
or"myothertask"
.positional
:Iterable重写解析器的自动“没有缺省值的参数被视为位置”行为。如果是Arg名称列表,则除了在此迭代表中命名的参数外,没有其他Arg将被视为位置参数。(这意味着空列表将强制将所有参数作为显式标志给出。)optional
:参数名称可迭代,声明这些参数具有 optional values 。这样的论据可以作为价值评估选项(例如--my-arg=myvalue
,其中给出了任务"myvalue"
)或作为布尔标志 (--my-arg
,导致True
)。iterable
:参数名称的可迭代,将它们声明为 build iterable values 。incrementable
:参数名称的可迭代,将它们声明为 increment their values 。default
:指定此任务是否应为其集合的默认任务的布尔选项(即,如果给定集合自己的名称则调用。)auto_shortflags
:是否根据任务选项自动创建短标志;默认为True。help
:DICT将参数名称映射到它们的帮助字符串。将显示在--help
输出。对于包含下划线(默认情况下在CLI上转换为短划线)的参数,此处可以提供短划线或下划线版本。pre
,post
:每次执行包装的任务之前或之后执行的任务对象的列表。autoprint
:Boolean确定直接通过CLI调用时是否自动将此任务的返回值打印到标准输出。默认为False。klass
:要实例化/返回的类。默认为Task
。
如果给出了任何非关键字参数,则将它们作为
pre
为了方便起见,请使用Kwarg。)两者都给是错误的*args
和pre
同时。)在 1.0 版本加入.
在 1.1 版本发生变更: 添加了
klass
关键字参数。