From 0f6424008c127b96938d2c5fb0a67c28a9dbf24d Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 30 Jan 2023 10:06:13 +0800 Subject: [PATCH] Don't package dev-only path dependencies in sdist --- Changelog.md | 1 + src/source_distribution.rs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index e02f0831f..d7160d34c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Add Cargo compile targets configuration for filtering multiple bin targets in [#1339](https://github.com/PyO3/maturin/pull/1339) * Respect `rustflags` settings in cargo configuration file in [#1405](https://github.com/PyO3/maturin/pull/1405) * Bump MSRV to 1.63.0 in [#1407](https://github.com/PyO3/maturin/pull/1407) +* Don't package dev-only path dependencies in sdist in [#1435](https://github.com/PyO3/maturin/pull/1435) ## [0.14.10] - 2023-01-13 diff --git a/src/source_distribution.rs b/src/source_distribution.rs index ff162d50b..28acb6b7f 100644 --- a/src/source_distribution.rs +++ b/src/source_distribution.rs @@ -65,8 +65,14 @@ fn rewrite_cargo_toml( // some_path_dep = { path = "../some_path_dep" } // ^^^^^^^^^^^^^^^^^^ table[&dep_name]["path"] // ^^^^^^^^^^^^^ dep_name - for dep_category in &["dependencies", "dev-dependencies", "build-dependencies"] { + for dep_category in ["dependencies", "dev-dependencies", "build-dependencies"] { if let Some(table) = data.get_mut(dep_category).and_then(|x| x.as_table_mut()) { + if dep_category == "dev-dependencies" { + // Remove dev-dependencies since building from sdist doesn't need them + data.remove(dep_category); + rewritten = true; + continue; + } let workspace_deps = workspace_manifest .get("workspace") .and_then(|x| x.get("dependencies")) @@ -477,6 +483,14 @@ fn find_path_deps(cargo_metadata: &Metadata) -> Result> while let Some(top) = stack.pop() { for dependency in &top.dependencies { if let Some(path) = &dependency.path { + if matches!(dependency.kind, cargo_metadata::DependencyKind::Development) { + // Skip dev-only dependency + debug!( + "Skipping development only dependency {} ({})", + dependency.name, path + ); + continue; + } // we search for the respective package by `manifest_path`, there seems // to be no way to query the dependency graph given `dependency` let dep_manifest_path = path.join("Cargo.toml");