Here's a bash script that creates a Pijul repository with a base version of a Python script and three independent patches, each representing a different "aspect" (error handling, observability, caching), each applied against the original base, not the previous patches.
✅ Key Features:
- Each patch is based on the base version, not on previous patches.
- No additive behavior — each aspect is a standalone patch.
- You can apply or remove any patch independently without affecting others.
- All patches are in the same repository, but they are not interdependent.
🧪 Script: create_aspect_repo.sh
#!/usr/bin/env bash
set -euo pipefail
# Directory for the demo
REPO_DIR="demo_pijul_aspects"
[[ -d "$REPO_DIR" ]] && { echo "Removing old $REPO_DIR"; rm -rf "$REPO_DIR"; }
mkdir "$REPO_DIR"
cd "$REPO_DIR"
# Initialize Pijul repo
echo "==> Initializing Pijul repository..."
pijul init
# Base code (as a variable)
BASE_CODE=$(cat <<'PY'
def compute(x: int) -> int:
"""Happy-path computation: double the input."""
return x * 2
if __name__ == "__main__":
result = compute(5)
print(f"Result: {result}")
PY
)
# 0. Base patch
echo "==> Adding base code..."
echo "$BASE_CODE" > main.py
pijul add main.py
pijul record -am "Base: happy-path source"
# 1. Aspect: Error Handling
echo "==> Creating error handling patch (based on base)..."
echo "$BASE_CODE" > main.py
cat >> main.py <<'PY'
try:
result = compute(5)
print(f"Result: {result}")
except Exception as e:
print(f"[ERROR] {e}")
import sys
sys.exit(1)
PY
pijul add main.py
pijul record -am "Aspect: error handling"
# 2. Aspect: Observability (logging)
echo "==> Creating observability patch (based on base)..."
echo "$BASE_CODE" > main.py
cat >> main.py <<'PY'
import logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
)
def compute(x: int) -> int:
"""Happy-path computation: double the input."""
logging.info("compute called with x=%s", x)
return x * 2
if __name__ == "__main__":
try:
logging.info("Application start")
result = compute(5)
logging.info("Computation finished: result=%s", result)
print(f"Result: {result}")
except Exception as e:
logging.exception("Unhandled error")
import sys
sys.exit(1)
PY
pijul add main.py
pijul record -am "Aspect: observability (logging)"
# 3. Aspect: Caching
echo "==> Creating caching patch (based on base)..."
echo "$BASE_CODE" > main.py
cat >> main.py <<'PY'
import logging
from functools import lru_cache
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
)
@lru_cache(maxsize=128)
def compute(x: int) -> int:
"""Compute with caching: double the input."""
logging.info("compute called with x=%s", x)
return x * 2
if __name__ == "__main__":
try:
logging.info("Application start")
# Make two calls to show the cache hit.
for n in (5, 5):
result = compute(n)
logging.info("Result for %s = %s", n, result)
print(f"Result: {result}")
except Exception as e:
logging.exception("Unhandled error")
import sys
sys.exit(1)
PY
pijul add main.py
pijul record -am "Aspect: caching"
# Final message
echo -e "\n🎉 Repository ready!"
echo "Run 'pijul log' to see the four independent patches."
echo "Run 'python3 main.py' to execute the latest version (with all aspects)."
echo "Use 'pijul undo' or 'pijul apply' to manage individual patches."
📌 How to Run
chmod +x create_aspect_repo.sh
./create_aspect_repo.sh
🧾 Output Summary
-
You’ll have 4 patches in the Pijul history:
Base: happy-path source
Aspect: error handling
Aspect: observability (logging)
Aspect: caching
-
Each patch is based on the original base, not the previous ones.
-
You can apply or remove any patch independently using pijul apply or pijul undo.
🔍 Notes
- No additive behavior: Each patch is a standalone change from the base.
- Conflict potential: If you apply all three aspects, they will conflict because they all modify the same file.
- Use case: This setup is ideal for testing or experimenting with different combinations of aspects without affecting the base.
🧠 Optional: Apply a Single Aspect
You can apply a specific patch like this:
pijul apply <patch-id>
You can find the patch IDs using:
pijul log
✅ Summary
This script demonstrates how to create independent aspect patches in Pijul, each based on the original base, rather than on previous patches. This is a closer approximation of an aspect-oriented versioning workflow than traditional additive workflows.