Skip to main content

compileall2 Python module

Copy of compileall module from CPython source code with some new features, namely:

  • compatibility with Python >= 3.6 & PyPy 3

The following features were first implemented in this project and then included into the standard libraty of CPython.

  • default recursion limit is now "unlimited" (actually limited by sys.getrecursionlimit())

  • -s and -p command line options for manipulation of the path baked into a compiled *.pyc file.

  • the -o command line option can be specified multiple times to compile for multiple optimization levels in one run

  • the -e command line option for ignoring symlinks pointing outside a specific directory

  • the --hardlink-dupes command line option which creates hardlinks between .pyc files with the same content

Installation

  • From PyPI via pip install compileall2

  • In Fedora Linux, compileall2.py is a part of python-srpm-macros RPM package.

Usage

compileall2 can be executed as a Python module or directly.

Example usage:

# 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

Testing

You can test it locally with tox or unittest directly:

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

OK (skipped=12)

but running in a container might be better because the superuser has privileges to write to sys.path which lowers the number of skipped tests.

License

PSF license v2

Release files for compileall2 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for compileall2 0.8.0
File Size Uploaded
compileall2-0.8.0.tar.gz 9.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for compileall2 0.8.0
File Interpreter ABI Platform
compileall2-0.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.3 kB

Release files / compileall2-0.8.0.tar.gz

Download URL compileall2-0.8.0.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c976d99ea6af04482c87b434f8b10ce21fccc7e95a8e63792c0895677f6f48e3
BLAKE2b-256 checksum
How to use checksums
20e5fdcf30add058a32eb12a9ae351f7aae0bfadb4bd1e313413f1c25c96e8ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.12.2

Release files / compileall2-0.8.0-py3-none-any.whl

Download URL compileall2-0.8.0-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
730b7b02502ed196a3fb13d5db975af27b3437444c9ad9347c02947ca8c0aeb3
BLAKE2b-256 checksum
How to use checksums
11ebecff38add2e89a09bf51afa1407c270e311b71443af5e7ed7204331f9649
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.8.0 This release

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page