Skip to content

Commit

Permalink
Pass through often used environment variables
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <[email protected]>
  • Loading branch information
gaborbernat committed Feb 21, 2024
1 parent 7f19683 commit fc7c985
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/tox_uv/_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ def environment_variables(self) -> dict[str, str]:
env["VIRTUAL_ENV"] = str(self.venv_dir)
return env

def _default_pass_env(self) -> list[str]:
env = super()._default_pass_env()
env.append("UV_*") # accept uv env vars
if sys.platform == "darwin": # pragma: darwin cover
env.append("MACOSX_DEPLOYMENT_TARGET") # needed for macOS binary builds
env.append("PKG_CONFIG_PATH") # needed for binary builds
return env

def create_python_env(self) -> None:
base = self.base_python.version_info
version_spec = f"{base.major}.{base.minor}" if base.minor else f"{base.major}"
Expand Down
16 changes: 16 additions & 0 deletions tests/test_tox_uv_venv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import sys
from configparser import ConfigParser
from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand All @@ -13,6 +14,21 @@ def test_uv_venv_self(tox_project: ToxProjectCreator) -> None:
result.assert_success()


def test_uv_venv_pass_env(tox_project: ToxProjectCreator) -> None:
project = tox_project({"tox.ini": "[testenv]\npackage=skip"})
result = project.run("c", "-k", "pass_env")
result.assert_success()

parser = ConfigParser()
parser.read_string(result.out)
pass_through = set(parser["testenv:py"]["pass_env"].splitlines())

if sys.platform == "darwin": # pragma: darwin cover
assert "MACOSX_DEPLOYMENT_TARGET" in pass_through
assert "UV_*" in pass_through
assert "PKG_CONFIG_PATH" in pass_through


def test_uv_venv_spec(tox_project: ToxProjectCreator) -> None:
ver = sys.version_info
project = tox_project({"tox.ini": f"[testenv]\npackage=skip\nbase_python={ver.major}.{ver.minor}"})
Expand Down

0 comments on commit fc7c985

Please sign in to comment.