From 77f9b1a8997deae443db9e30b1ed809890815683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Fri, 16 Feb 2024 16:53:59 -0800 Subject: [PATCH] Use uv for packaging environments too (#7) --- README.md | 20 ++++++++++++++------ pyproject.toml | 2 +- src/tox_uv/_package.py | 24 ++++++++++++++++++++++++ src/tox_uv/_run.py | 4 ++-- src/tox_uv/plugin.py | 3 +++ tests/test_tox_uv_package.py | 4 +++- 6 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 src/tox_uv/_package.py diff --git a/README.md b/README.md index a2a0b66..fcb01b4 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/pyproject.toml b/pyproject.toml index a5e4a5e..f935b1a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ dynamic = [ "version", ] dependencies = [ - "tox<5,>=4.12.1", + "tox<5,>=4.13", "uv<1,>=0.1.2", ] optional-dependencies.test = [ diff --git a/src/tox_uv/_package.py b/src/tox_uv/_package.py new file mode 100644 index 0000000..8c87c9c --- /dev/null +++ b/src/tox_uv/_package.py @@ -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", +] diff --git a/src/tox_uv/_run.py b/src/tox_uv/_run.py index defe899..c0bff0d 100644 --- a/src/tox_uv/_run.py +++ b/src/tox_uv/_run.py @@ -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: diff --git a/src/tox_uv/plugin.py b/src/tox_uv/plugin.py index c60bda9..bd9db32 100644 --- a/src/tox_uv/plugin.py +++ b/src/tox_uv/plugin.py @@ -6,6 +6,7 @@ from tox.plugin import impl +from ._package import UvVenvCmdBuilder, UvVenvPep517Packager from ._run import UvVenvRunner if TYPE_CHECKING: @@ -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 diff --git a/tests/test_tox_uv_package.py b/tests/test_tox_uv_package.py index 2b3e05f..045a692 100644 --- a/tests/test_tox_uv_package.py +++ b/tests/test_tox_uv_package.py @@ -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()