Compilation
The equipment compile command prepares a generated project for bytecode-based distribution. It compiles Python files to .pyc and copies runtime assets into an output directory.
Compilation is optional. Use it when you want a deployment directory that contains Python bytecode and runtime assets but excludes tests and source .py files.
Command
equipment compile dist
Run it from the generated project root.
What It Does
- Walks the current directory.
- Ignores
__pycache__,dist,tests,equipment, and the selected output directory. - Compiles
.pyfiles into.pycfiles under the output directory. - Copies runtime assets:
config,database,storage,.coveragerc,.editorconfig,.env,.env.example,.gitignore,pyproject.toml, andREADME.md.
The command is designed for generated projects. Run it from the generated project root, not from inside the equipment package repository unless you are intentionally testing the command.
Example
equipment compile dist
cd dist
python main.pyc
On Windows:
equipment compile dist
cd dist
py -3.14 main.pyc
Output Shape
dist/
├── app/
│ └── ... .pyc files
├── config/
├── database/
├── storage/
├── main.pyc
├── queues.pyc
├── scheduler.pyc
├── web.pyc
├── README.md
└── pyproject.toml
Tests and the vendored equipment package directory are intentionally excluded.
Included And Excluded Content
Included by default:
- compiled
.pycfiles for application Python files; config/;database/;storage/;.coveragerc;.editorconfig;.env;.env.example;.gitignore;pyproject.toml;README.md.
Excluded by default:
tests/;equipment/when present inside the generated project;__pycache__/;dist/;- the selected output directory;
- source
.pyfiles.
Deployment Checklist
After compiling:
cdinto the output directory.- Run
python main.pyc. - Run any deployment smoke script you maintain.
- Confirm config files and
.envvalues are appropriate for the target environment. - Confirm optional services such as Redis, database, and S3 are reachable.
If the target environment differs from your build environment, build with the Python version and operating system you intend to run where possible.
Cross-platform Notes
- Use
python main.pycon Unix and Windows whenpythonis on PATH. - Use
py -3.14 main.pycon Windows when selecting a specific interpreter. - Do not rely on executable file permissions in compiled output.
- Keep paths inside application code platform-safe with
pathliboros.path.
Limitations
- Bytecode is not a security boundary. Treat
.pycfiles as packaging convenience, not source protection. - Compiled output should be tested before deployment.
- Platform-specific bytecode should be built with the Python version and operating system you plan to run.
- The command does not bundle third-party dependencies into the output directory.
- The command does not replace proper packaging, containerization, or deployment automation.
Troubleshooting
ModuleNotFoundError in compiled output:
Install project dependencies in the runtime environment. The compile command copies your project runtime assets, not every dependency from the environment.
Config file missing:
Confirm the file is in one of the included runtime asset paths or copy it as part of your deployment process.
Compiled output includes stale files:
Delete the output directory before compiling again.
Compiled output runs locally but not on another machine:
Check Python version, operating system, architecture, installed dependencies, and environment variables.
Guidance
- Compile into a clean output directory such as
distorbuild/output. - Do not compile into the source root.
- Run
python main.pycfrom inside the output directory to verify imports and runtime assets. - Use
pathlibin project code so compiled projects behave consistently on Windows and Unix. - Keep compile validation in CI if bytecode deployment is part of your release process.