diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index a371123..99a0ca3 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -37,14 +37,17 @@ jobs: enable-cache: true cache-dependency-glob: "pyproject.toml" - name: Install tox - run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv + run: uv tool install --python-preference only-managed --python 3.13 tox --with . - name: Install Python if: startsWith(matrix.env, '3.') && matrix.env != '3.13' run: uv python install --python-preference only-managed ${{ matrix.env }} - name: Setup test suite run: tox run -vv --notest --skip-missing-interpreters false -e ${{ matrix.env }} + env: + UV_PYTHON_PREFERENCE: "only-managed" - name: Run test suite run: tox run --skip-pkg-install -e ${{ matrix.env }} env: PYTEST_ADDOPTS: "-vv --durations=20" DIFF_AGAINST: HEAD + UV_PYTHON_PREFERENCE: "only-managed" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f9cf1dc..9200d50 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: rev: v2.3.0 hooks: - id: codespell - additional_dependencies: ["tomli>=2.0.2"] + additional_dependencies: ["tomli>=2.2.1"] - repo: https://github.com/tox-dev/tox-ini-fmt rev: "1.4.1" hooks: diff --git a/pyproject.toml b/pyproject.toml index ba94054..60278cb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ build-backend = "hatchling.build" requires = [ "hatch-vcs>=0.4", - "hatchling>=1.25", + "hatchling>=1.27", ] [project] @@ -40,10 +40,10 @@ dynamic = [ "version", ] dependencies = [ - "packaging>=24.1", - "tox>=4.21.2,<5", + "packaging>=24.2", + "tox>=4.24.1,<5", "typing-extensions>=4.12.2; python_version<'3.10'", - "uv>=0.4.18,<1", + "uv>=0.5.21,<1", ] urls.Changelog = "https://github.com/tox-dev/tox-uv/releases" urls.Documentation = "https://github.com/tox-dev/tox-uv#tox-uv" @@ -62,14 +62,14 @@ dev = [ test = [ "covdefaults>=2.3", "devpi-process>=1.0.2", - "diff-cover>=9.2", - "pytest>=8.3.3", - "pytest-cov>=5", + "diff-cover>=9.2.1", + "pytest>=8.3.4", + "pytest-cov>=6", "pytest-mock>=3.14", ] -type = [ "mypy==1.11.2", { include-group = "test" } ] -lint = [ "pre-commit-uv>=4.1.3" ] -pkg-meta = [ "check-wheel-contents>=0.6", "twine>=5.1.1", "uv>=0.4.18" ] +type = [ "mypy==1.14.1", { include-group = "test" } ] +lint = [ "pre-commit-uv>=4.1.4" ] +pkg-meta = [ "check-wheel-contents>=0.6.1", "twine>=6.1", "uv>=0.5.21" ] [tool.hatch] build.hooks.vcs.version-file = "src/tox_uv/version.py" diff --git a/src/tox_uv/_venv.py b/src/tox_uv/_venv.py index 80b91ac..aa6fd42 100644 --- a/src/tox_uv/_venv.py +++ b/src/tox_uv/_venv.py @@ -73,7 +73,7 @@ def register_config(self) -> None: self.conf.add_config( keys=["uv_python_preference"], of_type=cast("Type[Optional[PythonPreference]]", Optional[PythonPreference]), # noqa: UP006 - default="system", + default=lambda conf, name: self.environment_variables.get("UV_PYTHON_PREFERENCE", "system"), # noqa: ARG005 desc=( "Whether to prefer using Python installations that are already" " present on the system, or those that are downloaded and" diff --git a/tests/conftest.py b/tests/conftest.py index c47212e..ed5c923 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -33,6 +33,11 @@ def demo_pkg_inline(root: Path) -> Path: return root / "demo_pkg_inline" +@pytest.fixture +def clear_python_preference_env_var(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.delenv("UV_PYTHON_PREFERENCE", raising=False) + + pytest_plugins = [ "tox.pytest", ] diff --git a/tests/test_tox_uv_lock.py b/tests/test_tox_uv_lock.py index a6e20aa..e789c26 100644 --- a/tests/test_tox_uv_lock.py +++ b/tests/test_tox_uv_lock.py @@ -10,6 +10,7 @@ from tox.pytest import ToxProjectCreator +@pytest.mark.usefixtures("clear_python_preference_env_var") def test_uv_lock_list_dependencies_command(tox_project: ToxProjectCreator) -> None: project = tox_project({ "tox.ini": """ @@ -70,6 +71,7 @@ def test_uv_lock_list_dependencies_command(tox_project: ToxProjectCreator) -> No assert calls[i] == expected[i] +@pytest.mark.usefixtures("clear_python_preference_env_var") @pytest.mark.parametrize("verbose", ["", "-v", "-vv", "-vvv"]) def test_uv_lock_command(tox_project: ToxProjectCreator, verbose: str) -> None: project = tox_project({ @@ -131,6 +133,7 @@ def test_uv_lock_command(tox_project: ToxProjectCreator, verbose: str) -> None: assert show_uv_output is (bool(verbose)) +@pytest.mark.usefixtures("clear_python_preference_env_var") def test_uv_lock_with_dev(tox_project: ToxProjectCreator) -> None: project = tox_project({ "tox.ini": """ @@ -166,6 +169,7 @@ def test_uv_lock_with_dev(tox_project: ToxProjectCreator) -> None: assert calls == expected +@pytest.mark.usefixtures("clear_python_preference_env_var") @pytest.mark.parametrize( "name", [ @@ -229,6 +233,7 @@ def test_uv_lock_with_install_pkg(tox_project: ToxProjectCreator, name: str) -> assert calls == expected +@pytest.mark.usefixtures("clear_python_preference_env_var") def test_uv_sync_extra_flags(tox_project: ToxProjectCreator) -> None: project = tox_project({ "tox.ini": """ @@ -281,6 +286,7 @@ def test_uv_sync_extra_flags(tox_project: ToxProjectCreator) -> None: assert calls == expected +@pytest.mark.usefixtures("clear_python_preference_env_var") def test_uv_sync_extra_flags_toml(tox_project: ToxProjectCreator) -> None: project = tox_project({ "tox.toml": """ @@ -333,6 +339,7 @@ def test_uv_sync_extra_flags_toml(tox_project: ToxProjectCreator) -> None: assert calls == expected +@pytest.mark.usefixtures("clear_python_preference_env_var") def test_uv_sync_dependency_groups(tox_project: ToxProjectCreator) -> None: project = tox_project({ "tox.toml": """ diff --git a/tests/test_tox_uv_venv.py b/tests/test_tox_uv_venv.py index bfc1225..ea1e47d 100644 --- a/tests/test_tox_uv_venv.py +++ b/tests/test_tox_uv_venv.py @@ -41,6 +41,36 @@ def test_uv_venv_pass_env(tox_project: ToxProjectCreator) -> None: assert "PKG_CONFIG_PATH" in pass_through +@pytest.mark.usefixtures("clear_python_preference_env_var") +def test_uv_venv_preference_system_by_default(tox_project: ToxProjectCreator) -> None: + project = tox_project({"tox.ini": "[testenv]"}) + + result = project.run("c", "-k", "uv_python_preference") + result.assert_success() + + parser = ConfigParser() + parser.read_string(result.out) + got = parser["testenv:py"]["uv_python_preference"] + + assert got == "system" + + +def test_uv_venv_preference_override_via_env_var( + tox_project: ToxProjectCreator, monkeypatch: pytest.MonkeyPatch +) -> None: + project = tox_project({"tox.ini": "[testenv]"}) + monkeypatch.setenv("UV_PYTHON_PREFERENCE", "only-managed") + + result = project.run("c", "-k", "uv_python_preference") + result.assert_success() + + parser = ConfigParser() + parser.read_string(result.out) + got = parser["testenv:py"]["uv_python_preference"] + + assert got == "only-managed" + + 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}"}) diff --git a/tox.ini b/tox.ini index 42884ba..1cd4f95 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] requires = - tox>=4.2 - tox-uv>=1.11.3 + tox>=4.24.1 + tox-uv>=1.19.1 env_list = fix 3.13 @@ -36,7 +36,7 @@ dependency_groups = test 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.3 + pre-commit-uv>=4.1.4 commands = pre-commit run --all-files --show-diff-on-failure