loader

class invoke.loader.Loader(config: Config | None = None)

定义如何查找/导入会话基的抽象类 Collection .

在 1.0 版本加入.

__init__(config: Config | None = None) None

设置一个新的加载器 Config

参数:

config -- 一个显式的 Config 使用;它被引用用于与加载相关的配置选项。默认为匿名 Config() 如果没有给予的话。

find(name: str) ModuleSpec | None

特定于实现的查找器方法,用于查找集合 name

Must return a ModuleSpec valid for use by importlib, which is typically a name string followed by the contents of the 3-tuple returned by importlib.module_from_spec (name, loader, origin.)

有关示例实现,请参见 FilesystemLoader

在 1.0 版本加入.

load(name: str | None = None) Tuple[module, str]

由标识的加载和返回收集模块 name

此方法需要一个有效的 find 才能发挥作用。

除了导入命名模块外,它还会将该模块的父目录添加到 sys.path 提供正常的Python导入行为(即,加载的模块可以加载本地到它的模块或包)。

返回:

两个元组 (module, directory) 哪里 module 是包含集合的Python模块对象,并且 directory 是找到模块的目录的字符串路径。

在 1.0 版本加入.

class invoke.loader.FilesystemLoader(start: str | None = None, **kwargs: Any)

从文件系统加载python文件(例如 tasks.py

从给定的起点递归搜索文件系统根目录。

在 1.0 版本加入.

__init__(start: str | None = None, **kwargs: Any) None

设置一个新的加载器 Config

参数:

config -- 一个显式的 Config 使用;它被引用用于与加载相关的配置选项。默认为匿名 Config() 如果没有给予的话。

find(name: str) ModuleSpec | None

特定于实现的查找器方法,用于查找集合 name

Must return a ModuleSpec valid for use by importlib, which is typically a name string followed by the contents of the 3-tuple returned by importlib.module_from_spec (name, loader, origin.)

有关示例实现,请参见 FilesystemLoader

在 1.0 版本加入.