Skip to content

Rich Module Switching

Demo Status: Verified

This demo is fully functional and runs automatically via the CLI.

Try it now: Click the play button to run this demo instantly:

omnipkg demo 1

This demo showcases OmniPkg’s ability to manage multiple concurrent versions of a pure Python package (like rich) within a single environment, switching between them instantly using the Worker Daemon.

Usage

To run this demo directly on your machine (skipping the main interactive menu), use the following command:

# Run Demo #1: Rich Module Switching
omnipkg demo 1

What You’ll Learn

  1. Bubble Creation: How OmniPkg installs conflicting versions into isolated “Bubbles” without breaking the main environment.
  2. Daemon Proxying: How to execute code against a specific version using the DaemonProxy.
  3. Auto-Healing: How the system detects corruption or missing files and repairs them on the fly.

The Code

This script sets up a “Main” environment with rich==13.7.1, then creates isolated bubbles for older versions (13.5.3 and 13.4.2). It then verifies that each context loads the correct code.

demo_rich.py
from omnipkg.common_utils import safe_print
from omnipkg.isolation.worker_daemon import DaemonClient, DaemonProxy

# 1. Setup Main Environment
omnipkg_core.smart_install(["rich==13.7.1"])

# 2. Create Isolated Bubbles
# These do NOT overwrite 13.7.1; they live in hidden side-dirs
omnipkg_core.smart_install(["rich==13.5.3"])
omnipkg_core.smart_install(["rich==13.4.2"])

# 3. Verify Main Environment (Local Process)
import rich
print(f"Main Process Version: {rich.__version__}") 
# Output: 13.7.1

# 4. Verify Bubbles (Daemon Process)
client = DaemonClient()

# Execute code inside the v13.5.3 bubble
proxy = DaemonProxy(client, "rich==13.5.3")
result = proxy.execute("""
import rich
from importlib.metadata import version
print(f"Daemon Version: {version('rich')}")
""")
# Output: 13.5.3

Live Execution Log

Below is the actual output from running this demo. Notice how OmniPkg handles the installation, verification, and cleanup automatically.

omnipkg demo 1
(evocoder_env) minds3t@aiminingrig:~/omnipkg$ omnipkg demo 1

================================================================================
  ๐Ÿš€ STEP 1: Environment Setup & Cleanup
================================================================================
   ๐Ÿงน Force removing any existing Rich installation...
   โœ… Rich uninstalled successfully.
   โ„น๏ธ  Rich not found. Installing baseline v13.7.1...
   โœ“ Pip validated 'rich==13.7.1' -> 'rich==13.7.1'
   โœ… Environment prepared

================================================================================
  ๐Ÿš€ STEP 2: Creating Test Bubbles
================================================================================
   ๐Ÿซง Creating bubble for rich==13.5.3
   โš ๏ธ  Detected 1 dependency changes:
      โฌ‡๏ธ  rich: v13.7.1 โ†’ v13.5.3 (downgrade)
   ๐Ÿ›ก๏ธ STABILITY PROTECTION: Processing 1 changed package(s)
   ๐Ÿซง Creating isolated bubble for rich v13.5.3 (Python 3.11 context)
   - ๐Ÿšš Moving verified build to bubble: .../.omnipkg_versions/rich-13.5.3
   โœ… Bubble created successfully

   ๐Ÿซง Creating bubble for rich==13.4.2
   โš ๏ธ  Detected 1 dependency changes:
      โฌ‡๏ธ  rich: v13.7.1 โ†’ v13.4.2 (downgrade)
   ๐Ÿ›ก๏ธ STABILITY PROTECTION: Processing 1 changed package(s)
   - ๐Ÿšš Moving verified build to bubble: .../.omnipkg_versions/rich-13.4.2
   โœ… Bubble created successfully

================================================================================
  ๐Ÿš€ STEP 3: High-Speed Version Verification
================================================================================

--- Testing Main Environment (rich==13.7.1) ---
   ๐Ÿ  Verifying v13.7.1 in Main Process...
   โœ… Verified version 13.7.1

--- Testing Bubble (rich==13.5.3) ---
   โšก Verifying v13.5.3 via Daemon Worker...
      - Version: 13.5.3
      - Path: .../site-packages/.omnipkg_versions/rich-13.5.3/rich/__init__.py
      - Latency: 1752.59ms
   โœ… Verified version 13.5.3

--- Testing Bubble (rich==13.4.2) ---
   โšก Verifying v13.4.2 via Daemon Worker...
      - Version: 13.4.2
      - Path: .../site-packages/.omnipkg_versions/rich-13.4.2/rich/__init__.py
      - Latency: 1723.25ms
   โœ… Verified version 13.4.2

================================================================================
  ๐Ÿš€ FINAL TEST RESULTS
================================================================================
   main-13.7.1               : โœ… PASSED
   bubble-13.5.3             : โœ… PASSED
   bubble-13.4.2             : โœ… PASSED

================================================================================
  ๐Ÿš€ STEP 4: Cleanup
================================================================================
   ๐Ÿงน Removing test bubbles...
   ๐Ÿ—‘๏ธ  Deleting bubble directory: .../.omnipkg_versions/rich-13.5.3
   ๐Ÿ—‘๏ธ  Deleting bubble directory: .../.omnipkg_versions/rich-13.4.2
   โœ… Main environment (v13.7.1) preserved.

How It Works

  1. Stability Protection: When the script requested rich==13.5.3, OmniPkg saw that 13.7.1 was already installed. Instead of downgrading (which would break the main environment), it triggered Stability Protection.
  2. Bubble Storage: The older versions were installed into hidden directories (.omnipkg_versions/).
  3. Daemon Isolation: The main process kept using v13.7.1. The verification requests for older versions were sent to the Worker Daemon, which dynamically loaded the bubble paths into sys.path for that specific execution context.