Skip to main content

A wrapper script for uv enabling automatic virtual environment detection and configuration.

Project description

vuv

A wrapper script for uv enabling automatic virtual environment detection and configuration.

Motivation

uv, by defaults without UV_PROJECT_ENVIRONMENT customization, forcefully creates and activates its own virtual environment, even when you already have one activated. This behavior can be inconvenient, especially when working in a monorepo setup.

In monorepo development, uv only supports:

  1. Using a single environment across all sub-repositories, or
  2. Using separate environments for each sub-repository.

However, these options lack flexibility. They do not allow you to selectively install and manage dependencies across some sub-repositories with flexible interdependencies.

The existing virtual environment support in uv is limited and doesn't accommodate such scenarios. It provides only minimal customization through environment variables.

To address these limitations, vuv was created. It allows uv to detect and use your currently activated virtual environment, providing the flexibility needed for complex project structures without forcing the creation of new environments.

Related issues in uv: https://github.com/astral-sh/uv/issues/1703, https://github.com/astral-sh/uv/issues/11152, https://github.com/astral-sh/uv/issues/11315, https://github.com/astral-sh/uv/issues/11273, ...

If equivalent feature is implemented in uv, this repo would be useless; I hope that time comes soon, since I'm waiting over 1 year.

Features

  • Respects Existing Virtual Environments: If a virtual environment is already activated (managed by conda, virtualenv, etc.), vuv ensures that uv uses it instead of creating a new one.

  • Seamless Integration with uv: Use vuv just like uv; all commands and arguments are passed directly to uv.

  • vuv install: uv, by defaults, forcefully sync whole project dependencies into python environment and it leads possible environment corruption when we use pre-existing environments. To support install instead of sync and to match uv behavior with poetry, we supports vuv install commands. It's implemented as simple; just it remaps vuv install into uv sync --inexact.

Installation

pip install virtual-uv

Usage

Use vuv as a drop-in replacement for uv.

Examples

# Add a package to your project
vuv add package-name

# Install dependencies (equivalent to 'uv sync --inexact')
vuv install

# Run other uv commands
vuv <uv-command> [arguments]

# For Docker containers or when you need to work with conda base environment
VUV_ALLOW_BASE=1 vuv add package-name

Note

  • Virtual Environment Required: vuv requires an active virtual environment. If none is detected, to prevent unexpected behavior, it will prompt you to activate one. If you require system-wide install, use pure uv instead of vuv.
  • conda's base environment protection: vuv will ask for user confirmation before modifying packages in the base environment in conda, as this is generally not recommended. You can bypass this prompt by setting the VUV_ALLOW_BASE=1 environment variable (useful in Docker containers).

How It Works

When you run a command with vuv:

  1. Checks for an Active Virtual Environment:
    • For conda, it checks if CONDA_DEFAULT_ENV is set. If it's the base environment, it asks for user confirmation before proceeding.
    • For virtualenv, it checks if VIRTUAL_ENV is set.
  2. Sets Environment Variables:
    • Sets UV_PROJECT_ENVIRONMENT to point to your current virtual environment, so uv uses it instead of creating a new one.
  3. Runs the uv Command:
    • Passes all arguments to uv with the modified environment variables.

Environment Variables

  • VUV_ALLOW_BASE: Set to 1, true, or yes to allow modifications to conda's base environment without confirmation prompts. This is particularly useful in Docker containers where you need to work with the base environment.

    # Allow base environment modifications
    export VUV_ALLOW_BASE=1
    vuv add package-name
    
    # Or set it for a single command
    VUV_ALLOW_BASE=1 vuv add package-name
    

Requirements

  • Python: 3.7 or higher
  • uv: Ensure uv is installed and accessible from the command line.
  • Virtual Environment: An active virtual environment managed by conda, virtualenv, or similar tools.

Contributing

Contributions are welcome! Feel free to submit issues or pull requests.

License

This project is licensed under the MIT License.

Author

Developed by MilkClouds.

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

virtual_uv-0.1.4.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

virtual_uv-0.1.4-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file virtual_uv-0.1.4.tar.gz.

File metadata

  • Download URL: virtual_uv-0.1.4.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for virtual_uv-0.1.4.tar.gz
Algorithm Hash digest
SHA256 103a01c68095df31823cc8957bccf9bf8d017dddd572867d1935431779a52445
MD5 c8e7a0921e1e00360479003e942eb33b
BLAKE2b-256 66604aa9fe7ee7b435bb93394427a01b232f21688b3b319e516a127a2d947c1d

See more details on using hashes here.

File details

Details for the file virtual_uv-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: virtual_uv-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for virtual_uv-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4cdebf7b6e159df280e6977327f4e9fc42e9a65d54fdce70611c604b85a443eb
MD5 282823ab5abade729cec7180133639bb
BLAKE2b-256 849555f0cd098f18499c7bc8c13008ba287e7d05a67fbd74623e984656a841b5

See more details on using hashes here.

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