A base template project providing reproducible Python execution environments via two independent methods:
- Bare metal -
shell/run.shruns directly on the local machine - Containerized -
shell/run_docker.shbuilds, maintains, and runs a Docker container that executesshell/run.sh
The python/main.py entry point is a placeholder — replace it with production code. This project is intended as a base for other Python projects.
python-wrapper/
├── Dockerfile # Docker image definition
├── requirements.txt # Python dependencies (empty by default)
├── configuration/
│ ├── environment.properties # Configuration / environment variables
│ └── README.md # Environment variable documentation
├── python/
│ └── main.py # Python application entry point
└── shell/
├── run.sh # Core bare-metal execution script
├── run_docker.sh # Docker orchestration script
├── build_image.sh # Docker image build script
├── helpers.sh # Shared helper functions (repo root, env sourcing, SHA, venv path)
├── pre_run.sh # Pre-execution hook (placeholder)
└── post_run.sh # Post-execution hook (placeholder)
- Dependency hashing — SHA-256 hash of
requirements.txt(first 16 chars) is appended to the venv directory name (e.g.py_venv_a1b2c3d4e5f6g7h8). When requirements change, a new venv is created automatically. SHA calculation is portable across Linux (sha256sum), macOS (shasum), and any system withopenssl. - Smart rebuilds — Docker images only rebuild when the git HEAD changes, the image is missing, or
FORCE_DOCKER_REBUILD=TRUE. Venvs only rebuild when requirements change orFORCE_VENV_REBUILD=TRUE. - Pre/post hooks —
shell/pre_run.shandshell/post_run.shrun before and afterpython/main.pyfor custom setup/teardown logic. - Configurable logging — Console and optional file logging via
LOG_LEVELandLOG_LOCATIONenvironment variables.
- Validate
dockeris installed - Source environment variables from
configuration/environment.properties - Calculate
requirements.txtSHA-256 hash for venv versioning - Determine if rebuild is needed:
- Docker image does not exist
- Repository HEAD has changed (new git commit)
FORCE_DOCKER_REBUILDis set toTRUE
- If rebuild needed → execute
shell/build_image.sh:- Source environment variables
- Deactivate and delete any existing bare-metal venv
- Pull latest
python:latestimage (ifAUTO_UPDATE=TRUE) - Remove old Docker image
- Build new Docker image
- Otherwise → delete any existing bare-metal venv to prevent conflicts
- Run disposable container → executes
shell/run.shinside container
- Determine repository root (via
gitor script path fallback) - Source environment variables from
configuration/environment.properties - Execute
shell/pre_run.sh - Calculate
requirements.txtSHA-256 hash and derive venv name - Create/activate Python venv (or reuse existing if hash matches and
FORCE_VENV_REBUILD != TRUE) - Install/upgrade pip and packages from
requirements.txt - Optionally refreeze requirements (if
REFREEZE_REQUIREMENTS=TRUE) - Execute
python/main.pywith any command-line arguments - Execute
shell/post_run.sh
Environment variables are defined in configuration/environment.properties. See configuration/README.md for full documentation.
| Variable | Description | Default |
|---|---|---|
PYVENV_LOCATION |
Base name for the Python venv directory (hash appended) | py_venv |
LOG_LEVEL |
Python logging verbosity | INFO |
LOG_LOCATION |
Path to log file (omit for console-only) | (unset) |
REFREEZE_REQUIREMENTS |
Overwrite requirements.txt with current pip freeze |
FALSE |
DOCKER_NAME |
Docker image name | python-wrapper |
FORCE_DOCKER_REBUILD |
Force Docker image rebuild on every run | TRUE |
FORCE_VENV_REBUILD |
Force venv rebuild on every run | TRUE |
AUTO_UPDATE |
Pull latest Python Docker image before builds | TRUE |