Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat committed Feb 21, 2025
1 parent 268da4d commit 37432ec
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 64 deletions.
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,13 @@ Therefore, options like `deps` are ignored (and all others

### `package`

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

- `wheel`
- `editable`
- `skip`
- `from-dir`
- `from-dir-editable`

By default will do `editable`.

The latter two options delegate to `uv`'s built-in packager and dependency resolver, and will respect
`[tool.uv.sources]` in `pyproject.toml`
- `wheel`,
- `editable` (default),
- `skip`,
- `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`).

### `extras`

Expand Down
18 changes: 9 additions & 9 deletions src/tox_uv/_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from __future__ import annotations

import itertools
import logging
from collections import defaultdict
from collections.abc import Sequence
from itertools import chain
from typing import TYPE_CHECKING, Any, Final

from packaging.requirements import Requirement
Expand All @@ -17,7 +17,7 @@
from tox.tox_env.python.pip.req_file import PythonDeps
from uv import find_uv_bin

from ._package_types import UvFromDirEditablePackage, UvFromDirPackage
from ._package import UvEditablePackage, UvPackage

if TYPE_CHECKING:
from tox.config.main import Config
Expand Down Expand Up @@ -117,12 +117,12 @@ def _install_list_of_deps( # noqa: C901, PLR0912
elif isinstance(arg, EditableLegacyPackage):
groups["req"].extend(str(i) for i in arg.deps)
groups["dev_pkg"].append(str(arg.path))
elif isinstance(arg, UvFromDirPackage):
elif isinstance(arg, UvPackage):
extras_suffix = f"[{','.join(arg.extras)}]" if arg.extras else ""
groups["pkg_from_dir"].append(f"{arg.path}{extras_suffix}")
elif isinstance(arg, UvFromDirEditablePackage):
groups["uv"].append(f"{arg.path}{extras_suffix}")
elif isinstance(arg, UvEditablePackage):
extras_suffix = f"[{','.join(arg.extras)}]" if arg.extras else ""
groups["dev_pkg_from_dir"].append(f"{arg.path}{extras_suffix}")
groups["uv_editable"].append(f"{arg.path}{extras_suffix}")
else: # pragma: no branch
_LOGGER.warning("uv install %r", arg) # pragma: no cover
raise SystemExit(1) # pragma: no cover
Expand All @@ -139,10 +139,10 @@ def _install_list_of_deps( # noqa: C901, PLR0912
if new_deps: # pragma: no branch
self._execute_installer(new_deps, req_of_type)
install_args = ["--reinstall"]
if groups["pkg_from_dir"]:
if groups["uv"]:
self._execute_installer(install_args + groups["pkg_from_dir"], of_type)
if groups["dev_pkg_from_dir"]:
requirements = list(itertools.chain.from_iterable(("-e", entry) for entry in groups["dev_pkg_from_dir"]))
if groups["uv_editable"]:
requirements = list(chain.from_iterable(("-e", entry) for entry in groups["dev_pkg_from_dir"]))
self._execute_installer(install_args + requirements, of_type)
install_args.append("--no-deps")
if groups["pkg"]:
Expand Down
39 changes: 28 additions & 11 deletions src/tox_uv/_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,34 @@

from typing import TYPE_CHECKING

from tox.tox_env.python.package import PythonPathPackageWithDeps
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

if TYPE_CHECKING:
import pathlib
from collections.abc import Sequence

from tox.config.sets import EnvConfigSet
from tox.tox_env.package import Package

from ._package_types import UvFromDirEditablePackage, UvFromDirPackage
from ._venv import UvVenv

class UvBasePackage(PythonPathPackageWithDeps):
"""Package to be built and installed by uv directly."""

def __init__(self, path: pathlib.Path, extras: Sequence[str]) -> None:
super().__init__(path, ())
self.extras = extras


class UvPackage(UvBasePackage):
"""Package to be built and installed by uv directly as wheel."""


class UvEditablePackage(UvBasePackage):
"""Package to be built and installed by uv directly as editable wheel."""


class UvVenvPep517Packager(Pep517VenvPackager, UvVenv):
Expand All @@ -20,15 +39,11 @@ def id() -> str:

def perform_packaging(self, for_env: EnvConfigSet) -> list[Package]:
of_type: str = for_env["package"]
types = {
"from-dir": UvFromDirPackage,
"from-dir-editable": UvFromDirEditablePackage,
}
if of_type not in types:
return super().perform_packaging(for_env)

extras: list[str] = for_env["extras"]
return [types[of_type](self.core["tox_root"], extras)]
if of_type == "uv":
return [UvPackage(self.core["tox_root"], self.conf["extras"])]
if of_type == "uv-editable":
return [UvEditablePackage(self.core["tox_root"], self.conf["extras"])]
return super().perform_packaging(for_env)


class UvVenvCmdBuilder(VenvCmdBuilder, UvVenv):
Expand All @@ -38,6 +53,8 @@ def id() -> str:


__all__ = [
"UvEditablePackage",
"UvPackage",
"UvVenvCmdBuilder",
"UvVenvPep517Packager",
]
31 changes: 0 additions & 31 deletions src/tox_uv/_package_types.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/tox_uv/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def default_pkg_type(self) -> str:

@property
def _package_types(self) -> tuple[str, ...]:
return (*super()._package_types, "from-dir", "from-dir-editable")
return *super()._package_types, "uv", "uv-editable"


__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tox_uv_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_uv_package_use_default_from_file(tox_project: ToxProjectCreator) -> Non


@pytest.mark.parametrize("with_dash", [True, False], ids=["name_dash", "name_underscore"])
@pytest.mark.parametrize("package", ["sdist", "wheel", "editable", "from-dir", "from-dir-editable"])
@pytest.mark.parametrize("package", ["sdist", "wheel", "editable", "uv", "uv-editable"])
def test_uv_package_artifact(
tox_project: ToxProjectCreator, package: str, demo_pkg_inline: Path, with_dash: bool
) -> None:
Expand Down

0 comments on commit 37432ec

Please sign in to comment.