Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update workspace memebers for sdist local dependencies #844

Merged
merged 3 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: workspace members contain paths not just names, so this only handles simple path without subdirectory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix this later.

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