增强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
,这降低了跳过的测试数量。
许可证
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定要选择哪个,请了解更多关于 安装包 的信息。
源分发
compileall2-0.8.0.tar.gz (9.5 kB 查看哈希值)
构建分发
compileall2-0.8.0-py3-none-any.whl (9.8 kB 查看哈希值)
关闭
compileall2-0.8.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | c976d99ea6af04482c87b434f8b10ce21fccc7e95a8e63792c0895677f6f48e3 |
|
MD5 | 28b1334827a5ba1368e748e84753484a |
|
BLAKE2b-256 | 20e5fdcf30add058a32eb12a9ae351f7aae0bfadb4bd1e313413f1c25c96e8ca |
关闭
compileall2-0.8.0-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 730b7b02502ed196a3fb13d5db975af27b3437444c9ad9347c02947ca8c0aeb3 |
|
MD5 | c7cacd5207e37aaf5651b052ea290317 |
|
BLAKE2b-256 | 11ebecff38add2e89a09bf51afa1407c270e311b71443af5e7ed7204331f9649 |