跳转到主要内容

Python的静态代码提取器

项目描述

GitlabCIPipeline GitlabCICoverage ReadTheDocs Pypi Downloads

Github

https://gitlab.kitware.com/python/liberator

Pypi

https://pypi.ac.cn/project/liberator

ReadTheDocs

https://liberator.readthedocs.io/en/latest/

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 查看哈希值)

上传时间 Python 3

支持者