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:
- Using a single environment across all sub-repositories, or
- 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.),vuvensures thatuvuses it instead of creating a new one. -
Seamless Integration with
uv: Usevuvjust likeuv; all commands and arguments are passed directly touv. -
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 supportinstallinstead ofsyncand to matchuvbehavior withpoetry, we supportsvuv installcommands. It's implemented as simple; just it remapsvuv installintouv 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:
vuvrequires 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 pureuvinstead ofvuv. conda'sbaseenvironment protection:vuvwill ask for user confirmation before modifying packages in thebaseenvironment inconda, as this is generally not recommended. You can bypass this prompt by setting theVUV_ALLOW_BASE=1environment variable (useful in Docker containers).
How It Works
When you run a command with vuv:
- Checks for an Active Virtual Environment:
- For conda, it checks if
CONDA_DEFAULT_ENVis set. If it's thebaseenvironment, it asks for user confirmation before proceeding. - For virtualenv, it checks if
VIRTUAL_ENVis set.
- For conda, it checks if
- Sets Environment Variables:
- Sets
UV_PROJECT_ENVIRONMENTto point to your current virtual environment, souvuses it instead of creating a new one.
- Sets
- Runs the
uvCommand:- Passes all arguments to
uvwith the modified environment variables.
- Passes all arguments to
Environment Variables
-
VUV_ALLOW_BASE: Set to1,true, oryesto 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
uvis 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
103a01c68095df31823cc8957bccf9bf8d017dddd572867d1935431779a52445
|
|
| MD5 |
c8e7a0921e1e00360479003e942eb33b
|
|
| BLAKE2b-256 |
66604aa9fe7ee7b435bb93394427a01b232f21688b3b319e516a127a2d947c1d
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4cdebf7b6e159df280e6977327f4e9fc42e9a65d54fdce70611c604b85a443eb
|
|
| MD5 |
282823ab5abade729cec7180133639bb
|
|
| BLAKE2b-256 |
849555f0cd098f18499c7bc8c13008ba287e7d05a67fbd74623e984656a841b5
|