Skip to content

Commit

Permalink
Add support for system_site_packages matching tox own behavior
Browse files Browse the repository at this point in the history
Fixes: #109

# Conflicts:
#	tests/test_tox_uv_venv.py
  • Loading branch information
ssbarnea committed Dec 28, 2024
1 parent 75dcdc1 commit 960d632
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/tox_uv/_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from platform import python_implementation
from typing import TYPE_CHECKING, Any, Literal, Optional, Type, cast # noqa: UP035

from tox.config.loader.str_convert import StrConvert
from tox.execute.local_sub_process import LocalSubProcessExecutor
from tox.execute.request import StdinSource
from tox.tox_env.errors import Skip
Expand Down Expand Up @@ -56,6 +57,15 @@ def register_config(self) -> None:
default=False,
desc="add seed packages to the created venv",
)
self.conf.add_config(
keys=["system_site_packages", "sitepackages"],
of_type=bool,
default=lambda conf, name: StrConvert().to_bool( # noqa: ARG005
self.environment_variables.get("VIRTUALENV_SYSTEM_SITE_PACKAGES", "False"),
),
desc="create virtual environments that also have access to globally installed packages.",
)

# 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 Down Expand Up @@ -195,6 +205,8 @@ def create_python_env(self) -> None:
cmd.append("-v")
if self.conf["uv_seed"]:
cmd.append("--seed")
if self.conf["system_site_packages"]:
cmd.append("--system-site-packages")
if self.conf["uv_python_preference"]:
cmd.extend(["--python-preference", self.conf["uv_python_preference"]])
cmd.append(str(self.venv_dir))
Expand Down
6 changes: 6 additions & 0 deletions tests/test_tox_uv_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ def test_uv_venv_spec_full_implementation(
assert f"no interpreter found for {expected_name} 9.99" in result.err.lower()


def test_uv_venv_system_site_packages(tox_project: ToxProjectCreator) -> None:
project = tox_project({"tox.ini": "[testenv]\npackage=skip\nsystem_site_packages=true"})
result = project.run("-vv")
result.assert_success()


@pytest.fixture
def other_interpreter_exe() -> pathlib.Path: # pragma: no cover
"""Returns an interpreter executable path that is not the exact same as `sys.executable`.
Expand Down

0 comments on commit 960d632

Please sign in to comment.