compile_to_pyc.sh is a shell utility for compiling all .py files in a specified source directory into .pyc bytecode files. It preserves the original directory structure and excludes all source .py files and __pycache__ folders from the output.
- Compiles
.pyfiles to.pycusing Python'scompileallmodule - Preserves the original directory hierarchy
- Outputs compiled files to a specified directory
- Skips
.pysource files and__pycache__folders - Can be installed system-wide as the
compile_pycommand - Supports
--source,--output, and--helpflags
git clone https://github.com/horhe-dvlp/python-module-compiler.git
cd python-module-compilersudo install -m 755 compile_to_pyc.sh /usr/local/bin/compile_pyThis will make the compile_py command available globally.
sudo rm /usr/local/bin/compile_pycompile_py --source <path/to/source> [--output <path/to/output>]Compile .py files in ./src and store the output in ./src_compiled:
compile_py --source ./srcSpecify a custom output directory:
compile_py --source ./src --output ./build/compiledShow help:
compile_py --help| Argument | Description |
|---|---|
--source |
(Required) Path to the directory containing .py files |
--output |
(Optional) Output directory for .pyc files (default: <source>_compiled) |
--help, -h |
Show usage information |
Input:
src/
└── module/
├── __init__.py
└── utils.py
Output:
src_compiled/
└── module/
├── __init__.pyc
└── utils.pyc
bash(POSIX-compatible shell)python3(with standardcompileallmodule)
MIT License