Skip to content

Commit

Permalink
Merge pull request #844 from messense/update-sdist-workspace-member
Browse files Browse the repository at this point in the history
Update workspace memebers for sdist local dependencies
  • Loading branch information
messense authored Mar 14, 2022
2 parents 0c96687 + 1e62f47 commit 0d0bf46
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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
Expand Down
4 changes: 3 additions & 1 deletion src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
46 changes: 37 additions & 9 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -96,17 +130,11 @@ fn add_crate_to_source_distribution(
known_path_deps: &HashMap<String, PathDependency>,
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")?;
.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{}",
Expand Down

0 comments on commit 0d0bf46

Please sign in to comment.