Skip to content

Commit

Permalink
Drop 3.8 and uv sync now works in verbose mode same way as pip (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat authored Oct 11, 2024
1 parent 2500a69 commit 268477f
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 29 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
- "3.11"
- "3.10"
- "3.9"
- "3.8"
- type
- dev
- pkg_meta
Expand All @@ -37,7 +36,6 @@ jobs:
with:
enable-cache: true
cache-dependency-glob: "pyproject.toml"
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install tox
run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv
- name: Install Python
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies: ["tomli>=2.0.1"]
additional_dependencies: ["tomli>=2.0.2"]
- repo: https://github.com/tox-dev/tox-ini-fmt
rev: "1.4.1"
hooks:
Expand Down
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ license = "MIT"
maintainers = [
{ name = "Bernát Gábor", email = "[email protected]" },
]
requires-python = ">=3.8"
requires-python = ">=3.9"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand All @@ -41,11 +40,10 @@ dynamic = [
"version",
]
dependencies = [
"importlib-resources>=6.4.5; python_version<'3.9'",
"packaging>=24.1",
"tox<5,>=4.20",
"tox<5,>=4.21.2",
"typing-extensions>=4.12.2; python_version<'3.10'",
"uv<1,>=0.4.12",
"uv<1,>=0.4.18",
]
optional-dependencies.testing = [
"covdefaults>=2.3",
Expand Down Expand Up @@ -74,7 +72,6 @@ version.source = "vcs"
line-length = 120

[tool.ruff]
target-version = "py38"
line-length = 120
format.preview = true
format.docstring-code-line-length = 100
Expand Down Expand Up @@ -155,3 +152,6 @@ overrides = [
"uv.*",
], ignore_missing_imports = true },
]

[tool.uv]
cache-keys = [ { file = "pyproject.toml" }, { git = true } ]
3 changes: 2 additions & 1 deletion src/tox_uv/_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

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

from packaging.requirements import Requirement
from packaging.utils import parse_sdist_filename, parse_wheel_filename
Expand Down
8 changes: 5 additions & 3 deletions src/tox_uv/_run_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING, Set, cast
from typing import TYPE_CHECKING, cast

from tox.execute.request import StdinSource
from tox.tox_env.python.package import SdistPackage, WheelPackage
Expand Down Expand Up @@ -49,14 +49,16 @@ def register_config(self) -> None:
def _setup_env(self) -> None:
super()._setup_env()
cmd = ["uv", "sync", "--frozen"]
for extra in cast(Set[str], sorted(self.conf["extras"])):
for extra in cast(set[str], sorted(self.conf["extras"])):
cmd.extend(("--extra", extra))
if not self.conf["with_dev"]:
cmd.append("--no-dev")
install_pkg = getattr(self.options, "install_pkg", None)
if install_pkg is not None:
cmd.append("--no-install-project")
outcome = self.execute(cmd, stdin=StdinSource.OFF, run_id="uv-sync", show=False)
if self.options.verbosity > 2: # noqa: PLR2004
cmd.append("-v")
outcome = self.execute(cmd, stdin=StdinSource.OFF, run_id="uv-sync", show=self.options.verbosity > 1)
outcome.assert_success()
if install_pkg is not None:
path = Path(install_pkg)
Expand Down
9 changes: 3 additions & 6 deletions src/tox_uv/_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from functools import cached_property
from pathlib import Path
from platform import python_implementation
from typing import TYPE_CHECKING, Any, Literal, Optional, Type, cast
from typing import TYPE_CHECKING, Any, Literal, Optional, Type, cast # noqa: UP035

from tox.execute.local_sub_process import LocalSubProcessExecutor
from tox.execute.request import StdinSource
Expand All @@ -25,10 +25,7 @@
else: # pragma: no cover (<py310)
from typing_extensions import TypeAlias

if sys.version_info >= (3, 9): # pragma: no cover (py39+)
from importlib.resources import as_file, files
else: # pragma: no cover (py38+)
from importlib_resources import as_file, files
from importlib.resources import as_file, files

