diff --git a/src/module_writer.rs b/src/module_writer.rs index 0c13e0105..0c9946884 100644 --- a/src/module_writer.rs +++ b/src/module_writer.rs @@ -302,7 +302,7 @@ impl WheelWriter { .normalize() .with_context(|| { format!( - "failed to normalize path `{}`", + "failed to normalize python dir path `{}`", project_layout.python_dir.display() ) })? diff --git a/src/project_layout.rs b/src/project_layout.rs index affb25d80..c63a2e2db 100644 --- a/src/project_layout.rs +++ b/src/project_layout.rs @@ -209,7 +209,7 @@ impl ProjectResolver { if let Some(path) = cargo_manifest_path { let path = path .normalize() - .with_context(|| format!("failed to normalize path `{}`", path.display()))? + .with_context(|| format!("failed to normalize manifest path `{}`", path.display()))? .into_path_buf(); debug!( "Using cargo manifest path from command line argument: {:?}", @@ -248,7 +248,7 @@ impl ProjectResolver { debug!("Using cargo manifest path from pyproject.toml {:?}", path); return Ok(( path.normalize() - .with_context(|| format!("failed to normalize path `{}`", path.display()))? + .with_context(|| format!("failed to normalize manifest path `{}`", path.display()))? .into_path_buf(), pyproject_file, )); diff --git a/src/source_distribution.rs b/src/source_distribution.rs index 1cdc7c8b6..7328dd11a 100644 --- a/src/source_distribution.rs +++ b/src/source_distribution.rs @@ -2,7 +2,7 @@ use crate::module_writer::{add_data, ModuleWriter}; use crate::pyproject_toml::SdistGenerator; use crate::{pyproject_toml::Format, BuildContext, PyProjectToml, SDistWriter}; use anyhow::{bail, Context, Result}; -use cargo_metadata::{Metadata, MetadataCommand}; +use cargo_metadata::{Metadata, MetadataCommand, PackageId}; use fs_err as fs; use ignore::overrides::Override; use normpath::PathExt as _; @@ -242,14 +242,23 @@ fn find_path_deps(cargo_metadata: &Metadata) -> Result>(); + .collect::>(); // scan the dependency graph for path dependencies let mut path_deps = HashMap::new(); let mut stack: Vec<&cargo_metadata::Package> = vec![root]; while let Some(top) = stack.pop() { - for dependency in &top.dependencies { + // There seems to be no API to get the package id of a dependency, so collect the package ids from resolve + // and match them up with the `Dependency`s from `Package.dependencies`. + let dep_ids = &cargo_metadata.resolve.as_ref().unwrap().nodes.iter().find(|node| node.id == top.id).unwrap().dependencies; + for dep_id in dep_ids { + // Assumption: Each package name can only occur once in a `[dependencies]` table. + let dependency = top.dependencies.iter().find(|package| { + // Package ids are opaque and there seems to be no way to query their name. + let dep_name = &cargo_metadata.packages.iter().find(|package| &package.id == dep_id).unwrap().name; + &package.name == dep_name + }).unwrap(); if let Some(path) = &dependency.path { let dep_name = dependency.rename.as_ref().unwrap_or(&dependency.name); if path_deps.contains_key(dep_name) { @@ -269,9 +278,10 @@ fn find_path_deps(cargo_metadata: &Metadata) -> Result Result