Repository: astral-sh/uv
File: crates/uv-requirements/src/specification.rs (Rust)

Code before:
                            path.user_display(),
                            err
                        ));
                    }
                };
                let pyproject_toml = toml::from_str::<PyProjectToml>(&contents)
                    .with_context(|| format!("Failed to parse: `{}`", path.user_display()))?;

                Self {
                    source_trees: vec![SourceTree::PyProjectToml(path.clone(), pyproject_toml)],
                    ..Self::default()
                }
            }
            RequirementsSource::Pep723Script(source) => {
                let script = if let Some(script) = source.script() {
                    Pep723Item::Script(script.clone())
                } else {
                    match Pep723Script::read(source.path()).await {
                        Ok(Some(script)) => Pep723Item::Script(script),
                        Ok(None) => {
                            return Err(anyhow::anyhow!(
                                "`{}` does not contain inline script metadata",
                                source.path().user_display(),
                            ));
                        }
                        Err(Pep723Error::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => {
                            return Err(anyhow::anyhow!(
                                "Failed to read `{}` (not found)",
                                source.path().user_display(),
                            ));
                        }
                        Err(err) => return Err(err.into()),
                    }
                };

                let metadata = script.metadata();

                let requirements = metadata
                    .dependencies
                    .as_ref()
                    .map(|dependencies| {
                        dependencies
                            .iter()
                            .map(|dependency| {
                                UnresolvedRequirementSpecification::from(Requirement::from(
                                    dependency.to_owned(),
                                ))
                            })
                            .collect::<Vec<UnresolvedRequirementSpecification>>()
                    })
                    .unwrap_or_default();

Review comment (suggestion):
Haven't checked the rest properly yet, but the `if err.kind() == std::io::ErrorKind::NotFound` branches should be handled by fs_err already.

Code after:
                            path.user_display(),
                            err
                        ));
                    }
                };
                let pyproject_toml = toml::from_str::<PyProjectToml>(&contents)
                    .with_context(|| format!("Failed to parse: `{}`", path.user_display()))?;

                Self {
                    source_trees: vec![SourceTree::PyProjectToml(path.clone(), pyproject_toml)],
                    ..Self::default()
                }
            }
            RequirementsSource::Pep723Script(source) => {
                let script = if let Some(script) = source.script() {
                    Pep723Item::Script(script.clone())
                } else {
                    match Pep723Script::read(source.path()).await {
                        Ok(Some(script)) => Pep723Item::Script(script),
                        Ok(None) => {
                            return Err(anyhow::anyhow!(
                                "`{}` does not contain inline script metadata",
                                source.path().user_display(),
                            ));
                        }
                        Err(err) => return Err(err.into()),
                    }
                };

                let metadata = script.metadata();

                let requirements = metadata
                    .dependencies
                    .as_ref()
                    .map(|dependencies| {
                        dependencies
                            .iter()
                            .map(|dependency| {
                                UnresolvedRequirementSpecification::from(Requirement::from(
                                    dependency.to_owned(),
                                ))
                            })
                            .collect::<Vec<UnresolvedRequirementSpecification>>()
                    })
                    .unwrap_or_default();

                if let Some(tool_uv) = metadata.tool.as_ref().and_then(|tool| tool.uv.as_ref()) {
                    let constraints = tool_uv
                        .constraint_dependencies
                        .as_ref()
                        .map(|dependencies| {