From 8320f74221cab2a76e8d4d2b9fed4a03b070f5b2 Mon Sep 17 00:00:00 2001 From: "Tomasz (Tom) Kramkowski" Date: Fri, 22 May 2026 20:47:31 +0100 Subject: [PATCH] Fix scroll environment creation for long filenames When a scroll's filename approaches the path element length limit (conveniently 255 almost everywhere), the underlying cache entry path which gets generated from it ends up exceeding the limit. This caps it at 100. It does mean, however, that pre-existing environments which previously exceeded this limit will end up re-created. No clue if this would be breaking or not. --- crates/uv/src/commands/project/mod.rs | 2 +- crates/uv/tests/it/run.rs | 38 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/crates/uv/src/commands/project/mod.rs b/crates/uv/src/commands/project/mod.rs index 1244bf44f0f..e1869388ebb 100644 --- a/crates/uv/src/commands/project/mod.rs +++ b/crates/uv/src/commands/project/mod.rs @@ -717,7 +717,7 @@ impl ScriptInterpreter { .path .file_stem() .and_then(|name| name.to_str()) - .and_then(|name| cache_name(name, None)) + .and_then(|name| cache_name(name, Some(100))) { format!("{file_name}-{digest}") } else { diff --git a/crates/uv/tests/it/run.rs b/crates/uv/tests/it/run.rs index 0a944fc8a15..a642bb47cd2 100644 --- a/crates/uv/tests/it/run.rs +++ b/crates/uv/tests/it/run.rs @@ -510,6 +510,44 @@ fn run_pep723_script() -> Result<()> { Ok(()) } +/// A PEP 723 script with a long file name should still succeed at creating a script environment on +/// Windows. +#[test] +fn run_pep723_script_long_filename() -> Result<()> { + let context = uv_test::test_context!("3.12"); + + // The cache environment entry path, which is derived from the script's name, would exceed many + // common path component length limits if it was not truncated first. + let script_name = format!("{}.py", "a".repeat(240)); + let test_script = context.temp_dir.child(&script_name); + test_script.write_str(indoc! { r#" + # /// script + # requires-python = ">=3.11" + # dependencies = [ + # "iniconfig", + # ] + # /// + + print("Hello, world!") + "# + })?; + + uv_snapshot!(context.filters(), context.run().arg(&script_name), @" + success: true + exit_code: 0 + ----- stdout ----- + Hello, world! + + ----- stderr ----- + Resolved 1 package in [TIME] + Prepared 1 package in [TIME] + Installed 1 package in [TIME] + + iniconfig==2.0.0 + "); + + Ok(()) +} + #[test] fn run_pep723_script_requires_python() -> Result<()> { let context = uv_test::test_context_with_versions!(&["3.11", "3.12"]);