diff --git a/crates/uv/tests/pip_compile.rs b/crates/uv/tests/pip_compile.rs index 4e60c2d7d..8cc338610 100644 --- a/crates/uv/tests/pip_compile.rs +++ b/crates/uv/tests/pip_compile.rs @@ -6134,3 +6134,163 @@ fn dynamic_dependencies() -> Result<()> { Ok(()) } + +/// This tests the marker expressions emitted when depending on a package with +/// exciting markers like 'anyio'. +/// +/// NOTE: This test runs on `linux` only because some of `anyio`'s markers +/// involve querying the specific platform being used to run `uv pip compile`. +/// Since this test was developed on Linux, the marker expression generated is +/// coupled with the Linux platform. Other tests for other platforms could be +/// added. +#[cfg(target_os = "linux")] +#[test] +fn emit_marker_expression_exciting_linux() -> Result<()> { + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); + requirements_in.write_str("anyio")?; + + uv_snapshot!(context + .compile() + .arg("requirements.in") + .arg("--emit-marker-expression"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + # This file was autogenerated by uv via the following command: + # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in --emit-marker-expression + # Pinned dependencies known to be valid for: + # platform_system == 'Linux' and python_version == '3.12' and platform_python_implementation == 'CPython' + anyio==4.3.0 + idna==3.6 + # via anyio + sniffio==1.3.1 + # via anyio + + ----- stderr ----- + Resolved 3 packages in [TIME] + "###); + + Ok(()) +} + +/// This tests that the marker expression emitted accounts for markers directly +/// in `requirements.in`. +/// +/// NOTE: This test runs on `linux` only because it requires that `sys_platform +/// == 'linux'` evaluates to `true`. +#[cfg(target_os = "linux")] +#[test] +fn emit_marker_expression_direct() -> Result<()> { + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); + requirements_in.write_str("anyio ; sys_platform == 'linux'")?; + + uv_snapshot!(context + .compile() + .arg("requirements.in") + .arg("--emit-marker-expression"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + # This file was autogenerated by uv via the following command: + # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in --emit-marker-expression + # Pinned dependencies known to be valid for: + # python_version == '3.12' and platform_python_implementation == 'CPython' and sys_platform == 'linux' and platform_system == 'Linux' + anyio==4.3.0 + idna==3.6 + # via anyio + sniffio==1.3.1 + # via anyio + + ----- stderr ----- + Resolved 3 packages in [TIME] + "###); + + Ok(()) +} + +/// This tests that the marker expression emitted accounts for markers directly +/// in `requirements.in`, even when the marker evaluates to false on the +/// current platform. In this case, we set `sys_platform == 'macos'` so that on +/// Linux, this dependency is ignored. But the marker expression generated must +/// have `sys_platform == 'Linux'`, since the locked set of packages might be +/// different (and indeed are different) on other platforms. +/// +/// NOTE: This test runs on `linux` because it requires that `sys_platform +/// == 'macos'` evaluates to `false`. While this technically only requires +/// `not(target_os = "macos")`, the marker expression generated during test +/// development was on Linux. So we require Linux. +#[cfg(target_os = "linux")] +#[test] +fn emit_marker_expression_conditional() -> Result<()> { + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); + requirements_in.write_str("anyio ; sys_platform == 'macos'")?; + + uv_snapshot!(context + .compile() + .arg("requirements.in") + .arg("--emit-marker-expression"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + # This file was autogenerated by uv via the following command: + # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in --emit-marker-expression + # Pinned dependencies known to be valid for: + # sys_platform == 'linux' + + ----- stderr ----- + Resolved 0 packages in [TIME] + "###); + + Ok(()) +} + +/// This tests the marker expressions emitted when depending on a package with +/// a non-pypy dependency. Specifically, `pendulum` depends on `time-machine`, +/// but not when using pypy. +/// +/// NOTE: This test runs on `linux` because it was written on Linux. While the +/// marker expression itself doesn't have anything in it that couples it to +/// Linux, it is possible for the resolution to change on other platforms. For +/// example, on Windows, the `tzdata` dependency is excluded. (It's actually +/// not clear why. The `tzdata` dependency appears to be an unconditional +/// dependency. And if anything, I'd expect it to be included on Windows and +/// excluded everywhere else... Odd.) +#[cfg(target_os = "linux")] +#[test] +fn emit_marker_expression_pypy() -> Result<()> { + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); + requirements_in.write_str("pendulum")?; + + uv_snapshot!(context + .compile() + .arg("requirements.in") + .arg("--emit-marker-expression"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + # This file was autogenerated by uv via the following command: + # uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in --emit-marker-expression + # Pinned dependencies known to be valid for: + # python_version == '3.12' and implementation_name == 'cpython' + pendulum==3.0.0 + python-dateutil==2.9.0.post0 + # via + # pendulum + # time-machine + six==1.16.0 + # via python-dateutil + time-machine==2.14.1 + # via pendulum + tzdata==2024.1 + # via pendulum + + ----- stderr ----- + Resolved 5 packages in [TIME] + "###); + + Ok(()) +}