Skip to content

Commit

Permalink
Use uv for packaging environments too (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat authored Feb 17, 2024
1 parent fbea9f6 commit 77f9b1a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@
**tox-uv** is a tox plugin which replaces virtualenv and pip with uv your tox environments.
Note that you will get both the benefits (performance) or downsides (bugs) of uv.

Simply install `tox-uv` into the environment your tox is installed and will replace virtualenv and pip in the tox
run environments with uv.
## How to use

Note: currently we haven't implemented uv support for packaging environments, so only your run tox environments will
use uv.
Install `tox-uv` into the environment of your tox and will replace virtualenv and pip for all runs:

```bash
python -m pip install tox tox-uv
python -m tox r -e py312 # will use uv
```

## Configuration

- `uv-venv-runner` is the ID for the tox environments [runner](https://tox.wiki/en/4.12.1/config.html#runner).
- `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_seed

This flag controls if the created virtual environment injects pip/setuptools/wheel into the created virtual environment
or not. By default, is off.
This flag, set on a tox environment level, controls if the created virtual environment injects pip/setuptools/wheel into
the created virtual environment or not. By default, is off. You will need to set this if you have a project that uses
the old legacy editable mode, or your project does not support the `pyprooject.toml` powered isolated build model.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dynamic = [
"version",
]
dependencies = [
"tox<5,>=4.12.1",
"tox<5,>=4.13",
"uv<1,>=0.1.2",
]
optional-dependencies.test = [
Expand Down
24 changes: 24 additions & 0 deletions src/tox_uv/_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import annotations

from tox.tox_env.python.virtual_env.package.cmd_builder import VenvCmdBuilder
from tox.tox_env.python.virtual_env.package.pyproject import Pep517VenvPackager

from ._venv import UvVenv


class UvVenvPep517Packager(Pep517VenvPackager, UvVenv):
@staticmethod
def id() -> str:
return "uv-venv-pep-517"


class UvVenvCmdBuilder(VenvCmdBuilder, UvVenv):
@staticmethod
def id() -> str:
return "uv-venv-cmd-builder"


__all__ = [
"UvVenvCmdBuilder",
"UvVenvPep517Packager",
]
4 changes: 2 additions & 2 deletions src/tox_uv/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def id() -> str:

@property
def _package_tox_env_type(self) -> str:
return "virtualenv-pep-517"
return "uv-venv-pep-517"

@property
def _external_pkg_tox_env_type(self) -> str:
return "virtualenv-cmd-builder" # pragma: no cover
return "uv-venv-cmd-builder" # pragma: no cover

@property
def default_pkg_type(self) -> str:
Expand Down
3 changes: 3 additions & 0 deletions src/tox_uv/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from tox.plugin import impl

from ._package import UvVenvCmdBuilder, UvVenvPep517Packager
from ._run import UvVenvRunner

if TYPE_CHECKING:
Expand All @@ -15,6 +16,8 @@
@impl
def tox_register_tox_env(register: ToxEnvRegister) -> None:
register.add_run_env(UvVenvRunner)
register.add_package_env(UvVenvPep517Packager)
register.add_package_env(UvVenvCmdBuilder)
register._default_run_env = UvVenvRunner.id() # noqa: SLF001


Expand Down
4 changes: 3 additions & 1 deletion tests/test_tox_uv_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def test_uv_package_editable(tox_project: ToxProjectCreator, package: str, demo_


def test_uv_package_editable_legacy(tox_project: ToxProjectCreator, demo_pkg_setuptools: Path) -> None:
project = tox_project({"tox.ini": "[testenv]\npackage=editable-legacy"}, base=demo_pkg_setuptools)
project = tox_project(
{"tox.ini": "[testenv]\npackage=editable-legacy\n[testenv:.pkg]\nuv_seed=true"}, base=demo_pkg_setuptools
)
result = project.run()
result.assert_success()

Expand Down

0 comments on commit 77f9b1a

Please sign in to comment.