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

Add workspace lock file to sdist as a fallback #1362

Merged
merged 1 commit into from
Dec 19, 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
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* **Breaking Change**: Remove deprecated `python-source` option in `Cargo.toml` in [#1335](https://github.com/PyO3/maturin/pull/1335)
* **Breaking Change**: Turn `patchelf` version warning into a hard error in [#1335](https://github.com/PyO3/maturin/pull/1335)
* **Breaking Change**: [`uniffi_bindgen` CLI](https://mozilla.github.io/uniffi-rs/tutorial/Prerequisites.html#the-uniffi-bindgen-cli-tool) is required for building `uniffi` bindings wheels in [#1352](https://github.com/PyO3/maturin/pull/1352)
* Add workspace lock file to sdist as a fallback in [#1362](https://github.com/PyO3/maturin/pull/1362)

## [0.14.6] - 2022-12-13

Expand Down
15 changes: 13 additions & 2 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,16 +590,27 @@ pub fn source_distribution(
let abs_manifest_path = manifest_path.normalize()?.into_path_buf();
let abs_manifest_dir = abs_manifest_path.parent().unwrap();
let cargo_lock_path = abs_manifest_dir.join("Cargo.lock");
let cargo_lock_exists = cargo_lock_path.exists();
let workspace_cargo_lock = build_context
.cargo_metadata
.workspace_root
.join("Cargo.lock");
let workspace_cargo_lock_exists = workspace_cargo_lock.exists();
let cargo_lock_required =
build_context.cargo_options.locked || build_context.cargo_options.frozen;
if cargo_lock_required || cargo_lock_path.exists() {
if cargo_lock_required || cargo_lock_exists || workspace_cargo_lock_exists {
let project_root = pyproject_toml_path.parent().unwrap();
let relative_cargo_lock = if cargo_lock_path.starts_with(project_root) {
cargo_lock_path.strip_prefix(project_root).unwrap()
} else {
cargo_lock_path.strip_prefix(abs_manifest_dir).unwrap()
};
writer.add_file(root_dir.join(relative_cargo_lock), &cargo_lock_path)?;
if cargo_lock_exists {
writer.add_file(root_dir.join(relative_cargo_lock), &cargo_lock_path)?;
} else {
// Fallback to workspace Cargo lock file
writer.add_file(root_dir.join(relative_cargo_lock), workspace_cargo_lock)?;
}
} else {
eprintln!(
"⚠️ Warning: Cargo.lock is not found, it is recommended \
Expand Down
18 changes: 18 additions & 0 deletions tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,22 @@ fn pyo3_mixed_include_exclude_wheel_files() {
))
}

#[test]
fn workspace_sdist() {
handle_result(other::test_source_distribution(
"test-crates/workspace/py",
vec![
"py-0.1.0/Cargo.lock",
"py-0.1.0/Cargo.toml",
"py-0.1.0/PKG-INFO",
"py-0.1.0/pyproject.toml",
"py-0.1.0/src/main.rs",
],
None,
"sdist-workspace",
))
}

#[test]
fn workspace_with_path_dep_sdist() {
handle_result(other::test_source_distribution(
Expand All @@ -555,6 +571,7 @@ fn workspace_with_path_dep_sdist() {
"workspace_with_path_dep-0.1.0/local_dependencies/generic_lib/src/lib.rs",
"workspace_with_path_dep-0.1.0/local_dependencies/transitive_lib/Cargo.toml",
"workspace_with_path_dep-0.1.0/local_dependencies/transitive_lib/src/lib.rs",
"workspace_with_path_dep-0.1.0/Cargo.lock",
"workspace_with_path_dep-0.1.0/Cargo.toml",
"workspace_with_path_dep-0.1.0/pyproject.toml",
"workspace_with_path_dep-0.1.0/src/lib.rs",
Expand All @@ -573,6 +590,7 @@ fn workspace_inheritance_sdist() {
vec![
"workspace_inheritance-0.1.0/local_dependencies/generic_lib/Cargo.toml",
"workspace_inheritance-0.1.0/local_dependencies/generic_lib/src/lib.rs",
"workspace_inheritance-0.1.0/Cargo.lock",
"workspace_inheritance-0.1.0/Cargo.toml",
"workspace_inheritance-0.1.0/pyproject.toml",
"workspace_inheritance-0.1.0/src/lib.rs",
Expand Down