增强的python“compileall”模块
compileall2的Python项目详细描述
CompileAll2 Python模块
cpython源代码中compileall
模块的副本,具有一些新功能,即:
与python的兼容性=3.4&pypy 3
默认递归限制现在是“unlimited”(实际上由
sys.getrecursionlimit()
限制)-s
和-p
用于操作烘焙到的路径的命令行选项 编译的*.pyc
文件。可以多次指定
-o
命令行选项来编译 一次运行多个优化级别
安装
从PyPI到
pip install compileall2
RPM将在Fedora COPR
用法
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
完成
启动项目:)
☆使上游试验运行
使
compileall2
与cpythons兼容:- 3.8∏
- 3.7∏
- 3.6∏
- 3.5∏
- 3.4∏
☆使
compileall2
与pypy 3兼容去除上面提到的
最大深度限制☆添加从编译文件中删除原始文件路径的某些部分的可能性
☆发布到pypi
☆在Fedora Copr中提供
待办事项
[下一步]使用copr中的python包测试它
将其推到Fedora Rawhide
使用所有python包在fedora基础结构中测试它
是吗?为上游cpython准备修补程序
测试
您可以在本地使用tox或unittest直接进行检测:
$ python3 -m unittest test_compileall_original.py ............sss.......................sss.....................ss................. ---------------------------------------------------------------------- Ran 81 tests in 2.137s OK (skipped=8)
但是,在Docker容器中运行可能更好,因为超级用户有权写入sys.path
,这样可以减少跳过的测试数。
您可以只构建准备好的版本:
$ docker build -t compileall2 . Sending build context to Docker daemon 177.2 kB Step 1/3 : FROM frenzymadness/fedora-python-tox:latest ---> 00f92ad0e1d3 ... etc ...
并在其中运行测试:
$ docker run --rm -it -e TOXENV=py37 -v $PWD:/src:Z -w /src compileall2 py37 create: /src/.tox/py37 py37 installdeps: pytest py37 installed: atomicwrites==1.3.0,attrs==19.1.0,more-itertools==6.0.0,pluggy==0.9.0,py==1.8.0,pytest==4.3.1,six==1.12.0 py37 run-test-pre: PYTHONHASHSEED='519909491' py37 runtests: commands[0]| pytest -v -s ==========================================test session starts========================================== platform linux -- Python 3.7.2, pytest-4.3.1, py-1.8.0, pluggy-0.9.0 -- /src/.tox/py37/bin/python cachedir: .tox/py37/.pytest_cache rootdir: /src, inifile: collected 81 items test_compileall_original.py::CompileallTestsWithSourceEpoch::test_compile_dir_pathlike PASSED test_compileall_original.py::CompileallTestsWithSourceEpoch::test_compile_file_pathlike PASSED test_compileall_original.py::CompileallTestsWithSourceEpoch::test_compile_file_pathlike_ddir PASSED ... etc ... =================================79 passed, 2 skipped in 5.15 seconds================================== ________________________________________________ summary ________________________________________________ py37: commands succeeded congratulations :)