Skip to main content

Hierarchical UV Virtual Environment Manager

Project description

huv - Hierarchical UV Virtual Environment Manager

A powerful wrapper around uv that creates hierarchical virtual environments where child environments can inherit packages from parent environments with proper precedence handling.

โœจ Features

  • ๐Ÿ—๏ธ Hierarchical Virtual Environments: Create child environments that inherit from parent environments
  • ๐Ÿ“ฆ Smart Package Management: Automatically skip installing packages that are already available from parent environments
  • ๐Ÿ” Dependency Analysis: Full dependency tree analysis to avoid duplicate installations
  • โšก Storage Efficient: Minimize disk usage by sharing common packages across environments
  • ๐ŸŽฏ Version Conflict Detection: Detect and handle version conflicts between parent and child environments
  • ๐Ÿ› ๏ธ Complete uv Compatibility: Full support for all uv venv and pip install flags and options
  • ๐Ÿ”ง Seamless Integration: Drop-in replacement for uv with added hierarchical capabilities

๐Ÿ“‹ Requirements

  • Python 3.8+
  • uv installed and available in PATH

Install uv if you haven't already:

Linux/macOS:

curl -LsSf https://astral.sh/uv/install.sh | sh

Windows (PowerShell):

powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

Windows (via winget):

winget install astral-sh.uv

๐Ÿš€ Installation

Option 1: Install via pip (Recommended)

pip install huv

Option 2: Run standalone executable

# Download the standalone executable
curl -LsSf https://github.com/your-org/huv/releases/latest/download/huv -o huv
chmod +x huv

# Move to a directory in your PATH (optional)
mv huv /usr/local/bin/

Option 3: Install from source

git clone https://github.com/your-org/huv.git
cd huv
pip install .

๐Ÿ“– Quick Start

Create a Root Environment

# Create a root environment with common packages
huv venv .vroot

Activating on Linux/macOS:

cd .vroot && source bin/activate
uv pip install numpy pandas requests
deactivate && cd ..

Activating on Windows:

cd .vroot && Scripts\activate.bat
uv pip install numpy pandas requests
deactivate && cd ..

Create Child Environments

# Create a child environment that inherits from .vroot
huv venv .vchild --parent .vroot

Activating on Linux/macOS:

cd .vchild && source bin/activate

# numpy, pandas, requests are already available from parent!
python -c "import numpy, pandas, requests; print('All packages available!')"

Activating on Windows:

cd .vchild && Scripts\activate.bat

# numpy, pandas, requests are already available from parent!
python -c "import numpy, pandas, requests; print('All packages available!')"

Smart Package Installation

# Install matplotlib - huv will skip numpy (available from parent)
huv pip install matplotlib

# Output:
# ๐Ÿ” Analyzing dependencies...
# ๐Ÿ“‹ Found 11 total packages (including dependencies)
# ๐Ÿ“ฆ Dependency 'numpy' (v2.3.3 available from parent)
# ๐Ÿ“ฆ Dependency 'packaging' (v25.0 available from parent)
# ๐Ÿ“ฅ Installing 8 package(s)
# โญ๏ธ  Skipped 3 package(s) available from parent

๐Ÿ”ง Commands

Environment Creation

# Create a standalone environment
huv venv myenv

# Create a hierarchical environment
huv venv child-env --parent parent-env

# Pass through uv options
huv venv myenv --python 3.11 --seed

Virtual Environment Options

huv supports all uv venv parameters while adding hierarchical functionality:

Core Environment Options

# Initialize with seed packages (pip, setuptools, wheel)
huv venv myenv --seed

# Clear existing environment if it exists
huv venv myenv --clear

# Custom prompt name
huv venv myenv --prompt "MyProject"

# Include system site packages
huv venv myenv --system-site-packages

Python Version Control

# Specify Python version
huv venv myenv --python 3.11
huv venv myenv -p python3.12

# Use managed Python installations
huv venv myenv --managed-python 3.11

Package Index Configuration

# Custom package index
huv venv myenv --index https://custom-index.com/simple/

# Default index configuration
huv venv myenv --default-index

# Find links for packages
huv venv myenv --find-links https://download.pytorch.org/whl/
huv venv myenv -f ./local-packages/

Performance and Caching Options

# Control file linking behavior
huv venv myenv --link-mode copy      # Copy files instead of hard links
huv venv myenv --link-mode hardlink  # Use hard links (default)
huv venv myenv --link-mode symlink   # Use symbolic links

