Project Compilation
Equipment provides a built-in compile command that prepares your project for distribution by converting Python files into bytecode (.pyc) and packaging all necessary assets into a single directory.
Why Compile?
- Performance: Bytecode files skip the compilation step when executed, leading to faster startup times.
- Obfuscation: While not a security measure, bytecode is harder to read than source code, providing a basic level of protection for your logic.
- Clean Distribution: Compiling creates a dedicated
distfolder containing only what's needed to run the application, making deployment simpler.
Usage
Run the compile command followed by the target directory name.
# Compile the project into the 'dist' folder
equipment compile dist
How it Works
When you run the compile command, Equipment performs the following steps:
- Scans the Project: It identifies all files in your current directory while respecting a set of default ignore patterns (like
.git,venv,__pycache__, etc.). - Converts Python Files: Every
.pyfile is compiled into a.pycfile using thepy_compilemodule. The original.pyfiles are not included in the output. - Preserves Assets: All non-Python files (YAML, JSON, INI, SQL, TXT, etc.) are copied exactly as they are to the target directory.
- Maintains Structure: The directory hierarchy is perfectly preserved in the output directory.
Deployment
After compilation, the dist folder is ready to be deployed.
# Navigate to the compiled project
cd dist
# Run the application (no .py files needed!)
python main.pyc
Best Practices
- Compile before Release: Always use the
compilecommand before packaging your application for production. - Verify the Output: After compiling, run your tests or the main entry point within the
distfolder to ensure everything was copied correctly. - Keep it Clean: Avoid compiling directly into your main project directory. Always use a dedicated output folder like
distorbuild.