加载模块

mohand.load_file.find_handfile(names=None)[源代码]

尝试定位 handfile 文件,明确指定或逐级搜索父路径

参数:names (str) – 可选,待查找的文件名,主要用于调试,默认使用终端传入的配置
返回:handfile 文件所在的绝对路径,默认为 None
返回类型:str
mohand.load_file.get_commands_from_module(imported)[源代码]

从传入的 imported 中获取所有 click.core.Command

参数:imported (module) – 导入的Python包
返回:包描述文档,仅含终端命令函数的对象字典
返回类型:(str, dict(str, object))
mohand.load_file.is_command_object(obj)[源代码]

验证传入的 obj 是否为一个 CLI 命令对象

参数:obj (object) – 待判断对象
返回:是否为 click.core.Command 命令对象
返回类型:bool
mohand.load_file.extract_commands(imported_vars)[源代码]

从传入的变量列表中提取命令( click.core.Command )对象

参数:imported_vars (dict_items) – 字典的键值条目列表
返回:判定为终端命令的对象字典
返回类型:dict(str, object)
mohand.load_file.load_handfile(path, importer=None)[源代码]

导入传入的 handfile 文件路径,并返回(docstring, callables)

也就是 handfile 包的 __doc__ 属性 (字符串) 和一个 {'name': callable} 的字典,包含所有通过 mohand 的 command 测试的 callables

参数:
  • path (str) – 待导入的 handfile 文件路径
  • importer (function) – 可选,包导入函数,默认为 __import__
返回:

包描述文档,仅含终端命令函数的对象字典

返回类型:

(str, dict(str, object))