# Cache management
huv venv myenv --cache-dir /custom/cache/path
huv venv myenv --refresh             # Refresh package metadata

# Combined hierarchical and performance options
huv venv child --parent .base --seed --python 3.11 --link-mode copy

Package Management

# Smart install (skips packages from parent)
huv pip install package1 package2

# Install from requirements files
huv pip install -r requirements.txt

# Editable installs
huv pip install -e ./my-package

# Install with constraints
huv pip install -c constraints.txt package1

# Install with extras
huv pip install package[extra1,extra2]
huv pip install --extra security requests

# Upgrade packages
huv pip install -U package1

# Custom indexes
huv pip install --index-url https://custom-index.com package1
huv pip install --extra-index-url https://extra-index.com package1

# Advanced options
huv pip install --no-deps package1      # Skip dependencies
huv pip install --user package1         # User install
huv pip install --target ./lib package1 # Target directory

# Uninstall with parent visibility
huv pip uninstall package1

๐ŸŽฏ Use Cases

Development Environments

Linux/macOS:

# Base environment with common tools
huv venv .base
source .base/bin/activate && uv pip install pytest black ruff mypy

# Project-specific environments
huv venv project1 --parent .base  # Inherits pytest, black, etc.
huv venv project2 --parent .base  # Inherits pytest, black, etc.

Windows:

# Base environment with common tools
huv venv .base
.base\Scripts\activate.bat && uv pip install pytest black ruff mypy

# Project-specific environments
huv venv project1 --parent .base  # Inherits pytest, black, etc.
huv venv project2 --parent .base  # Inherits pytest, black, etc.

Machine Learning Workflows

Linux/macOS:

# Base ML environment
huv venv .ml-base
source .ml-base/bin/activate && uv pip install numpy pandas scikit-learn

# Experiment environments
huv venv experiment1 --parent .ml-base  # + tensorflow
huv venv experiment2 --parent .ml-base  # + pytorch

Windows:

# Base ML environment
huv venv .ml-base
.ml-base\Scripts\activate.bat && uv pip install numpy pandas scikit-learn

# Experiment environments
huv venv experiment1 --parent .ml-base  # + tensorflow
huv venv experiment2 --parent .ml-base  # + pytorch

Microservices

Linux/macOS:

# Shared utilities environment
huv venv .shared
source .shared/bin/activate && uv pip install requests pydantic fastapi

# Service-specific environments
huv venv auth-service --parent .shared     # + additional auth packages
huv venv user-service --parent .shared     # + additional user packages

Windows:

# Shared utilities environment
huv venv .shared
.shared\Scripts\activate.bat && uv pip install requests pydantic fastapi

# Service-specific environments
huv venv auth-service --parent .shared     # + additional auth packages
huv venv user-service --parent .shared     # + additional user packages

๐Ÿ—๏ธ How It Works

  1. Environment Creation: huv venv creates a standard uv virtual environment with full support for all uv venv parameters, then modifies the activation scripts to include parent environment paths in PYTHONPATH

  2. Package Resolution: huv pip install analyzes the complete dependency tree and checks which packages are already available from parent environments

  3. Smart Installation: Only packages not available from parents are installed, using --no-deps when necessary to avoid conflicts

  4. Precedence: Child environment packages always take precedence over parent packages

๐Ÿ–ฅ๏ธ Cross-Platform Support

huv works seamlessly across Linux, macOS, and Windows with automatic OS detection and platform-specific handling:

Platform Differences

  • Linux/macOS: Uses bin/activate scripts and lib/python*/site-packages directories
  • Windows: Uses Scripts\activate.bat scripts and Lib\site-packages directories

Activation Commands

Linux/macOS:

source myenv/bin/activate

Windows Command Prompt:

myenv\Scripts\activate.bat

Windows PowerShell:

myenv\Scripts\Activate.ps1

Environment Structure

Linux/macOS:

myenv/
โ”œโ”€โ”€ bin/
โ”‚   โ”œโ”€โ”€ activate
โ”‚   โ”œโ”€โ”€ activate.fish
โ”‚   โ”œโ”€โ”€ activate.csh
โ”‚   โ”œโ”€โ”€ activate.nu
โ”‚   โ””โ”€โ”€ python
โ”œโ”€โ”€ lib/
โ”‚   โ””โ”€โ”€ python3.x/
โ”‚       โ””โ”€โ”€ site-packages/
โ””โ”€โ”€ pyvenv.cfg

Windows:

