Skip to content

Commit 13d107d

Browse files
authored
Fix scroll environment creation for scrolls with long filenames (#19539)
## Summary Note: scroll == PEP 723 script 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 PR 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. I've marked it as such for now. ## Test Plan Added a test for this.
1 parent 1cf1f10 commit 13d107d

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

crates/uv/src/commands/project/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ impl ScriptInterpreter {
717717
.path
718718
.file_stem()
719719
.and_then(|name| name.to_str())
720-
.and_then(|name| cache_name(name, None))
720+
.and_then(|name| cache_name(name, Some(100)))
721721
{
722722
format!("{file_name}-{digest}")
723723
} else {

crates/uv/tests/it/run.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,44 @@ fn run_pep723_script() -> Result<()> {
510510
Ok(())
511511
}
512512

513+
/// A PEP 723 script with a long file name should still succeed at creating a script environment on
514+
/// Windows.
515+
#[test]
516+
fn run_pep723_script_long_filename() -> Result<()> {
517+
let context = uv_test::test_context!("3.12");
518+
519+
// The cache environment entry path, which is derived from the script's name, would exceed many
520+
// common path component length limits if it was not truncated first.
521+
let script_name = format!("{}.py", "a".repeat(240));
522+
let test_script = context.temp_dir.child(&script_name);
523+
test_script.write_str(indoc! { r#"
524+
# /// script
525+
# requires-python = ">=3.11"
526+
# dependencies = [
527+
# "iniconfig",
528+
# ]
529+
# ///
530+
531+
print("Hello, world!")
532+
"#
533+
})?;
534+
535+
uv_snapshot!(context.filters(), context.run().arg(&script_name), @"
536+
success: true
537+
exit_code: 0
538+
----- stdout -----
539+
Hello, world!
540+
541+
----- stderr -----
542+
Resolved 1 package in [TIME]
543+
Prepared 1 package in [TIME]
544+
Installed 1 package in [TIME]
545+
+ iniconfig==2.0.0
546+
");
547+
548+
Ok(())
549+
}
550+
513551
#[test]
514552
fn run_pep723_script_requires_python() -> Result<()> {
515553
let context = uv_test::test_context_with_versions!(&["3.11", "3.12"]);

0 commit comments

Comments
 (0)