fn sync_deps(
    paths: &util::Paths,
    lock_packs: &[LockPackage],
    dont_uninstall: &[String],
    installed: &[(String, Version, Vec<String>)],
    os: util::Os,
    python_vers: &Version,
) {
    let packages: Vec<PackToInstall> = lock_packs
        .iter()
        .map(|lp| {
            (
                (
                    util::standardize_name(&lp.name),
                    Version::from_str(&lp.version).expect("Problem parsing lock version"),
                ),
                lp.rename.as_ref().map(|rn| parse_lockpack_rename(rn)),
            )
        })
        .collect();

    // todo shim. Use top-level A/R. We discard it temporarily while working other issues.
    let installed: Vec<(String, Version)> = installed
        .iter()
        // Don't standardize name here; see note below in to_uninstall.
        .map(|t| (t.0.clone(), t.1.clone()))
        .collect();

    // Filter by not-already-installed.
    let to_install: Vec<&PackToInstall> = packages
        .iter()
        .filter(|(pack, _)| {
            let mut contains = false;
            for inst in &installed {
                if util::compare_names(&pack.0, &inst.0) && pack.1 == inst.1 {
                    contains = true;
                    break;
                }
            }

            // The typing module is sometimes downloaded, causing a conflict/improper
            // behavior compared to the built in module.
            !contains && pack.0 != "typing"
        })
        .collect();

    // todo: Once you include rename info in installed, you won't need to use the map logic here.
    let packages_only: Vec<&(String, Version)> = packages.iter().map(|(p, _)| p).collect();
    let to_uninstall: Vec<&(String, Version)> = installed
        .iter()
        .filter(|inst| {
            // Don't standardize the name here; we need original capitalization to uninstall
            // metadata etc.
            let inst = (inst.0.clone(), inst.1.clone());
            let mut contains = false;
            // We can't just use the contains method, due to needing compare_names().
            for pack in &packages_only {
                if util::compare_names(&pack.0, &inst.0) && pack.1 == inst.1 {
                    contains = true;
                    break;
                }
            }

            for name in dont_uninstall {
                if util::compare_names(name, &inst.0) {
                    contains = true;
                    break;
                }
            }

            !contains
        })
        .collect();

    for (name, version) in &to_uninstall {
        // todo: Deal with renamed. Currently won't work correctly with them.
        install::uninstall(name, version, &paths.lib)
    }

    for ((name, version), rename) in &to_install {
        let data =
            res::get_warehouse_release(name, version).expect("Problem getting warehouse data");

        let (best_release, package_type) =
            util::find_best_release(&data, name, version, os, python_vers);

        // Powershell  doesn't like emojis
        // todo format literal issues, so repeating this whole statement.
        #[cfg(target_os = "windows")]
        util::print_color_(&format!("Installing {}", &name), Color::Cyan);
        #[cfg(target_os = "linux")]
        util::print_color_(&format!("⬇ Installing {}", &name), Color::Cyan);
        #[cfg(target_os = "macos")]
        util::print_color_(&format!("⬇ Installing {}", &name), Color::Cyan);
        println!(" {} ...", &version.to_string_color());

        if install::download_and_install_package(
            name,
            version,
            &best_release.url,
            &best_release.filename,
            &best_release.digests.sha256,
            paths,
            package_type,
            rename,
        )
        .is_err()
        {
            abort("Problem downloading packages");
        }
    }
    // Perform renames after all packages are installed, or we may attempt to rename a package
    // we haven't yet installed.
    for ((name, version), rename) in &to_install {
        if let Some((id, new)) = rename {
            // Rename in the renamed package

            let renamed_path = &paths.lib.join(util::standardize_name(new));

            util::wait_for_dirs(&[renamed_path.clone()]).expect("Problem creating renamed path");
            install::rename_package_files(renamed_path, name, new);

            // Rename in the parent calling the renamed package. // todo: Multiple parents?
            let parent = lock_packs
                .iter()
                .find(|lp| lp.id == *id)
                .expect("Can't find parent calling renamed package");
            install::rename_package_files(
                &paths.lib.join(util::standardize_name(&parent.name)),
                name,
                new,
            );

            // todo: Handle this more generally, in case we don't have proper semver dist-info paths.
            install::rename_metadata(
                &paths
                    .lib
                    .join(&format!("{}-{}.dist-info", name, version.to_string())),
                name,
                new,
            );
        }
    }
}
/// Install/uninstall deps as required from the passed list, and re-write the lock file.
Install/uninstall deps as required from the passed list, and re-write the lock file.
Install / uninstall deps as required from the passed list and re - write the lock file .
fn sync_deps(
    paths: &util::Paths,
    lock_packs: &[LockPackage],
    dont_uninstall: &[String],
    installed: &[(String, Version, Vec<String>)],
    os: util::Os,
    python_vers: &Version,
) {
    let packages: Vec<PackToInstall> = lock_packs
        .iter()
        .map(|lp| {
            (
                (
                    util::standardize_name(&lp.name),
                    Version::from_str(&lp.version).expect("Problem parsing lock version"),
                ),
                lp.rename.as_ref().map(|rn| parse_lockpack_rename(rn)),
            )
        })
        .collect();
    // todo shim. Use top-level A/R. We discard it temporarily while working other issues.
    let installed: Vec<(String, Version)> = installed
        .iter()
        // Don't standardize name here; see note below in to_uninstall.
        .map(|t| (t.0.clone(), t.1.clone()))
        .collect();
    // Filter by not-already-installed.
    let to_install: Vec<&PackToInstall> = packages
        .iter()
        .filter(|(pack, _)| {
            let mut contains = false;
            for inst in &installed {
                if util::compare_names(&pack.0, &inst.0) && pack.1 == inst.1 {
                    contains = true;
                    break;
                }
            }
            // The typing module is sometimes downloaded, causing a conflict/improper
            // behavior compared to the built in module.
            !contains && pack.0 != "typing"
        })
        .collect();
    // todo: Once you include rename info in installed, you won't need to use the map logic here.
    let packages_only: Vec<&(String, Version)> = packages.iter().map(|(p, _)| p).collect();
    let to_uninstall: Vec<&(String, Version)> = installed
        .iter()
        .filter(|inst| {
            // Don't standardize the name here; we need original capitalization to uninstall
            // metadata etc.
            let inst = (inst.0.clone(), inst.1.clone());
            let mut contains = false;
            // We can't just use the contains method, due to needing compare_names().
            for pack in &packages_only {
                if util::compare_names(&pack.0, &inst.0) && pack.1 == inst.1 {
                    contains = true;
                    break;
                }
            }
            for name in dont_uninstall {
                if util::compare_names(name, &inst.0) {
                    contains = true;
                    break;
                }
            }
            !contains
        })
        .collect();
    for (name, version) in &to_uninstall {
        // todo: Deal with renamed. Currently won't work correctly with them.
        install::uninstall(name, version, &paths.lib)
    }
    for ((name, version), rename) in &to_install {
        let data =
            res::get_warehouse_release(name, version).expect("Problem getting warehouse data");
        let (best_release, package_type) =
            util::find_best_release(&data, name, version, os, python_vers);
        // Powershell  doesn't like emojis
        // todo format literal issues, so repeating this whole statement.
        #[cfg(target_os = "windows")]
        util::print_color_(&format!("Installing {}", &name), Color::Cyan);
        #[cfg(target_os = "linux")]
        util::print_color_(&format!("⬇ Installing {}", &name), Color::Cyan);
        #[cfg(target_os = "macos")]
        util::print_color_(&format!("⬇ Installing {}", &name), Color::Cyan);
        println!(" {} ...", &version.to_string_color());
        if install::download_and_install_package(
            name,
            version,
            &best_release.url,
            &best_release.filename,
            &best_release.digests.sha256,
            paths,
            package_type,
            rename,
        )
        .is_err()
        {
            abort("Problem downloading packages");
        }
    }
    // Perform renames after all packages are installed, or we may attempt to rename a package
    // we haven't yet installed.
    for ((name, version), rename) in &to_install {
        if let Some((id, new)) = rename {
            // Rename in the renamed package
            let renamed_path = &paths.lib.join(util::standardize_name(new));
            util::wait_for_dirs(&[renamed_path.clone()]).expect("Problem creating renamed path");
            install::rename_package_files(renamed_path, name, new);
            // Rename in the parent calling the renamed package. // todo: Multiple parents?
            let parent = lock_packs
                .iter()
                .find(|lp| lp.id == *id)
                .expect("Can't find parent calling renamed package");
            install::rename_package_files(
                &paths.lib.join(util::standardize_name(&parent.name)),
                name,
                new,
            );
            // todo: Handle this more generally, in case we don't have proper semver dist-info paths.
            install::rename_metadata(
                &paths
                    .lib
                    .join(&format!("{}-{}.dist-info", name, version.to_string())),
                name,
                new,
            );
        }
    }
}
fn sync_deps ( paths : & util :: Paths , lock_packs : & [ LockPackage ] , dont_uninstall : & [ String ] , installed : & [ ( String , Version , Vec < String > ) ] , os : util :: Os , python_vers : & Version , ) { let packages : Vec < PackToInstall > = lock_packs . iter ( ) . map ( | lp | { ( ( util :: standardize_name ( & lp . name ) , Version :: from_str ( & lp . version ) . expect ( " " ) , ) , lp . rename . as_ref ( ) . map ( | rn | parse_lockpack_rename ( rn ) ) , ) } ) . collect ( ) ; // todo shim. Use top-level A/R. We discard it temporarily while working other issues. let installed : Vec < ( String , Version ) > = installed . iter ( ) // Don't standardize name here; see note below in to_uninstall. . map ( | t | ( t . 0 . clone ( ) , t . 1 . clone ( ) ) ) . collect ( ) ; // Filter by not-already-installed. let to_install : Vec < & PackToInstall > = packages . iter ( ) . filter ( | ( pack , _ ) | { let mut contains = false ; for inst in & installed { if util :: compare_names ( & pack . 0 , & inst . 0 ) && pack . 1 == inst . 1 { contains = true ; break ; } } // The typing module is sometimes downloaded, causing a conflict/improper // behavior compared to the built in module. ! contains && pack . 0 != " " } ) . collect ( ) ; // todo: Once you include rename info in installed, you won't need to use the map logic here. let packages_only : Vec < & ( String , Version ) > = packages . iter ( ) . map ( | ( p , _ ) | p ) . collect ( ) ; let to_uninstall : Vec < & ( String , Version ) > = installed . iter ( ) . filter ( | inst | { // Don't standardize the name here; we need original capitalization to uninstall // metadata etc. let inst = ( inst . 0 . clone ( ) , inst . 1 . clone ( ) ) ; let mut contains = false ; // We can't just use the contains method, due to needing compare_names(). for pack in & packages_only { if util :: compare_names ( & pack . 0 , & inst . 0 ) && pack . 1 == inst . 1 { contains = true ; break ; } } for name in dont_uninstall { if util :: compare_names ( name , & inst . 0 ) { contains = true ; break ; } } ! contains } ) . collect ( ) ; for ( name , version ) in & to_uninstall { // todo: Deal with renamed. Currently won't work correctly with them. install :: uninstall ( name , version , & paths . lib ) } for ( ( name , version ) , rename ) in & to_install { let data = res :: get_warehouse_release ( name , version ) . expect ( " " ) ; let ( best_release , package_type ) = util :: find_best_release ( & data , name , version , os , python_vers ) ; // Powershell  doesn't like emojis // todo format literal issues, so repeating this whole statement. # [ cfg ( target_os " " ) ] util :: print_color_ ( & format ! ( " " name ) , Color :: Cyan ) ; # [ cfg ( target_os " " ) ] util :: print_color_ ( & format ! ( " me), C lor:: Cy an); # [ cfg ( target_os " " ) ] util :: print_color_ ( & format ! ( " me), C lor:: Cy an); println ! ( " " version to_string_color ( ) ) ; if install :: download_and_install_package ( name , version , & best_release . url , & best_release . filename , & best_release . digests . sha256 , paths , package_type , rename , ) . is_err ( ) { abort ( " " ) ; } } // Perform renames after all packages are installed, or we may attempt to rename a package // we haven't yet installed. for ( ( name , version ) , rename ) in & to_install { if let Some ( ( id , new ) ) = rename { // Rename in the renamed package let renamed_path = & paths . lib . join ( util :: standardize_name ( new ) ) ; util :: wait_for_dirs ( & [ renamed_path . clone ( ) ] ) . expect ( " " ) ; install :: rename_package_files ( renamed_path , name , new ) ; // Rename in the parent calling the renamed package. // todo: Multiple parents? let parent = lock_packs . iter ( ) . find ( | lp | lp . id == * id ) . expect ( " " ) ; install :: rename_package_files ( & paths . lib . join ( util :: standardize_name ( & parent . name ) ) , name , new , ) ; // todo: Handle this more generally, in case we don't have proper semver dist-info paths. install :: rename_metadata ( & paths . lib . join ( & format ! ( " " name version to_string ( ) ) ) , name , new , ) ; } } }
Install/uninstall deps as required from the passed list, and re-write the lock file.
Install / uninstall deps as required from the passed list and re - write the lock file .
paths
&util::Paths
lock_packs
&[LockPackage]
dont_uninstall
&[String]
installed
&[(String, Version, Vec<String>)]
os
util::Os
python_vers
&Version
paths
&util::Paths
lock_packs
&[LockPackage]
dont_uninstall
&[String]
installed
&[(String, Version, Vec<String>)]
os
util::Os
python_vers
&Version