myenv\
โ”œโ”€โ”€ Scripts\
โ”‚   โ”œโ”€โ”€ activate.bat
โ”‚   โ”œโ”€โ”€ Activate.ps1
โ”‚   โ””โ”€โ”€ python.exe
โ”œโ”€โ”€ Lib\
โ”‚   โ””โ”€โ”€ site-packages\
โ””โ”€โ”€ pyvenv.cfg

All huv features work identically across platforms - only the activation commands differ.

๐Ÿ“š Complete Flag Support

huv provides comprehensive support for both uv venv and uv pip install commands while maintaining hierarchical functionality.

Requirements and Constraints

# Requirements files (with comments and empty lines supported)
huv pip install -r requirements.txt -r dev-requirements.txt

# Constraint files  
huv pip install -c constraints.txt package1

# Editable installs
huv pip install -e ./my-package -e git+https://github.com/user/repo.git

Package Sources and Indexes

# Custom package indexes
huv pip install -i https://custom-index.com/simple/ package1
huv pip install --extra-index-url https://extra-index.com/simple/ package1

# Find links (local or remote archives)
huv pip install -f https://example.com/packages/ package1
huv pip install -f ./local-packages/ package1

# Ignore PyPI entirely
huv pip install --no-index -f ./local-packages/ package1

Package Extras and Dependencies

# Install with extras
huv pip install --extra security --extra testing requests
huv pip install --all-extras package1

# Control dependency installation
huv pip install --no-deps package1  # Skip dependencies entirely

Upgrade and Reinstall Options

# Upgrade packages
huv pip install -U package1         # Upgrade specific package
huv pip install -P package1 -P package2  # Upgrade specific packages

# Force reinstallation
huv pip install --force-reinstall package1

Installation Targets

# User installation
huv pip install --user package1

# Custom target directory
huv pip install --target ./mylib package1

# Custom prefix
huv pip install --prefix /opt/myapp package1

Build Control

# Control wheel/source usage
huv pip install --no-binary package1    # Force source build
huv pip install --only-binary package1  # Only use wheels
huv pip install --no-build package1     # Don't build sources

# Security requirements
huv pip install --require-hashes -r requirements.txt

๐Ÿ”ง Environment Management

Python Version Consistency

huv automatically ensures Python version consistency in hierarchical environments:

# Create parent with Python 3.11
huv venv .parent --python 3.11

# Child automatically inherits Python 3.11
huv venv child --parent .parent  # Uses Python 3.11 automatically

# Error if trying to use different version
huv venv child --parent .parent --python 3.10  # โŒ Error: Version mismatch

Environment Information

Check environment hierarchy:

cat child/pyvenv.cfg | grep huv_parent
# Output: huv_parent = /path/to/.parent

Verify package inheritance:

Linux/macOS:

source child/bin/activate
python -c "import sys; print(sys.path)"  # Shows parent paths

Windows:

child\Scripts\activate.bat
python -c "import sys; print(sys.path)"  # Shows parent paths

Cleanup and Management

# Remove environments (children first)
rm -rf child/
rm -rf .parent/

# Check what packages come from where
huv pip list  # Shows local packages only
pip list      # Shows all packages (including inherited)

๐Ÿ› ๏ธ Advanced Usage

Advanced Installation Options

Version Constraints

# huv respects version constraints
huv pip install "numpy>=1.20"  # Skips if parent has compatible version
huv pip install "numpy>=2.0"   # Installs if parent has numpy 1.x

Multiple Requirements Sources

# Combine requirements files, constraints, and packages
huv pip install -r requirements.txt -c constraints.txt package1 package2

# Install with multiple requirement files
huv pip install -r base-requirements.txt -r dev-requirements.txt

# Mix editable and regular packages
huv pip install -e ./my-lib package1 package2

Build and Installation Control

# Control build process
huv pip install --no-build package1        # Don't build from source
huv pip install --no-binary :all: package1 # Force source builds
huv pip install --only-binary :all: package1 # Only use wheels

# Reinstall packages
huv pip install --force-reinstall package1

# Security options
huv pip install --require-hashes -r locked-requirements.txt

Multiple Inheritance Levels

huv venv .base
huv venv .ml --parent .base
huv venv .deep-learning --parent .ml  # Inherits from both .ml and .base

Advanced Environment Configuration

# Create optimized hierarchical environments
huv venv .base --seed --python 3.11 --link-mode hardlink
huv venv project1 --parent .base --prompt "Project1" --clear

# Development environment with custom index
huv venv dev --parent .base --index https://test.pypi.org/simple/ --seed

