Skip to main content

Integration of uv with tox.

Project description

tox-uv

PyPI version PyPI Supported Python Versions check Downloads

tox-uv is a tox plugin, which replaces virtualenv and pip with uv in your tox environments. Note that you will get both the benefits (performance) or downsides (bugs) of uv.

How to use

Install tox-uv into the environment of your tox, and it will replace virtualenv and pip for all runs:

uv tool install tox --with tox-uv # use uv to install
tox --version # validate you are using the installed tox
tox r -e py312 # will use uv
tox --runner virtualenv r -e py312 # will use virtualenv+pip

tox environment types provided

This package will provide the following new tox environments:

  • uv-venv-runner is the ID for the tox environments runner for environments not using a lock file.
  • uv-venv-lock-runner is the ID for the tox environments runner for environments using uv.lock (note we can’t detect the presence of the uv.lock file to enable this because that would break environments not using the lock file - such as your linter).
  • uv-venv-pep-517 is the ID for the PEP-517 packaging environment.
  • uv-venv-cmd-builder is the ID for the external cmd builder.

uv.lock support

If you want for a tox environment to use uv sync with a uv.lock file you need to change for that tox environment the runner to uv-venv-lock-runner. Furthermore, should in such environments you use the extras config to instruct uv to install the specified extras, for example (this example is for the tox.ini, for other formats see the documentation here):

[testenv:fix]
description = run code formatter and linter (auto-fix)
skip_install = true
deps =
    pre-commit-uv>=4.1.1
commands =
    pre-commit run --all-files --show-diff-on-failure

[testenv:type]
runner = uv-venv-lock-runner
description = run type checker via mypy
commands =
    mypy {posargs:src}

[testenv:dev]
runner = uv-venv-lock-runner
description = dev environment
extras =
    dev
    test
    type
commands =
    uv pip tree

In this example:

  • fix will use the uv-venv-runner and use uv pip install to install dependencies to the environment.
  • type will use the uv-venv-lock-runner and use uv sync to install dependencies to the environment without any extra group.
  • dev will use the uv-venv-lock-runner and use uv sync to install dependencies to the environment with the dev, test and type extra groups.

Note that when using uv-venv-lock-runner, all dependencies will come from the lock file, controlled by extras. Therefore, options like deps are ignored (and all others enumerated here as Python run flags).

package

How to install the source tree package, must be one of:

  • skip,
  • wheel,
  • editable (default),
  • uv (use uv to install the project, rather than build wheel via tox),
  • uv-editable (use uv to install the project in editable mode, rather than build wheel via tox).

You should use the latter two in case you need to use any non-standard features of uv, such as tool.uv.sources.

extras

A list of string that selects, which extra groups you want to install with uv sync. By default, it is empty.

no_default_groups

A boolean flag to toggle installation of the uv default development groups. By default, it will be true if the dependency_groups is not empty and false otherwise.

dependency_groups

Specify PEP 735 – Dependency Groups to install.

uv_sync_flags

A list of strings, containing additional flags to pass to uv sync (useful because some flags are not configurable via environment variables). For example, if you want to install the package in non editable mode and keep extra packages installed into the environment you can do:

uv_sync_flags = --no-editable, --inexact

External package support

Should tox be invoked with the --installpkg flag (the argument must be either a wheel or source distribution) the sync operation will run with --no-install-project and uv pip install will be used afterward to install the provided package.

Environment creation

We use uv venv to create virtual environments. This process can be configured with the following options:

uv_seed

This flag, set on a tox environment level, controls if the created virtual environment injects pip, setuptools and wheel into the created virtual environment or not. By default, it is off. You will need to set this if you have a project that uses the old legacy-editable mode, or your project doesn’t support the pyproject.toml powered isolated build model.

uv_python_preference

This flag, set on a tox environment level, controls how uv select the Python interpreter.

By default, uv will attempt to use Python versions found on the system and only download managed interpreters when necessary. However, It is possible to adjust uv's Python version selection preference with the python-preference option.

system_site_packages (sitepackages)

Create virtual environments that also have access to globally installed packages. Note the default value may be overwritten by the VIRTUALENV_SYSTEM_SITE_PACKAGES environment variable. This flag works the same way as the one from tox native virtualenv implementation.

Package installation

We use uv pip to install packages into the virtual environment. The behavior of this can be configured via the following options:

uv_resolution

This flag, set on a tox environment level, informs uv of the desired resolution strategy:

  • highest - (default) selects the highest version of a package satisfying the constraints.
  • lowest - install the lowest compatible versions for all dependencies, both direct and transitive.
  • lowest-direct - opt for the lowest compatible versions for all direct dependencies, while using the latest compatible versions for all transitive dependencies.

This is an uv specific feature that may be used as an alternative to frozen constraints for test environments if the intention is to validate the lower bounds of your dependencies during test executions.

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

tox_uv-1.26.1.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

tox_uv-1.26.1-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file tox_uv-1.26.1.tar.gz.

File metadata

  • Download URL: tox_uv-1.26.1.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for tox_uv-1.26.1.tar.gz
Algorithm Hash digest
SHA256 241cc530b4a80436c4487977c8303d9aace398c6561d5e7d8845606fa7d482ab
MD5 7f1c694884a7ab54adbfc3f946943239
BLAKE2b-256 cf0098e564731fc361cc2f1e39c58d2feb0b4c9f9a7cb06f0c769cdeb9a98004

See more details on using hashes here.

Provenance

The following attestation bundles were made for tox_uv-1.26.1.tar.gz:

Publisher: release.yaml on tox-dev/tox-uv

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

File details

Details for the file tox_uv-1.26.1-py3-none-any.whl.

File metadata

  • Download URL: tox_uv-1.26.1-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for tox_uv-1.26.1-py3-none-any.whl
Algorithm Hash digest
SHA256 edc25b254e5cdbb13fc5d23d6d05b511dee562ab72b0e99da4a874a78018c38e
MD5 0299640c2e5f4c6c2ca0fe97a847f63c
BLAKE2b-256 fa0be47c1bb2bc9e20b22a6913ea2162b7bb5729d38924fa2c1d4eaf95d3b36f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tox_uv-1.26.1-py3-none-any.whl:

Publisher: release.yaml on tox-dev/tox-uv

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 Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page