if TYPE_CHECKING:
from tox.execute.api import Execute
Expand Down Expand Up @@ -62,7 +59,7 @@ def register_config(self) -> None:
# The cast(...) might seems superfluous but removing it makes mypy crash. The problem isy on tox typing side.
self.conf.add_config(
keys=["uv_python_preference"],
of_type=cast(Type[Optional[PythonPreference]], Optional[PythonPreference]),
of_type=cast(Type[Optional[PythonPreference]], Optional[PythonPreference]), # noqa: UP006
default=None,
desc=(
"Whether to prefer using Python installations that are already"
Expand Down
16 changes: 9 additions & 7 deletions tests/test_tox_uv_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ def test_uv_lock_list_dependencies_command(tox_project: ToxProjectCreator) -> No
"venv",
[uv, "venv", "-p", sys.executable, "--allow-existing", "-v", str(project.path / ".tox" / "py")],
),
("py", "uv-sync", ["uv", "sync", "--frozen", "--extra", "dev", "--extra", "type", "--no-dev"]),
("py", "uv-sync", ["uv", "sync", "--frozen", "--extra", "dev", "--extra", "type", "--no-dev", "-v"]),
("py", "freeze", [uv, "--color", "never", "pip", "freeze"]),
("py", "commands[0]", ["python", "hello"]),
]
assert calls == expected


def test_uv_lock_command(tox_project: ToxProjectCreator) -> None:
@pytest.mark.parametrize("verbose", [True, False])
def test_uv_lock_command(tox_project: ToxProjectCreator, verbose: bool) -> None:
project = tox_project({
"tox.ini": """
[testenv]
Expand All @@ -52,18 +53,19 @@ def test_uv_lock_command(tox_project: ToxProjectCreator) -> None:
"""
})
execute_calls = project.patch_execute(lambda r: 0 if r.run_id != "venv" else None)
result = project.run("-vv")
result = project.run(*["-vv"] if verbose else [])
result.assert_success()

calls = [(i[0][0].conf.name, i[0][3].run_id, i[0][3].cmd) for i in execute_calls.call_args_list]
uv = find_uv_bin()
v_args = ["-v"] if verbose else []
expected = [
(
"py",
"venv",
[uv, "venv", "-p", sys.executable, "--allow-existing", "-v", str(project.path / ".tox" / "py")],
[uv, "venv", "-p", sys.executable, "--allow-existing", *v_args, str(project.path / ".tox" / "py")],
),
("py", "uv-sync", ["uv", "sync", "--frozen", "--extra", "dev", "--extra", "type", "--no-dev"]),
("py", "uv-sync", ["uv", "sync", "--frozen", "--extra", "dev", "--extra", "type", "--no-dev", *v_args]),
("py", "commands[0]", ["python", "hello"]),
]
assert calls == expected
Expand All @@ -89,7 +91,7 @@ def test_uv_lock_with_dev(tox_project: ToxProjectCreator) -> None:
"venv",
[uv, "venv", "-p", sys.executable, "--allow-existing", "-v", str(project.path / ".tox" / "py")],
),
("py", "uv-sync", ["uv", "sync", "--frozen"]),
("py", "uv-sync", ["uv", "sync", "--frozen", "-v"]),
]
assert calls == expected

Expand Down Expand Up @@ -122,7 +124,7 @@ def test_uv_lock_with_install_pkg(tox_project: ToxProjectCreator, name: str) ->
"venv",
[uv, "venv", "-p", sys.executable, "--allow-existing", "-v", str(project.path / ".tox" / "py")],
),
("py", "uv-sync", ["uv", "sync", "--frozen", "--no-dev", "--no-install-project"]),
("py", "uv-sync", ["uv", "sync", "--frozen", "--no-dev", "--no-install-project", "-v"]),
(
"py",
"install_external",
Expand Down
5 changes: 2 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ env_list =
3.11
3.10
3.9
3.8
type
pkg_meta
skip_missing_interpreters = true
Expand Down Expand Up @@ -38,7 +37,7 @@ commands =
description = format the code base to adhere to our styles, and complain about what we cannot do automatically
skip_install = true
deps =
pre-commit-uv>=4.1.2
pre-commit-uv>=4.1.3
commands =
pre-commit run --all-files --show-diff-on-failure

Expand All @@ -56,7 +55,7 @@ skip_install = true
deps =
check-wheel-contents>=0.6
twine>=5.1.1
uv>=0.4.12
uv>=0.4.18
commands =
uv build --sdist --wheel --out-dir {env_tmp_dir} .
twine check {env_tmp_dir}{/}*
Expand Down

0 comments on commit 268477f

Please sign in to comment.