Python的静态代码提取器
项目描述
Github |
|
Pypi |
|
ReadTheDocs |
Liberator是一个Python库,可以将(即静态提取)类/函数源代码从现有的Python库中提取到一个单独的独立模块中。
它通过静态解析代码以获取类/函数定义,然后递归解析和提取所有缺失的依赖项。
以下是一个示例。假设您想使用find_exe函数从ubelt,但您不想依赖于ubelt本身,您可以通过以下方式提取定义find_exe函数所需的最小代码到一个新的独立模块中
# Create a Liberator instance to manage construction of
# the new standalone code.
from liberator.core import Liberator
lib = Liberator()
# Pass the liberator object the function you want to expose
# You can add more than one function this way.
import ubelt as ub
lib.add_dynamic(ub.find_exe)
# Tell liberator about the library that you dont want to depend on,
# any (statically findable) external references to that library will be
# vendored into the new liberated code.
lib.expand(['ubelt'])
# Finally access the "current source code" which will
# have the self-contained version of the "liberated" utility.
print(lib.current_sourcecode())
限制
Liberator 存在一些限制。它只能在代码以静态方式表达时工作(即没有注册方法到列表以供将来注入的装饰器)。它不做任何评估工作,只是查看函数定义并直接引用。它也没有进行任何混淆操作以解决具有相同名称的不同函数(尽管它可以,这也是我希望添加的一个扩展)。最后,它只能“扩展”代码顶层导入的包。嵌套导入不会被“解放”。这又是一个可以实现的扩展,但目前还没有实现。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪一个,请了解有关安装包的更多信息。
源代码分发
此版本没有提供源代码分发文件。请参阅生成分发存档的教程。
构建的分发
liberator-0.1.1-py3-none-any.whl (26.9 kB 查看哈希值)
关闭
liberator-0.1.1-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 75d9faf87b6e5e8a0285853097fd5643823d59c84ed143b9be96d948bbe12b9a |
|
MD5 | 02ebb6dd926fe4bf2cd7ed6b0f7a7dea |
|
BLAKE2b-256 | fcc1eae54ed45772538913ac182095044f4564b6ce0d70ed2b6eb462fae19d29 |