# Performance-optimized environment
huv venv fast-env --parent .base --link-mode copy --cache-dir ./local-cache

Development Workflow

# Create development environment structure
huv venv .deps                           # Common dependencies
huv venv .tools --parent .deps           # + development tools  
huv venv myproject --parent .tools       # + project-specific packages

๐Ÿ› Troubleshooting

Common Issues

Environment Creation Fails

# Error: Path already exists
rm -rf existing-path && huv venv existing-path

# Error: Parent environment not found
huv venv child --parent /path/to/missing  # Check parent path

Package Installation Issues

# Force installation if dependency analysis fails
huv pip install --no-deps package-name

# Clear cache if having dependency resolution issues
uv cache clean

# Check what packages are inherited

Linux/macOS:

source child/bin/activate
python -c "import package; print(package.__file__)"  # Shows source location

Windows:

child\Scripts\activate.bat
python -c "import package; print(package.__file__)"  # Shows source location

Python Version Issues

Linux/macOS:

# Check parent Python version
parent-env/bin/python --version

# Create child with explicit version matching parent
huv venv child --parent parent-env --python 3.11

Windows:

# Check parent Python version
parent-env\Scripts\python.exe --version

# Create child with explicit version matching parent
huv venv child --parent parent-env --python 3.11

Performance Tips

  • Use --link-mode hardlink for fastest environment creation
  • Share a base environment across multiple projects to save disk space
  • Use --no-deps for packages when you know dependencies are satisfied by parents
  • Keep environment hierarchies shallow (2-3 levels max) for best performance

Debugging

# Enable verbose output for uv operations
export UV_VERBOSE=1
huv pip install package-name

# Check inheritance chain
huv venv child --parent .parent --verbose  # If supported

# Manual inspection of environment
cat child/pyvenv.cfg

Check activation script modifications:

Linux/macOS:

cat child/bin/activate  # Check PYTHONPATH modifications

Windows:

type child\Scripts\activate.bat  # Check PYTHONPATH modifications

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Project Structure

huv is designed as a single standalone executable for maximum portability:

huv                    # Main executable (Python script)
โ”œโ”€โ”€ README.md         # Documentation
โ”œโ”€โ”€ LICENSE           # MIT License
โ””โ”€โ”€ pyproject.toml    # Build configuration

The huv file contains the complete application and can be run directly without installation. This design makes it easy to:

  • Distribute as a single file
  • Run without complex dependencies
  • Integrate into existing workflows
  • Deploy in containerized environments

Development Setup

# Clone and setup development environment
git clone https://github.com/your-org/huv.git
cd huv

# Run tests
./run_tests.sh

# Or run specific tests
python tests/test_huv.py

# Test manually
./huv venv test-env
./huv venv test-child --parent test-env

Running Tests

The project includes comprehensive tests:

# Run all tests (unit + integration)
./run_tests.sh

# Run only unit tests
python tests/test_huv.py

# Run with Python's unittest
python -m unittest tests.test_huv

# Run specific test
python tests/test_huv.py TestHuv.test_create_hierarchical_venv

Code Quality

The project maintains high code quality standards:

  • Comprehensive test coverage (15+ test cases)
  • GitHub Actions CI/CD for multi-platform testing
  • Support for Python 3.8+ across Linux, macOS, and Windows
  • Automated testing on every commit

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Built on top of the excellent uv package manager
  • Inspired by the need for more efficient virtual environment management
  • Thanks to the Python packaging community for the tools and standards

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

huv-0.3.0.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

huv-0.3.0-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file huv-0.3.0.tar.gz.

File metadata

  • Download URL: huv-0.3.0.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for huv-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ddd36ecf044a70cc5075e061cebfc486311f4e1267f77e10de9e2522e999dd64
MD5 80f5a5798cae294da6790e3ce8a1169d
BLAKE2b-256 aa4a569a37450d3a236d0554562cba6e12bb02389a7a507234837c42904d380b

See more details on using hashes here.

Provenance

The following attestation bundles were made for huv-0.3.0.tar.gz:

Publisher: release.yml on abuss/huv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file huv-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: huv-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for huv-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4a4dd02a6539ced80f363c437bae77bf5c2599296096cb349426120362d0b31
MD5 c7a21b88e09bb3414e8e9088dfe3547b
BLAKE2b-256 8e342af2983b321f42fa953f8d4dda733a22f2a06f108c060e638a98d004c4b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for huv-0.3.0-py3-none-any.whl:

Publisher: release.yml on abuss/huv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page