Skip to content
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 src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub use crate::module_writer::{
pub use crate::new_project::{init_project, new_project, GenerateProjectOptions};
pub use crate::pyproject_toml::PyProjectToml;
pub use crate::python_interpreter::PythonInterpreter;
pub use crate::source_distribution::find_path_deps;
#[cfg(feature = "upload")]
pub use crate::upload::{upload, upload_ui, PublishOpt, Registry, UploadError};
pub use auditwheel::PlatformTag;
Expand Down
26 changes: 21 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use clap::{Parser, Subcommand};
#[cfg(feature = "scaffolding")]
use maturin::{ci::GenerateCI, init_project, new_project, GenerateProjectOptions};
use maturin::{
develop, write_dist_info, BridgeModel, BuildOptions, CargoOptions, DevelopOptions, PathWriter,
PythonInterpreter, Target, TargetTriple,
develop, find_path_deps, write_dist_info, BridgeModel, BuildOptions, CargoOptions,
DevelopOptions, PathWriter, PythonInterpreter, Target, TargetTriple,
};
#[cfg(feature = "schemars")]
use maturin::{generate_json_schema, GenerateJsonSchemaOptions};
Expand Down Expand Up @@ -433,13 +433,29 @@ fn run() -> Result<()> {
develop(develop_options, &venv_dir)?;
}
Command::SDist { manifest_path, out } => {
// Get cargo metadata to check for path dependencies
let cargo_metadata_result = cargo_metadata::MetadataCommand::new()
.cargo_path("cargo")
.manifest_path(
manifest_path
.as_deref()
.unwrap_or_else(|| std::path::Path::new("Cargo.toml")),
)
.verbose(true)
.exec();

let has_path_deps = cargo_metadata_result
.ok()
.and_then(|metadata| find_path_deps(&metadata).ok())
.map(|path_deps| !path_deps.is_empty())
.unwrap_or(false); // If we can't get metadata, don't force all features
let build_options = BuildOptions {
out,
cargo: CargoOptions {
manifest_path,
// Enable all features to ensure all optional path dependencies are packaged
// into source distribution
all_features: true,
// Only enable all features when we have local path dependencies
// to ensure they are packaged into source distribution
all_features: has_path_deps,
..Default::default()
},
..Default::default()
Expand Down
4 changes: 2 additions & 2 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use tracing::{debug, trace};
/// foo = { path = "path/to/foo" }
/// ```
#[derive(Debug, Clone)]
struct PathDependency {
pub struct PathDependency {
/// `Cargo.toml` path of the path dependency
manifest_path: PathBuf,
/// workspace root of the path dependency
Expand Down Expand Up @@ -307,7 +307,7 @@ fn add_crate_to_source_distribution(
}

/// Finds all path dependencies of the crate
fn find_path_deps(cargo_metadata: &Metadata) -> Result<HashMap<String, PathDependency>> {
pub fn find_path_deps(cargo_metadata: &Metadata) -> Result<HashMap<String, PathDependency>> {
let root = cargo_metadata
.root_package()
.context("Expected the dependency graph to have a root package")?;
Expand Down
Loading