From dc39d6622be268318acfb43a758c6ea688b722ea Mon Sep 17 00:00:00 2001 From: konsti Date: Fri, 28 Feb 2025 13:40:19 +0100 Subject: [PATCH] Fix non-directory in workspace on Windows (#11833) Fixes #11793 On Windows, trying to read a file inside what is not a directory but another file results in a not found error, while on Unix we get a not a directory error. We check explicitly if something included in a workspace glob is a non-directory to fix the behavior on Windows. --- crates/uv-workspace/src/workspace.rs | 46 ++++++++++--------- .../packages/Unrelated.md | 2 + 2 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 scripts/workspaces/albatross-virtual-workspace/packages/Unrelated.md diff --git a/crates/uv-workspace/src/workspace.rs b/crates/uv-workspace/src/workspace.rs index b2feefe62..e48c0df88 100644 --- a/crates/uv-workspace/src/workspace.rs +++ b/crates/uv-workspace/src/workspace.rs @@ -762,34 +762,38 @@ impl Workspace { let pyproject_path = member_root.join("pyproject.toml"); let contents = match fs_err::tokio::read_to_string(&pyproject_path).await { Ok(contents) => contents, - Err(err) if err.kind() == std::io::ErrorKind::NotFound => { - // If the directory is hidden, skip it. - if member_root - .file_name() - .map(|name| name.as_encoded_bytes().starts_with(b".")) - .unwrap_or(false) - { - debug!( - "Ignoring hidden workspace member: `{}`", + Err(err) => { + if !fs_err::metadata(&member_root)?.is_dir() { + warn!( + "Ignoring non-directory workspace member: `{}`", member_root.simplified_display() ); continue; } - return Err(WorkspaceError::MissingPyprojectTomlMember( - member_root, - member_glob.to_string(), - )); - } - Err(err) if err.kind() == std::io::ErrorKind::NotADirectory => { - warn!( - "Ignoring non-directory workspace member: `{}`", - member_root.simplified_display() - ); + // A directory exists, but it doesn't contain a `pyproject.toml`. + if err.kind() == std::io::ErrorKind::NotFound { + // If the directory is hidden, skip it. + if member_root + .file_name() + .map(|name| name.as_encoded_bytes().starts_with(b".")) + .unwrap_or(false) + { + debug!( + "Ignoring hidden workspace member: `{}`", + member_root.simplified_display() + ); + continue; + } - continue; + return Err(WorkspaceError::MissingPyprojectTomlMember( + member_root, + member_glob.to_string(), + )); + } + + return Err(err.into()); } - Err(err) => return Err(err.into()), }; let pyproject_toml = PyProjectToml::from_string(contents) .map_err(|err| WorkspaceError::Toml(pyproject_path.clone(), Box::new(err)))?; diff --git a/scripts/workspaces/albatross-virtual-workspace/packages/Unrelated.md b/scripts/workspaces/albatross-virtual-workspace/packages/Unrelated.md new file mode 100644 index 000000000..cdfbef871 --- /dev/null +++ b/scripts/workspaces/albatross-virtual-workspace/packages/Unrelated.md @@ -0,0 +1,2 @@ +This file is included in `packages/*`, but it is not a directory (it can't contain a package), so we +have to ignore it.