Emit dedicated error message for Conda environment.yml files (#12669)
Some checks are pending
CI / cargo dev generate-all (push) Blocked by required conditions
CI / cargo shear (push) Waiting to run
CI / check cache | macos aarch64 (push) Blocked by required conditions
CI / check system | python on macos x86-64 (push) Blocked by required conditions
CI / check system | python3.10 on windows x86-64 (push) Blocked by required conditions
CI / check system | python3.10 on windows x86 (push) Blocked by required conditions
CI / check system | python3.13 (push) Blocked by required conditions
CI / check system | conda3.11 on macos aarch64 (push) Blocked by required conditions
CI / check system | conda3.8 on macos aarch64 (push) Blocked by required conditions
CI / check system | conda3.11 on linux x86-64 (push) Blocked by required conditions
CI / check system | conda3.8 on linux x86-64 (push) Blocked by required conditions
CI / check system | conda3.11 on windows x86-64 (push) Blocked by required conditions
CI / Determine changes (push) Waiting to run
CI / lint (push) Waiting to run
CI / cargo clippy | ubuntu (push) Blocked by required conditions
CI / cargo clippy | windows (push) Blocked by required conditions
CI / cargo test | ubuntu (push) Blocked by required conditions
CI / cargo test | macos (push) Blocked by required conditions
CI / cargo test | windows (push) Blocked by required conditions
CI / check windows trampoline | aarch64 (push) Blocked by required conditions
CI / check system | conda3.8 on windows x86-64 (push) Blocked by required conditions
CI / check windows trampoline | i686 (push) Blocked by required conditions
CI / check windows trampoline | x86_64 (push) Blocked by required conditions
CI / test windows trampoline | i686 (push) Blocked by required conditions
CI / test windows trampoline | x86_64 (push) Blocked by required conditions
CI / typos (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / build binary | linux libc (push) Blocked by required conditions
CI / build binary | linux musl (push) Blocked by required conditions
CI / build binary | macos aarch64 (push) Blocked by required conditions
CI / build binary | macos x86_64 (push) Blocked by required conditions
CI / build binary | windows x86_64 (push) Blocked by required conditions
CI / build binary | windows aarch64 (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / build binary | freebsd (push) Blocked by required conditions
CI / ecosystem test | pydantic/pydantic-core (push) Blocked by required conditions
CI / ecosystem test | prefecthq/prefect (push) Blocked by required conditions
CI / ecosystem test | pallets/flask (push) Blocked by required conditions
CI / smoke test | linux (push) Blocked by required conditions
CI / check system | alpine (push) Blocked by required conditions
CI / smoke test | macos (push) Blocked by required conditions
CI / smoke test | windows x86_64 (push) Blocked by required conditions
CI / smoke test | windows aarch64 (push) Blocked by required conditions
CI / integration test | conda on ubuntu (push) Blocked by required conditions
CI / integration test | deadsnakes python3.9 on ubuntu (push) Blocked by required conditions
CI / integration test | free-threaded on linux (push) Blocked by required conditions
CI / integration test | free-threaded on windows (push) Blocked by required conditions
CI / integration test | pypy on ubuntu (push) Blocked by required conditions
CI / integration test | pypy on windows (push) Blocked by required conditions
CI / integration test | graalpy on ubuntu (push) Blocked by required conditions
CI / integration test | graalpy on windows (push) Blocked by required conditions
CI / integration test | github actions (push) Blocked by required conditions
CI / integration test | determine publish changes (push) Blocked by required conditions
CI / integration test | uv publish (push) Blocked by required conditions
CI / integration test | uv_build (push) Blocked by required conditions
CI / check cache | ubuntu (push) Blocked by required conditions
CI / check system | python on debian (push) Blocked by required conditions
CI / check system | python on fedora (push) Blocked by required conditions
CI / check system | python on ubuntu (push) Blocked by required conditions
CI / check system | python on opensuse (push) Blocked by required conditions
CI / check system | python on rocky linux 8 (push) Blocked by required conditions
CI / check system | python on rocky linux 9 (push) Blocked by required conditions
CI / check system | pypy on ubuntu (push) Blocked by required conditions
CI / check system | pyston (push) Blocked by required conditions
CI / check system | python on macos aarch64 (push) Blocked by required conditions
CI / check system | homebrew python on macos aarch64 (push) Blocked by required conditions
CI / check system | python3.13 on windows x86-64 (push) Blocked by required conditions
CI / check system | x86-64 python3.13 on windows aarch64 (push) Blocked by required conditions
CI / check system | windows registry (push) Blocked by required conditions
CI / check system | python3.12 via chocolatey (push) Blocked by required conditions
CI / check system | python3.9 via pyenv (push) Blocked by required conditions
CI / check system | amazonlinux (push) Blocked by required conditions
CI / check system | embedded python3.10 on windows x86-64 (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions

<!--
Thank you for contributing to uv! To help us out with reviewing, please
consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary
Fixes #12606.

Two options considered, thanks to @zanieb's guidance are:
1. Special-casing on parse error and encountering the `environment.yml`
filename, possibly at `RequirementsTxt::parse`
2. Adding a new `RequirementsSource::EnvironmentYml` variant and
erroring on `RequirementSpecification::from_source`

I went with the latter for the following reasons:
- This edge case is explicitly modelled within the type system. However,
it changes the semantics of `RequirementsSource` to also model
_unsupported_ sources.
- (**Separation of concerns**) The special-casing would occur in the
`uv-requirements-txt` crate, which seems to be relatively deep in the
guts of the codebase. In my opinion, maintainers working in
`uv-requirements-txt` would reasonably assume the input file to be a
`requirements.txt` file, instead of having to be concerned with it being
another file format (`environment.yml`, `pyproject.toml`, etc.)

<!-- What's the purpose of the change? What does it do, and why? -->

## Test Plan
Manually tested as follows:
```sh
>>> cargo run -- pip install -r environment.yml
error: Conda environment file `environment.yml` is not supported

>>> cargo run -- add -r environment.yml
error: Conda environment file `environment.yml` is not supported
``` 

If you can point me to the appropriate test module, I can write up tests
for these to use `insta`.

<!-- How was it tested? -->
This commit is contained in:
Christopher Tee 2025-04-07 19:11:43 -04:00 committed by GitHub
parent 335af984f2
commit 7921667ced
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 72 additions and 0 deletions

View file

@ -23,6 +23,8 @@ pub enum RequirementsSource {
SetupCfg(PathBuf),
/// Dependencies were provided via a path to a source tree (e.g., `pip install .`).
SourceTree(PathBuf),
/// Dependencies were provided via an unsupported Conda `environment.yml` file (e.g., `pip install -r environment.yml`).
EnvironmentYml(PathBuf),
}
impl RequirementsSource {
@ -35,6 +37,8 @@ impl RequirementsSource {
Self::SetupPy(path)
} else if path.ends_with("setup.cfg") {
Self::SetupCfg(path)
} else if path.ends_with("environment.yml") {
Self::EnvironmentYml(path)
} else {
Self::RequirementsTxt(path)
}
@ -217,6 +221,7 @@ impl std::fmt::Display for RequirementsSource {
| Self::PyprojectToml(path)
| Self::SetupPy(path)
| Self::SetupCfg(path)
| Self::EnvironmentYml(path)
| Self::SourceTree(path) => {
write!(f, "{}", path.simplified_display())
}

View file

@ -212,6 +212,12 @@ impl RequirementsSpecification {
..Self::default()
}
}
RequirementsSource::EnvironmentYml(path) => {
return Err(anyhow::anyhow!(
"Conda environment files (i.e. `{}`) are not supported",
path.user_display()
))
}
})
}

View file

@ -3662,6 +3662,41 @@ fn add_error() -> Result<()> {
Ok(())
}
/// Emit dedicated error message when adding Conda `environment.yml`
#[test]
fn add_environment_yml_error() -> Result<()> {
let context = TestContext::new("3.12");
let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(indoc! {r#"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = []
"#})?;
let environment_yml = context.temp_dir.child("environment.yml");
environment_yml.write_str(indoc! {r"
name: test-env
channels:
- conda-forge
dependencies:
- python>=3.12
"})?;
uv_snapshot!(context.filters(), context.add().arg("-r").arg("environment.yml"), @r"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: Conda environment files (i.e. `environment.yml`) are not supported
");
Ok(())
}
/// Set a lower bound when adding unconstrained dependencies.
#[test]
fn add_lower_bound() -> Result<()> {

View file

@ -8049,6 +8049,32 @@ fn install_incompatible_python_version_interpreter_broken_in_path() -> Result<()
Ok(())
}
/// Emit dedicated error message when installing Conda `environment.yml`
#[test]
fn install_unsupported_environment_yml() -> Result<()> {
let context = TestContext::new("3.12");
let environment_yml = context.temp_dir.child("environment.yml");
environment_yml.write_str(indoc! {r"
name: test-env
channels:
- conda-forge
dependencies:
- python>=3.12
"})?;
uv_snapshot!(context.filters(), context.pip_install().arg("-r").arg("environment.yml"), @r"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: Conda environment files (i.e. `environment.yml`) are not supported
");
Ok(())
}
/// Include a `build_constraints.txt` file with an incompatible constraint.
#[test]
fn incompatible_build_constraint() -> Result<()> {