Repository: astral-sh/uv
File: crates/uv/tests/it/sync.rs (Rust)

Code before:
        child = [{ requirement = "anyio>4", match-runtime = true }]
    "#})?;

    uv_snapshot!(context.filters(), context.sync(), @r#"
    success: false
    exit_code: 2
    ----- stdout -----

    ----- stderr -----
    warning: Failed to parse `pyproject.toml` during settings discovery:
      TOML parse error at line 11, column 9
         |
      11 | child = [{ requirement = "anyio>4", match-runtime = true }]
         |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      Dependencies marked with `match-runtime = true` cannot include version specifiers

    error: Failed to parse: `pyproject.toml`
      Caused by: TOML parse error at line 11, column 9
       |
    11 | child = [{ requirement = "anyio>4", match-runtime = true }]
       |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    Dependencies marked with `match-runtime = true` cannot include version specifiers
    "#);

    Ok(())
}

#[test]
fn sync_extra_build_variables() -> Result<()> {
    let context = TestContext::new("3.12").with_filtered_counts();

    // Create a build backend that asserts that `EXPECTED_ANYIO_VERSION` matches the installed version of `anyio`.
    let build_backend = context.temp_dir.child("build_backend.py");
    build_backend.write_str(indoc! {r#"
        import os
        import sys
        from hatchling.build import *

        expected_version = os.environ.get("EXPECTED_ANYIO_VERSION", "")
        if not expected_version:
            print("`EXPECTED_ANYIO_VERSION` not set", file=sys.stderr)
            sys.exit(1)

        try:
            import anyio
        except ModuleNotFoundError:
            print("Missing `anyio` module", file=sys.stderr)
            sys.exit(1)

        from importlib.metadata import version
        anyio_version = version("anyio")

Review comment (bug):
I guess this is "right" but it's kind of weird (we only warn, not fail, when we fail to parse options from a `pyproject.toml`). Before, we were both warning and erroring because these settings were parsed twice, once as `pyproject.toml` options and once as project settings.

Code after:
        child = [{ requirement = "anyio>4", match-runtime = true }]
    "#})?;

    uv_snapshot!(context.filters(), context.sync(), @r#"
    success: false
    exit_code: 1
    ----- stdout -----

    ----- stderr -----
    warning: Failed to parse `pyproject.toml` during settings discovery:
      TOML parse error at line 11, column 9
         |
      11 | child = [{ requirement = "anyio>4", match-runtime = true }]
         |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      Dependencies marked with `match-runtime = true` cannot include version specifiers

    Resolved [N] packages in [TIME]
      × Failed to build `child @ file://[TEMP_DIR]/child`
      ├─▶ The build backend returned an error
      ╰─▶ Call to `build_backend.build_wheel` failed (exit status: 1)

          [stderr]
          `EXPECTED_ANYIO_VERSION` not set

          hint: This usually indicates a problem with the package or the build environment.
      help: `child` was included because `parent` (v0.1.0) depends on `child`
    "#);

    Ok(())
}

#[test]
fn sync_extra_build_variables() -> Result<()> {
    let context = TestContext::new("3.12").with_filtered_counts();

    // Create a build backend that asserts that `EXPECTED_ANYIO_VERSION` matches the installed version of `anyio`.
    let build_backend = context.temp_dir.child("build_backend.py");
    build_backend.write_str(indoc! {r#"
        import os
        import sys
        from hatchling.build import *

        expected_version = os.environ.get("EXPECTED_ANYIO_VERSION", "")
        if not expected_version:
            print("`EXPECTED_ANYIO_VERSION` not set", file=sys.stderr)
            sys.exit(1)

        try:
            import anyio
        except ModuleNotFoundError:
            print("Missing `anyio` module", file=sys.stderr)