fn add_crate_to_source_distribution(
    writer: &mut SDistWriter,
    manifest_path: impl AsRef<Path>,
    prefix: impl AsRef<Path>,
    known_path_deps: &HashMap<&String, &PathBuf>,
    root_crate: bool,
    is_path_dep: bool,
) -> Result<()> {
    let output = Command::new("cargo")
        .args(&["package", "--list", "--allow-dirty", "--manifest-path"])
        .arg(manifest_path.as_ref())
        .output()
        .context("Failed to run cargo")?;
    if !output.status.success() {
        bail!(
            "Failed to query file list from cargo: {}\n--- Stdout:\n{}\n--- Stderr:\n{}",
            output.status,
            String::from_utf8_lossy(&output.stdout),
            String::from_utf8_lossy(&output.stderr),
        );
    }

    let file_list: Vec<&Path> = str::from_utf8(&output.stdout)
        .context("Cargo printed invalid utf-8 ಠ_ಠ")?
        .lines()
        .map(Path::new)
        .collect();

    let manifest_dir = manifest_path.as_ref().parent().unwrap();

    let target_source: Vec<(PathBuf, PathBuf)> = file_list
        .iter()
        .map(|relative_to_manifests| {
            let relative_to_cwd = manifest_dir.join(relative_to_manifests);
            (relative_to_manifests.to_path_buf(), relative_to_cwd)
        })
        // We rewrite Cargo.toml and add it separately
        .filter(|(target, _)| {
            target != Path::new("Cargo.toml.orig") && target != Path::new("Cargo.toml")
        })
        .collect();

    if root_crate
        && !target_source
            .iter()
            .any(|(target, _)| target == Path::new("pyproject.toml"))
    {
        bail!(
            "pyproject.toml was not included by `cargo package`. \
                 Please make sure pyproject.toml is not excluded or build with `--no-sdist`"
        )
    }

    let rewritten_cargo_toml = rewrite_cargo_toml(&manifest_path, known_path_deps, is_path_dep)?;

    writer.add_directory(&prefix)?;
    writer.add_bytes(
        prefix
            .as_ref()
            .join(manifest_path.as_ref().file_name().unwrap()),
        rewritten_cargo_toml.as_bytes(),
    )?;
    for (target, source) in target_source {
        writer.add_file(prefix.as_ref().join(target), source)?;
    }

    Ok(())
}
/// Copies the files of a crate to a source distribution, recursively adding path dependencies
/// and rewriting path entries in Cargo.toml
///
/// Runs `cargo package --list --allow-dirty` to obtain a list of files to package.
Copies the files of a crate to a source distribution, recursively adding path dependencies
and rewriting path entries in Cargo.toml


