Skip to content

Commit

Permalink
Add workspace lock file to sdist as a fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Dec 19, 2022
1 parent d665558 commit 2b8db1d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
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

0 comments on commit 2b8db1d

Please sign in to comment.