Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/tox_uv/_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ def uv_python_preference_default(conf: object, name: object) -> str: # noqa: AR
else os.environ.get("UV_PYTHON_PREFERENCE", "system")
)

def uv_python_preference_post_process(value: str | None) -> str:
if value is not None:
return value.lower()
return "system"

# 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"],
Expand All @@ -90,6 +95,7 @@ def uv_python_preference_default(conf: object, name: object) -> str: # noqa: AR
" interpreters with all tox environments and avoid accidental"
" downloading of other interpreters."
),
post_process=uv_python_preference_post_process,
)

def python_cache(self) -> dict[str, Any]:
Expand Down
29 changes: 29 additions & 0 deletions tests/test_tox_uv_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,35 @@ def test_uv_env_python_preference(
assert env_bin_dir in result.out


@pytest.mark.parametrize(
"env",
["3.10", "3.10-onlymanaged"],
)
def test_uv_env_python_preference_complex(
tox_project: ToxProjectCreator,
*,
env: str,
) -> None:
project = tox_project({
"tox.ini": (
"[tox]\n"
"env_list =\n"
" 3.10\n"
"[testenv]\n"
"package=skip\n"
"uv_python_preference=\n"
" onlymanaged: only-managed\n"
"commands=python -c 'print(\"{env_python}\")'"
)
})
result = project.run("-vv", "-e", env)
result.assert_success()

exe = "python.exe" if sys.platform == "win32" else "python"
env_bin_dir = str(project.path / ".tox" / env / ("Scripts" if sys.platform == "win32" else "bin") / exe)
assert env_bin_dir in result.out


def test_uv_env_site_package_dir_run(tox_project: ToxProjectCreator) -> None:
project = tox_project({"tox.ini": "[testenv]\npackage=skip\ncommands=python -c 'print(\"{envsitepackagesdir}\")'"})
result = project.run("-vv")
Expand Down