Copies the files of a crate to a source distribution recursively adding path dependencies and rewriting path entries in Cargo . toml
fn add_crate_to_source_distribution(
    writer: &mut SDistWriter,
    manifest_path: impl AsRef<Path>,
    prefix: impl AsRef<Path>,
    known_path_deps: &HashMap<&String, &PathBuf>,
    root_crate: bool,
    is_path_dep: bool,
) -> Result<()> {
    let output = Command::new("cargo")
        .args(&["package", "--list", "--allow-dirty", "--manifest-path"])
        .arg(manifest_path.as_ref())
        .output()
        .context("Failed to run cargo")?;
    if !output.status.success() {
        bail!(
            "Failed to query file list from cargo: {}\n--- Stdout:\n{}\n--- Stderr:\n{}",
            output.status,
            String::from_utf8_lossy(&output.stdout),
            String::from_utf8_lossy(&output.stderr),
        );
    }
    let file_list: Vec<&Path> = str::from_utf8(&output.stdout)
        .context("Cargo printed invalid utf-8 ಠ_ಠ")?
        .lines()
        .map(Path::new)
        .collect();
    let manifest_dir = manifest_path.as_ref().parent().unwrap();
    let target_source: Vec<(PathBuf, PathBuf)> = file_list
        .iter()
        .map(|relative_to_manifests| {
            let relative_to_cwd = manifest_dir.join(relative_to_manifests);
            (relative_to_manifests.to_path_buf(), relative_to_cwd)
        })
        // We rewrite Cargo.toml and add it separately
        .filter(|(target, _)| {
            target != Path::new("Cargo.toml.orig") && target != Path::new("Cargo.toml")
        })
        .collect();
    if root_crate
        && !target_source
            .iter()
            .any(|(target, _)| target == Path::new("pyproject.toml"))
    {
        bail!(
            "pyproject.toml was not included by `cargo package`. \
                 Please make sure pyproject.toml is not excluded or build with `--no-sdist`"
        )
    }
    let rewritten_cargo_toml = rewrite_cargo_toml(&manifest_path, known_path_deps, is_path_dep)?;
    writer.add_directory(&prefix)?;
    writer.add_bytes(
        prefix
            .as_ref()
            .join(manifest_path.as_ref().file_name().unwrap()),
        rewritten_cargo_toml.as_bytes(),
    )?;
    for (target, source) in target_source {
        writer.add_file(prefix.as_ref().join(target), source)?;
    }
    Ok(())
}
fn add_crate_to_source_distribution ( writer : & mut SDistWriter , manifest_path : impl AsRef < Path > , prefix : impl AsRef < Path > , known_path_deps : & HashMap < & String , & PathBuf > , root_crate : bool , is_path_dep : bool , ) -> Result < ( ) > { let output = Command :: new ( " " ) . args ( & [ " " , " " , " " , " " ] ) . arg ( manifest_path . as_ref ( ) ) . output ( ) . context ( " " ) ? ; if ! output . status . success ( ) { bail ! ( " \n \n \n \n " output status String from_utf8_lossy ( output stdout ) String from_utf8_lossy ( output stderr ) ) ; } let file_list : Vec < & Path > = str :: from_utf8 ( & output . stdout ) . context ( " . lines ( ) . map ( Path :: new ) . collect ( ) ; let manifest_dir = manifest_path . as_ref ( ) . parent ( ) . unwrap ( ) ; let target_source : Vec < ( PathBuf , PathBuf ) > = file_list . iter ( ) . map ( | relative_to_manifests | { let relative_to_cwd = manifest_dir . join ( relative_to_manifests ) ; ( relative_to_manifests . to_path_buf ( ) , relative_to_cwd ) } ) // We rewrite Cargo.toml and add it separately . filter ( | ( target , _ ) | { target != Path :: new ( " " ) && target != Path :: new ( " " ) } ) . collect ( ) ; if root_crate && ! target_source . iter ( ) . any ( | ( target , _ ) | target == Path :: new ( " " ) ) { bail ! ( " \
 " ) } let rewritten_cargo_toml = rewrite_cargo_toml ( & manifest_path , known_path_deps , is_path_dep ) ? ; writer . add_directory ( & prefix ) ? ; writer . add_bytes ( prefix . as_ref ( ) . join ( manifest_path . as_ref ( ) . file_name ( ) . unwrap ( ) ) , rewritten_cargo_toml . as_bytes ( ) , ) ? ; for ( target , source ) in target_source { writer . add_file ( prefix . as_ref ( ) . join ( target ) , source ) ? ; } Ok ( ( ) ) }
Copies the files of a crate to a source distribution, recursively adding path dependencies
and rewriting path entries in Cargo.toml
Copies the files of a crate to a source distribution recursively adding path dependencies and rewriting path entries in Cargo . toml
writer
&mut SDistWriter
manifest_path
impl AsRef<Path>
prefix
impl AsRef<Path>
known_path_deps
&HashMap<&String, &PathBuf>
root_crate
bool
is_path_dep
bool
writer
&mut SDistWriter
manifest_path
impl AsRef<Path>
prefix
impl AsRef<Path>
known_path_deps
&HashMap<&String, &PathBuf>
root_crate
bool
is_path_dep
bool