From 0c0c0c60ccc24969316d4b8a641c8c575752ce8b Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Thu, 13 Feb 2025 15:30:50 -0600 Subject: [PATCH] Add test coverage for `--python-version` overriding `UV_PYTHON` entirely --- crates/uv/tests/it/pip_compile.rs | 83 +++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 26 deletions(-) diff --git a/crates/uv/tests/it/pip_compile.rs b/crates/uv/tests/it/pip_compile.rs index bcb1500317a2..4b12871f69e4 100644 --- a/crates/uv/tests/it/pip_compile.rs +++ b/crates/uv/tests/it/pip_compile.rs @@ -1737,13 +1737,14 @@ fn compile_python_build_version_different_than_target() -> Result<()> { .arg("requirements.in") .arg("--python-version") .arg("3.12") - .env(EnvVars::UV_PYTHON, "3.11") + .arg("-p") + .arg("cpython@3.11") .env_remove(EnvVars::VIRTUAL_ENV), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by uv via the following command: - # uv pip compile --cache-dir [CACHE_DIR] requirements.in --python-version 3.12 + # uv pip compile --cache-dir [CACHE_DIR] requirements.in --python-version 3.12 -p cpython@3.11 black==23.10.[X] # via -r requirements.in click==8.1.7 @@ -1762,18 +1763,51 @@ fn compile_python_build_version_different_than_target() -> Result<()> { "### ); + // If we can't find the interpreter, we fail uv_snapshot!(context.filters(), context.pip_compile() .arg("requirements.in") .arg("--python-version") .arg("3.12") .arg("-p") - .arg("cpython@3.11") + .arg("pypy@3.11") + .env_remove(EnvVars::VIRTUAL_ENV), @r###" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + error: No interpreter found for PyPy 3.11 in [PYTHON SOURCES] + "### + ); + + uv_snapshot!(context.filters(), context.pip_compile() + .arg("requirements.in") + .arg("--python-version") + .arg("3.12") + .arg("-p") + .arg("3.13") + .env_remove(EnvVars::VIRTUAL_ENV), @r###" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + error: No interpreter found for Python 3.13 in [PYTHON SOURCES] + "### + ); + + // `UV_PYTHON` is ignored if `--python-version` is set + uv_snapshot!(context.filters(), context.pip_compile() + .arg("requirements.in") + .arg("--python-version") + .arg("3.12") + .env(EnvVars::UV_PYTHON, "3.11") .env_remove(EnvVars::VIRTUAL_ENV), @r###" success: true exit_code: 0 ----- stdout ----- # This file was autogenerated by uv via the following command: - # uv pip compile --cache-dir [CACHE_DIR] requirements.in --python-version 3.12 -p cpython@3.11 + # uv pip compile --cache-dir [CACHE_DIR] requirements.in --python-version 3.12 black==23.10.[X] # via -r requirements.in click==8.1.7 @@ -1792,36 +1826,33 @@ fn compile_python_build_version_different_than_target() -> Result<()> { "### ); - // If we can't find the interpreter, we fail - uv_snapshot!(context.filters(), context.pip_compile() - .arg("requirements.in") - .arg("--python-version") - .arg("3.12") - .arg("-p") - .arg("pypy@3.11") - .env_remove(EnvVars::VIRTUAL_ENV), @r###" - success: false - exit_code: 2 - ----- stdout ----- - - ----- stderr ----- - error: No interpreter found for PyPy 3.11 in [PYTHON SOURCES] - "### - ); - + // `UV_PYTHON` is ignored if `--python-version` is set uv_snapshot!(context.filters(), context.pip_compile() .arg("requirements.in") .arg("--python-version") .arg("3.12") - .arg("-p") - .arg("3.13") + .env(EnvVars::UV_PYTHON, "pypy") .env_remove(EnvVars::VIRTUAL_ENV), @r###" - success: false - exit_code: 2 + success: true + exit_code: 0 ----- stdout ----- + # This file was autogenerated by uv via the following command: + # uv pip compile --cache-dir [CACHE_DIR] requirements.in --python-version 3.12 + black==23.10.[X] + # via -r requirements.in + click==8.1.7 + # via black + mypy-extensions==1.0.0 + # via black + packaging==24.0 + # via black + pathspec==0.12.1 + # via black + platformdirs==4.2.0 + # via black ----- stderr ----- - error: No interpreter found for Python 3.13 in [PYTHON SOURCES] + Resolved 6 packages in [TIME] "### );