Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Architecture Overview

Portable Python Manager uses a strict 4-layer PowerShell 7.x architecture designed for zero external module dependencies, high performance via direct .NET APIs, and complete portability without Administrator elevation.


Directory & Layer Map

{ROOT}\
├── main.bat                        Interactive launcher (invokes pwsh.exe)
├── config.ini                      Manager settings & INI profile pointers
├── python.ini                      Personal [PipConfig], [Packages], [Venvs], [Env]
├── README.txt                      Standalone runtime doc (packaged in release ZIPs)
├── profiles\                       Opt-in active INI profiles (discovered dynamically)
├── logs\                           Auto-created daily verbose logs (30-day retention)
└── src\
    ├── install.ps1                 [Layer 4] CLI entrypoint: fresh install
    ├── update.ps1                  [Layer 4] CLI entrypoint: in-place binary update
    ├── configure.ps1               [Layer 4] CLI entrypoint: configurator & switcher
    ├── uninstall.ps1               [Layer 4] CLI entrypoint: removal & cleanup
    ├── core\                       [Layer 3] Domain logic & orchestration
    │   ├── config.ps1              INI parser, profile/python.ini loader & defaults
    │   ├── release.ps1             python.org index-windows.json, version picker & inspector
    │   ├── discovery.ps1           Multi-source portable install auto-discovery
    │   ├── settings.ps1            Portable data\ layout, sitecustomize.py, pip.ini & wizard
    │   └── packages.ps1            ensurepip bootstrap, scoped pip packages, venvs & cache
    ├── utility\                    [Layer 2] Low-level OS & I/O primitives
    │   ├── filesystem.ps1          HttpClient download, SHA-256, ZipFile extract, fast delete
    │   ├── path.ps1                User PATH & portable env var manager + broadcast
    │   └── registry.ps1            .NET Microsoft.Win32.Registry PEP 514 manager
    └── event\                      [Layer 1] Cross-cutting telemetry & UI
        ├── logger.ps1              Verbose daily file logger & retention pruner
        └── progress.ps1            Throttled inline wget-style progress bar

Dependency Flow

flowchart TD
    BAT["main.bat"] --> EP["Entrypoints: install / update / configure / uninstall"]
    EP --> CORE["src/core: config, release, discovery, settings, packages"]
    CORE --> UTIL["src/utility: filesystem, path, registry"]
    CORE --> EVT["src/event: logger, progress"]
    UTIL --> EVT
    EVT --> PROG["progress.ps1"]
  • Strict Acyclic Layering: Entrypoints dot-source all layers cleanly; library modules guard dot-sourcing via Get-Command checks so re-sourcing is idempotent.
  • Root Resolution Depth: Because src\core\config.ps1 and src\event\logger.ps1 reside two levels below {ROOT}, fallback $ScriptRoot computation always traverses two parent directories.

Key Architectural Decisions

1. Zero-Leak Portable Layout (data\ + sitecustomize.py)

Every installation creates data\pip-cache\, data\user-site\, data\venvs\, data\pip.ini, and writes an auto-managed Lib\site-packages\sitecustomize.py using os.environ.setdefault(...) pointing inside data\. Even if a user runs python.exe -m pip without User environment variables set, pip and REPL history stay strictly contained inside <InstallDir>\data\. Existing user-authored sitecustomize.py files are detected and never overwritten.

2. Pure .NET [Microsoft.Win32.Registry] with PEP 514

All registry operations use [Microsoft.Win32.Registry]::CurrentUser directly (CreateSubKey, OpenSubKey, SetValue, DeleteSubKeyTree, DeleteValue), registering official PEP 514 keys under HKCU\Software\Python\PythonCore\<Tag> alongside App Paths — requiring zero Administrator elevation and making portable copies discoverable by IDEs and py.

3. Exact Directory-Boundary Safety

All path-scoped operations prevent sibling prefix collisions (e.g. D:\CLI\Python vs D:\CLI\Python-3.14) using trailing separator checks ($Dir + "\") and regex boundary anchors.