From 53a9349e2ab385e36812ca15b49f7c04389c4d1c Mon Sep 17 00:00:00 2001 From: messense Date: Sat, 12 Mar 2022 18:44:50 +0800 Subject: [PATCH 1/3] Update workspace memebers for sdist local dependencies --- Changelog.md | 2 +- src/source_distribution.rs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 02ef4c877..7b234102d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Package license files in `.dist-info/license_files` following PEP 639 in [#837](https://github.com/PyO3/maturin/pull/837) * Stop testing Python 3.6 on CI since it's already EOL in [#840](https://github.com/PyO3/maturin/pull/840) -* Fix `maturin sdist --manifest-path ` for workspace project in [#843](https://github.com/PyO3/maturin/pull/843) +* Update workspace members for sdist local dependencies in [#844](https://github.com/PyO3/maturin/pull/844) * Migrate docker image to github container registry in [#845](https://github.com/PyO3/maturin/pull/845) ## [0.12.10] - 2022-03-09 diff --git a/src/source_distribution.rs b/src/source_distribution.rs index 7c22bdf5e..4087465fa 100644 --- a/src/source_distribution.rs +++ b/src/source_distribution.rs @@ -78,6 +78,40 @@ fn rewrite_cargo_toml( } } } + if root_crate { + // Update workspace members + if let Some(workspace) = data.get_mut("workspace").and_then(|x| x.as_table_mut()) { + if let Some(members) = workspace.get_mut("members").and_then(|x| x.as_array_mut()) { + let mut new_members = toml_edit::Array::new(); + for member in members.iter() { + if let toml_edit::Value::String(ref s) = member { + let name = s.value(); + if known_path_deps.contains_key(name) { + new_members.push(format!("{}/{}", LOCAL_DEPENDENCIES_FOLDER, name)); + } + } + } + if !new_members.is_empty() { + workspace["members"] = toml_edit::value(new_members); + rewritten = true; + } + } + } + } else { + // Update package.workspace + // https://rust-lang.github.io/rfcs/1525-cargo-workspace.html#implicit-relations + // https://doc.rust-lang.org/cargo/reference/manifest.html#the-workspace-field + if let Some(package) = data.get_mut("package").and_then(|x| x.as_table_mut()) { + if let Some(workspace) = package.get("workspace").and_then(|x| x.as_str()) { + // This is enough to fix https://github.com/PyO3/maturin/issues/838 + // Other cases can be fixed on demand + if workspace == ".." || workspace == "../" { + package.remove("workspace"); + rewritten = true; + } + } + } + } if rewritten { Ok(data.to_string()) } else { From 208c05889d8034b1dff7c4314b6b69aeb14142ee Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 14 Mar 2022 20:45:56 +0800 Subject: [PATCH 2/3] Better error message for `Failed to run cargo` --- src/compile.rs | 4 +++- src/source_distribution.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/compile.rs b/src/compile.rs index bc77b0722..f83e9d9bd 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -260,7 +260,9 @@ fn compile_target( build_command.env("PYO3_CROSS_LIB_DIR", lib_dir); } - let mut cargo_build = build_command.spawn().context("Failed to run cargo")?; + let mut cargo_build = build_command + .spawn() + .context("Failed to run `cargo rustc`")?; let mut artifacts = HashMap::new(); diff --git a/src/source_distribution.rs b/src/source_distribution.rs index 4087465fa..169d79a88 100644 --- a/src/source_distribution.rs +++ b/src/source_distribution.rs @@ -140,7 +140,7 @@ fn add_crate_to_source_distribution( .args(&["package", "--list", "--allow-dirty"]) .current_dir(crate_dir) .output() - .context("Failed to run cargo")?; + .context("Failed to run `cargo package --list --allow-dirty`")?; if !output.status.success() { bail!( "Failed to query file list from cargo: {}\n--- Stdout:\n{}\n--- Stderr:\n{}", From 1e62f47f1eb3a218a38dbb3437c4bdf77179c113 Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 14 Mar 2022 20:46:33 +0800 Subject: [PATCH 3/3] Revert "Fix `maturin sdist --manifest-path ` for workspace project" This reverts commit 54973be8bde71168961866fe35fc95182b9cac00. --- src/source_distribution.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/source_distribution.rs b/src/source_distribution.rs index 169d79a88..412ed2a67 100644 --- a/src/source_distribution.rs +++ b/src/source_distribution.rs @@ -130,15 +130,9 @@ fn add_crate_to_source_distribution( known_path_deps: &HashMap, root_crate: bool, ) -> Result<()> { - let crate_dir = manifest_path.as_ref().parent().with_context(|| { - format!( - "Can't get parent directory of {}", - manifest_path.as_ref().display() - ) - })?; let output = Command::new("cargo") - .args(&["package", "--list", "--allow-dirty"]) - .current_dir(crate_dir) + .args(&["package", "--list", "--allow-dirty", "--manifest-path"]) + .arg(manifest_path.as_ref()) .output() .context("Failed to run `cargo package --list --allow-dirty`")?; if !output.status.success() {