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.
This commit is contained in:
konsti 2025-02-28 13:40:19 +01:00 committed by GitHub
parent 2e7ae19b55
commit dc39d6622b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 21 deletions

View File

@ -762,34 +762,38 @@ impl Workspace {
let pyproject_path = member_root.join("pyproject.toml"); let pyproject_path = member_root.join("pyproject.toml");
let contents = match fs_err::tokio::read_to_string(&pyproject_path).await { let contents = match fs_err::tokio::read_to_string(&pyproject_path).await {
Ok(contents) => contents, Ok(contents) => contents,
Err(err) if err.kind() == std::io::ErrorKind::NotFound => { Err(err) => {
// If the directory is hidden, skip it. if !fs_err::metadata(&member_root)?.is_dir() {
if member_root warn!(
.file_name() "Ignoring non-directory workspace member: `{}`",
.map(|name| name.as_encoded_bytes().starts_with(b"."))
.unwrap_or(false)
{
debug!(
"Ignoring hidden workspace member: `{}`",
member_root.simplified_display() member_root.simplified_display()
); );
continue; continue;
} }
return Err(WorkspaceError::MissingPyprojectTomlMember( // A directory exists, but it doesn't contain a `pyproject.toml`.
member_root, if err.kind() == std::io::ErrorKind::NotFound {
member_glob.to_string(), // If the directory is hidden, skip it.
)); if member_root
} .file_name()
Err(err) if err.kind() == std::io::ErrorKind::NotADirectory => { .map(|name| name.as_encoded_bytes().starts_with(b"."))
warn!( .unwrap_or(false)
"Ignoring non-directory workspace member: `{}`", {
member_root.simplified_display() 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) let pyproject_toml = PyProjectToml::from_string(contents)
.map_err(|err| WorkspaceError::Toml(pyproject_path.clone(), Box::new(err)))?; .map_err(|err| WorkspaceError::Toml(pyproject_path.clone(), Box::new(err)))?;

View File

@ -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.