Core Concepts¶
Understanding wrknv's architecture and design principles.
๐ค AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
The Environment Generation Model¶
wrknv follows a configuration-driven code generation approach:
โโโโโโโโโโโโโโโโโโโโโโโ
โ pyproject.toml โ โ Your configuration
โ [tool.wrknv] โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โ wrknv generate
โโโโโโโโโโโโโโโโโโโโโโโ
โ Templates (Jinja2) โ โ Shell script templates
โ sh/base.sh.j2 โ
โ pwsh/base.ps1.j2 โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โ Render
โโโโโโโโโโโโโโโโโโโโโโโ
โ env.sh + env.ps1 โ โ Generated scripts
โ (300-400 lines) โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โ source env.sh
โโโโโโโโโโโโโโโโโโโโโโโ
โ Running Env โ โ Your development environment
โ โ Tools installed โ
โ โ Venv activated โ
โ โ Deps installed โ
โโโโโโโโโโโโโโโโโโโโโโโ
Key Concepts¶
1. Configuration, Not Code¶
wrknv replaces shell script code with TOML configuration:
Before (Shell Script):
# env.sh (400 lines of bash)
TERRAFORM_VERSION="1.9.0"
GO_VERSION="1.22.0"
# ... 300+ more lines ...
After (TOML Configuration):
2. Template-Based Generation¶
wrknv uses Jinja2 templates to generate platform-specific scripts:
- Templates: Battle-tested, maintained once
- Generation: Happens locally, verifiable
- Scripts: Fresh, correct, platform-appropriate
This means:
- โ
No copy-paste errors
- โ
Automatic platform handling
- โ
Updates via wrknv generate
- โ
Inspectable output
3. Work Environments (workenv/)¶
wrknv uses workenv/ instead of .venv/ for important reasons:
my-project/
โโโ pyproject.toml
โโโ env.sh # Generated scripts
โโโ env.ps1
โโโ workenv/ # Work environment (wrknv-managed)
โ โโโ bin/
โ โโโ lib/
โ โโโ pyvenv.cfg
โโโ .venv/ # Never used by wrknv
Why workenv/? - Clear ownership: Managed by wrknv, not manual - Avoid conflicts: Doesn't interfere with IDE-created .venv/ - Consistency: Same name across all projects - Gitignore-friendly: Standard pattern to exclude
4. Tool Managers¶
Each tool (UV, Terraform, Go) has a manager that knows how to:
- Download - From official sources
- Verify - Checksums and signatures
- Install - To
workenv/bin/ - Update - When configuration changes
ToolManager (Abstract Base)
โโโ UVManager # UV package manager
โโโ TerraformManager # HashiCorp Terraform
โโโ OpenTofuManager # OpenTofu fork
โโโ GoManager # Go toolchain
Manager Pattern Benefits: - Extensible: Add new tools easily - Consistent: Same interface for all tools - Platform-aware: Handles OS/architecture differences - Cacheable: Reuses downloads across projects
5. Sibling Package Discovery¶
wrknv automatically finds and installs related packages in a monorepo:
workspace/
โโโ provide-foundation/ # Core library
โ โโโ pyproject.toml
โโโ pyvider/ # Depends on foundation
โ โโโ pyproject.toml
โโโ my-provider/ # Depends on both
โโโ pyproject.toml
โโโ wrknv.toml
Configuration:
Discovery Process:
1. Match patterns against filesystem
2. Read each pyproject.toml
3. Build dependency graph
4. Install in topological order
5. Use editable mode (pip install -e)
Benefits: - โ No manual path management - โ Automatic dependency order - โ Live code updates (editable mode) - โ Works across ecosystems
6. Configuration Hierarchy¶
wrknv loads configuration from multiple sources:
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Default Values โ โ Built-in defaults
โโโโโโโโโโโโโฌโโโโโโโโโโโโโโ
โ (overridden by)
โโโโโโโโโโโโโผโโโโโโโโโโโโโโ
โ pyproject.toml โ โ Project configuration
โ [tool.wrknv] โ
โโโโโโโโโโโโโฌโโโโโโโโโโโโโโ
โ (overridden by)
โโโโโโโโโโโโโผโโโโโโโโโโโโโโ
โ wrknv.toml โ โ Optional separate config
โโโโโโโโโโโโโฌโโโโโโโโโโโโโโ
โ (overridden by)
โโโโโโโโโโโโโผโโโโโโโโโโโโโโ
โ Environment Variables โ โ Runtime overrides
โ WRKNV_* โ
โโโโโโโโโโโโโฌโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโผโโโโโโโโโโโโโโ
โ Final Configuration โ โ Merged result
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
7. Lockfiles¶
wrknv.lock ensures reproducible environments:
# wrknv.lock
[tools]
uv = { version = "0.5.1", hash = "sha256:..." }
terraform = { version = "1.9.0", hash = "sha256:..." }
[resolution]
timestamp = "2025-01-15T10:30:00Z"
platform = "darwin_arm64"
Lock Command:
Benefits: - ๐ Exact versions across team - ๐ Verified downloads - ๐ Audit trail
8. Profiles¶
Different configurations for different environments:
# pyproject.toml
[tool.wrknv.tools]
uv = "0.5.1"
[tool.wrknv.profile.ci]
terraform = "1.9.0" # CI needs Terraform
[tool.wrknv.profile.local]
terraform = "1.9.0"
go = "1.22.0" # Local dev also needs Go
Usage:
# Default profile
$ wrknv generate
# CI profile
$ wrknv generate --profile ci
# Local profile
$ wrknv generate --profile local
9. Container Integration¶
wrknv can generate environments inside containers:
[tool.wrknv.container]
runtime = "docker"
base_image = "python:3.11-slim"
volumes = [".:/workspace"]
Workflow:
$ wrknv container build
$ wrknv container shell
(container) $ source env.sh
(container) $ # Fully configured environment inside Docker!
10. Doctor System¶
Health checks ensure your environment is correct:
$ wrknv doctor
โ Python version: 3.11.12 (โ matches >=3.11)
โ UV installed: 0.5.1 (โ matches config)
โ Virtual environment: workenv/ (โ active)
โ Dependencies: 45 packages (โ all installed)
! Terraform: not found (โ specified in config)
2025-11-07 14:30:00 [WARNING] terraform specified but not installed
Doctor Checks: - Python version requirements - Tool installation and versions - Virtual environment state - Dependency installation - Configuration validity - Platform compatibility
Design Principles¶
1. Configuration Over Convention¶
wrknv requires explicit configuration. No hidden magic.
Example: You must specify tool versions:
2. Generate, Don't Abstract¶
wrknv generates readable scripts you can inspect and modify.
Philosophy:
- Scripts are artifacts, not black boxes
- You can read env.sh to see what it does
- Modifications go in config, not scripts
- Regenerate anytime with wrknv generate
3. Platform Native¶
Generated scripts use platform-native patterns:
- Linux/macOS: Bash with POSIX compatibility
- Windows: PowerShell with native cmdlets
No "universal shell" compromises.
4. Tool Ownership¶
wrknv owns tool installation, not your entire environment:
wrknv manages:
- Tools in workenv/bin/
- Python virtual environment
- Sibling package installation
wrknv does NOT manage: - System Python installation - IDE configuration - Global shell settings - Git configuration
5. Fail Fast, Fail Clearly¶
wrknv validates early and provides clear errors:
$ wrknv generate
โ Error: Python version 3.9.0 does not satisfy requirement >=3.11
Current: 3.9.0
Required: >=3.11
Please upgrade Python or adjust requires-python in pyproject.toml
Common Patterns¶
Pattern 1: Monorepo Structure¶
workspace/
โโโ .wrknvignore # Exclude certain directories
โโโ library-a/
โ โโโ pyproject.toml # [tool.wrknv.siblings]
โโโ library-b/
โ โโโ pyproject.toml # [tool.wrknv.siblings]
โโโ app/
โโโ pyproject.toml # Uses both libraries
Pattern 2: CI/CD Integration¶
# .github/workflows/test.yml
- name: Setup Environment
run: |
pip install wrknv
wrknv generate --profile ci
source env.sh
pytest
Pattern 3: Team Standardization¶
All team projects use:
One command updates all projects:
Next Steps¶
Now that you understand wrknv's concepts:
- API Reference - Python API documentation
- Quick Start Guide - Get wrknv running
- Installation Guide - Complete setup guide
Or return to: