astral-sh/ruff · error

For an mdtest with external dependencies, a Python platform

Error message

For an mdtest with external dependencies, a Python platform must be specified

What it means

setup_venv in ty_test's external-dependencies harness maps the mdtest Python platform to a uv-compatible platform string. When the platform is PythonPlatform::All (i.e. the mdtest did not pin a concrete platform), uv cannot resolve one lockfile for all platforms, so the harness refuses to proceed.

Source

Thrown at crates/ty_test/src/external_dependencies.rs:72

            .join("\n")
    );

    std::fs::write(
        temp_path.join("pyproject.toml").as_std_path(),
        pyproject_toml,
    )
    .context("Failed to write pyproject.toml")?;

    // Convert PythonPlatform to uv's platform format
    let uv_platform = match python_platform {
        PythonPlatform::Identifier(id) => match id.as_str() {
            "win32" => "windows",
            "darwin" => "macos",
            "linux" => "linux",
            other => other,
        },
        PythonPlatform::All => {
            bail!("For an mdtest with external dependencies, a Python platform must be specified");
        }
    };

    let upgrade_lockfile = std::env::var("MDTEST_UPGRADE_LOCKFILES").is_ok_and(|v| v == "1");
    let use_locked = if upgrade_lockfile {
        // In upgrade mode, we'll generate a new lockfile
        false
    } else if lockfile_path.exists() {
        // Copy existing lockfile to temp directory
        let temp_lockfile = temp_path.join("uv.lock");
        std::fs::copy(lockfile_path, temp_lockfile.as_std_path())
            .with_context(|| format!("Failed to copy lockfile from '{lockfile_path}'"))?;
        true
    } else {
        // No existing lockfile - error in normal mode
        bail!(
            "Lockfile not found at '{lockfile_path}'. Run with `MDTEST_UPGRADE_LOCKFILES=1` to generate it.",
        );

View on GitHub (pinned to 26f38c119c)

Solutions

  1. Add a concrete platform to the mdtest frontmatter, e.g. `platform: linux` (or darwin/win32)
  2. Only run the mdtest externally on a platform the test explicitly pins
  3. If the test truly is platform-independent, skip external-dependency setup instead of requiring uv resolution

Example fix

// before (mdtest frontmatter)
---
external_dependencies: true
---
// after
---
external_dependencies: true
platform: linux
---
Defensive patterns

Strategy: validation

Validate before calling

import re, sys
text = open(mdtest_path).read()
frontmatter = text.split('---')[1]
m = re.search(r'^platform:\s*(all|linux|darwin|win32)', frontmatter, re.M)
if m and m.group(1) == 'all':
    sys.exit(f"{mdtest_path}: external-dependency mdtests must pin a concrete platform")

Prevention

When it happens

Trigger: Running an mdtest with external dependencies (MDTEST_EXTERNAL=1) while the mdtest frontmatter sets platform: all, or omits a platform so it defaults to All, in setup_venv at crates/ty_test/src/external_dependencies.rs:72.

Common situations: Writing a new external-dependency mdtest and forgetting the `platform:` frontmatter key; running on CI where the default platform differs; copying an mdtest that targets all platforms into the external-dependencies suite.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05). Data as JSON: /api/errors/b851f55012425aab. Report an issue: GitHub.