You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lrpyopsr/source_code_learning

25 lines
908 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# Python Fire可以做什么
这是一个通过暴露复杂系统内部接口利用管道和CLI来方便测试的工具。
它可以自动扫描module, object, class, function并自动构建管道
Expose functionality to user by archive them in a function / module / object / class / dict
# Python fire 源码分析:
## __main__.py
主要负责import被使用的module或者file将其导入Fire.fire()函数。
## core.py
原型Fire(component=None, command=None, name=None).
fire的一般执行过程如下
1. 从参数列表pop一个参数
1. 根据参数的类型
1. 实例化被使用的class
2. 或者调用命令所指向的function
3. 或者查找命令指向的属性
1. 返回步骤1
当不再能够继续执行时fire将结果序列化后输出
我们可以注意到其比较核心的功能需要用到静态代码分析、反射、模式匹配