跳转到主要内容

增强Python `compileall`模块

项目描述

compileall2 Python模块

CPython源代码的compileall模块的副本,具有一些新特性,即

  • 与Python >= 3.6及PyPy 3兼容

以下特性首先在本项目中实现,然后包含到CPython标准库中。

  • 默认递归限制现在是“无限”(实际上受sys.getrecursionlimit()限制)

  • 使用-s-p命令行选项操作编译到*.pyc文件中的路径。

  • 可以使用多次指定-o命令行选项,以一次运行中编译多个优化级别

  • 使用-e命令行选项忽略指向特定目录外部的符号链接

  • 使用--hardlink-dupes命令行选项在具有相同内容的.pyc文件之间创建硬链接

安装

  • PyPI 通过 pip install compileall2 安装

  • 在 Fedora Linux 中,compileall2.py 是 python-srpm-macros RPM 软件包的一部分。

使用方法

compileall2 可以作为 Python 模块执行或直接执行。

示例用法

# Create some script (this one raises an exception to show tracebacks)
$ echo "1 / 0" > test.py

# Compile it
$ compileall2 test.py
Compiling 'test.py'...

# Try to execute compiled version directly
$ python __pycache__/test.cpython-37.pyc 
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    1 / 0
ZeroDivisionError: division by zero

# Recompile it with changes path which will be visible in error message
$ compileall2 -f -p /foo/bar test.py
Compiling 'test.py'...
$ python __pycache__/test.cpython-37.pyc
Traceback (most recent call last):
  File "/foo/bar/test.py", line 1, in <module>
ZeroDivisionError: division by zero

# Same thing as above but executed as a Python module
$ python -m compileall2 -f -p /bar/baz test.py
Compiling 'test.py'...
$ python __pycache__/test.cpython-37.pyc
Traceback (most recent call last):
  File "/bar/baz/test.py", line 1, in <module>
ZeroDivisionError: division by zero

测试

您可以使用 tox 或 unittest 直接在本地测试它

$ python3 -m unittest test_compileall2.py
..............sss....ss.......................sss....ss.....................ss.............................----------------------------------------------------------------------
Ran 107 tests in 3.714s

OK (skipped=12)

但在容器中运行可能更好,因为超级用户有权限写入 sys.path,这降低了跳过的测试数量。

许可证

PSF 许可证 v2

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定要选择哪个,请了解更多关于 安装包 的信息。

源分发

compileall2-0.8.0.tar.gz (9.5 kB 查看哈希值)

上传时间

构建分发

compileall2-0.8.0-py3-none-any.whl (9.8 kB 查看哈希值)

上传时间 Python 3

由以下组织支持