astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
20.02k stars 594 forks source link

Allow setting virtual environment options in `pyproject.toml` #5737

Open chrisrodrigue opened 1 month ago

chrisrodrigue commented 1 month ago

When running uv venv, the user may specify the options --system-site-packages and --relocatable. These values persist in .venv/pyenv.cfg as shown:

home = C:\WinPython\python-3.12.4.amd64
implementation = CPython
uv = 0.2.33
version_info = 3.12.4
include-system-site-packages = true
relocatable = true

The uv sync command implicitly creates a virtual environment in .venv, which is awesome. However, it is not possible to pass these options to uv sync or set them in the tool.uv section (or a tool.uv.venv section) of pyproject.toml. The virtual environment created with uv sync always defaults to setting include-system-site-package and relocatable to false.

I propose that uv be capable of reading these from pyproject.toml, and also when passed to uv sync.

Maybe a generalized approach to file-based configuration (both uv.toml and pyproject.toml) of uv behavior could be to support a section corresponding to each uv command for all available options:

Example pyproject.toml demonstrating command customization:

[tool.uv]
no-build-isolation = true
dev-dependencies = []

[uv.tool.venv]
relocatable = true
system-site-packages = true

[uv.tool.sync]
relocatable = true
system-site-packages = true
all-extras = true

# Generalization
[uv.tool.command]
option = value
charliermarsh commented 1 month ago

This seems reasonable to me though want a second opinion before adding any configuration.

chrisrodrigue commented 1 month ago

A more elegant and concise alternative (similar to pdm as shown here - passing constant arguments to every pdm invocation):

[tool.uv.options]
venv = ["--relocatable", "--system-site-packages"]