增强的python“compileall”模块

compileall2的Python项目详细描述


CompileAll2 Python模块

cpython源代码中compileall模块的副本,具有一些新功能,即:

  • 与python的兼容性=3.4&pypy 3

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

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

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

安装

用法

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 :)

许可证

PSF license v2

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为引用变量指定默认值   java在2D数组中旋转innersquare   java将hashmap键值与int进行比较   java程序中的并发监视器陷入死锁   安卓 java。lang.NoClassDefFoundError:java。awt。光标   java有没有更好的方法来引用包含对象的对象?   如何在Java编程中循环代码块   java如何在Junit5中使用Serenity?   java使用ANTLR识别JavaScript文件中的全局变量声明   EJB查询对象生成的java视图SQL?   java查找股票报价的范围   java错误:(453,69)不允许使用字符串类型(在值为“”的“活动\u水平\u边距”处)   java安装的环境变量   amazon web服务在使用awssdkjava上载到S3存储桶时发生直接错误   java在Android的ArrayList中添加相等的值   尝试打开MyEclipse Enterprise Workbench时出现ide“无法创建java虚拟机”错误   java如何使用单元格指定的行和列更改jTable的单元格颜色?   java如何等待文件从系统目录复制到具有根访问权限的外部存储