Skip to content

Commit e60ed9e

Browse files
committed
Don't package non-path-dep crates in sdist for workspaces
1 parent 19a1d7c commit e60ed9e

File tree

11 files changed

+343
-5
lines changed

11 files changed

+343
-5
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010
* Add a `maturin init` command as a companion to `maturin new` in [#719](https://github.com/PyO3/maturin/pull/719)
11+
* Don't package non-path-dep crates in sdist for workspaces in [#720](https://github.com/PyO3/maturin/pull/720)
1112

1213
## [0.12.3] - 2021-11-29
1314

src/source_distribution.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,22 @@ pub fn source_distribution(
178178
.resolve
179179
.as_ref()
180180
.context("Expected to get a dependency graph from cargo")?;
181-
let known_path_deps: HashMap<String, PathBuf> = resolve
181+
let root = resolve
182+
.root
183+
.as_ref()
184+
.context("Expected to get a root package id of dependency graph from cargo")?;
185+
let root_node = resolve
182186
.nodes
183187
.iter()
184-
.filter(|node| {
185-
&node.id != resolve.root.as_ref().unwrap() && node.id.repr.contains("path+file://")
186-
})
188+
.find(|node| &node.id == root)
189+
.context("Expected to get a root node of dependency graph from cargo")?;
190+
let known_path_deps: HashMap<String, PathBuf> = root_node
191+
.deps
192+
.iter()
193+
.filter(|node| node.pkg.repr.contains("path+file://"))
187194
.filter_map(|node| {
188195
cargo_metadata.packages.iter().find_map(|pkg| {
189-
if pkg.id.repr == node.id.repr {
196+
if pkg.id.repr == node.pkg.repr {
190197
Some((pkg.name.clone(), PathBuf::from(&pkg.manifest_path)))
191198
} else {
192199
None

test-crates/workspace_path_dep/Cargo.lock

Lines changed: 266 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[workspace]
2+
members = [
3+
"generic_lib",
4+
"dont_include_in_sdist",
5+
"python"
6+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "dont_include_in_sdist"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "generic_lib"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[cfg(test)]
2+
mod tests {
3+
#[test]
4+
fn it_works() {
5+
let result = 2 + 2;
6+
assert_eq!(result, 4);
7+
}
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "workspace_with_path_dep"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
[lib]
8+
name = "python"
9+
crate-type = ["cdylib"]
10+
11+
[dependencies]
12+
pyo3 = { version = "0.15.1", features = ["extension-module"] }
13+
generic_lib = { path = "../generic_lib" }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["maturin>=0.12,<0.13"]
3+
build-backend = "maturin"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
use pyo3::prelude::*;
3+
4+
/// Formats the sum of two numbers as string.
5+
#[pyfunction]
6+
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
7+
Ok((a + b).to_string())
8+
}
9+
10+
/// A Python module implemented in Rust.
11+
#[pymodule]
12+
fn python(_py: Python, m: &PyModule) -> PyResult<()> {
13+
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
14+
Ok(())
15+
}

0 commit comments

Comments
 (0)