pub fn merge_reqs(
    added: &[String],
    dev: bool,
    cfg: &crate::Config,
    cfg_path: &Path,
) -> (Vec<Req>, Vec<Req>) {
    let mut added_reqs = vec![];
    for p in added.iter() {
        let trimmed = p.replace(',', "");
        match Req::from_str(&trimmed, false) {
            Ok(r) => added_reqs.push(r),
            Err(_) => abort(&format!("Unable to parse this package: {}. \
                    Note that installing a specific version via the CLI is currently unsupported. If you need to specify a version,\
                     edit `pyproject.toml`", &p)),
        }
    }

    let existing = if dev { &cfg.dev_reqs } else { &cfg.reqs };

    // Reqs to add to `pyproject.toml`
    let mut added_reqs_unique: Vec<Req> = added_reqs
        .into_iter()
        .filter(|ar| {
            // return true if the added req's not in the cfg reqs, or if it is
            // and the version's different.
            let mut add = true;

            for cr in existing.iter() {
                if cr == ar
                    || (cr.name.to_lowercase() == ar.name.to_lowercase()
                        && ar.constraints.is_empty())
                {
                    // Same req/version exists
                    add = false;
                    break;
                }
            }
            add
        })
        .collect();

    // If no constraints are specified, use a caret constraint with the latest
    // version.
    for added_req in &mut added_reqs_unique {
        if added_req.constraints.is_empty() {
            let (_, vers, _) = if let Ok(r) = dep_resolution::get_version_info(&added_req.name) {
                r
            } else {
                abort("Problem getting latest version of the package you added. Is it spelled correctly? Is the internet OK?");
                unreachable!()
            };

            added_req.constraints.push(Constraint::new(
                ReqType::Caret,
                //                Version::new(vers.major, vers.minor, vers.patch),
                vers,
            ));
        }
    }

    let mut result = vec![]; // Reqs to sync

    // Merge reqs from the config and added via CLI. If there's a conflict in version,
    // use the added req.
    for cr in existing.iter() {
        let mut replaced = false;
        for added_req in &added_reqs_unique {
            if compare_names(&added_req.name, &cr.name) && added_req.constraints != cr.constraints {
                result.push(added_req.clone());
                replaced = true;
                break;
            }
        }
        if !replaced {
            result.push(cr.clone());
        }
    }

    result.append(&mut added_reqs_unique.clone());

    if dev {
        if !added_reqs_unique.is_empty() {
            files::add_reqs_to_cfg(&cfg_path, &[], &added_reqs_unique);
        }
        (cfg.reqs.clone(), result)
    } else {
        if !added_reqs_unique.is_empty() {
            files::add_reqs_to_cfg(&cfg_path, &added_reqs_unique, &[]);
        }
        (result, cfg.dev_reqs.clone())
    }
}
/// Handle reqs added via the CLI. Result is (normal reqs, dev reqs)
Handle reqs added via the CLI. Result is (normal reqs, dev reqs)
Handle reqs added via the CLI . Result is ( normal reqs dev reqs )
pub fn merge_reqs(
    added: &[String],
    dev: bool,
    cfg: &crate::Config,
    cfg_path: &Path,
) -> (Vec<Req>, Vec<Req>) {
    let mut added_reqs = vec![];
    for p in added.iter() {
        let trimmed = p.replace(',', "");
        match Req::from_str(&trimmed, false) {
            Ok(r) => added_reqs.push(r),
            Err(_) => abort(&format!("Unable to parse this package: {}. \
                    Note that installing a specific version via the CLI is currently unsupported. If you need to specify a version,\
                     edit `pyproject.toml`", &p)),
        }
    }
    let existing = if dev { &cfg.dev_reqs } else { &cfg.reqs };
    // Reqs to add to `pyproject.toml`
    let mut added_reqs_unique: Vec<Req> = added_reqs
        .into_iter()
        .filter(|ar| {
            // return true if the added req's not in the cfg reqs, or if it is
            // and the version's different.
            let mut add = true;
            for cr in existing.iter() {
                if cr == ar
                    || (cr.name.to_lowercase() == ar.name.to_lowercase()
                        && ar.constraints.is_empty())
                {
                    // Same req/version exists
                    add = false;
                    break;
                }
            }
            add
        })
        .collect();
    // If no constraints are specified, use a caret constraint with the latest
    // version.
    for added_req in &mut added_reqs_unique {
        if added_req.constraints.is_empty() {
            let (_, vers, _) = if let Ok(r) = dep_resolution::get_version_info(&added_req.name) {
                r
            } else {
                abort("Problem getting latest version of the package you added. Is it spelled correctly? Is the internet OK?");
                unreachable!()
            };
            added_req.constraints.push(Constraint::new(
                ReqType::Caret,
                //                Version::new(vers.major, vers.minor, vers.patch),
                vers,
            ));
        }
    }
    let mut result = vec![]; // Reqs to sync
    // Merge reqs from the config and added via CLI. If there's a conflict in version,
    // use the added req.
    for cr in existing.iter() {
        let mut replaced = false;
        for added_req in &added_reqs_unique {
            if compare_names(&added_req.name, &cr.name) && added_req.constraints != cr.constraints {
                result.push(added_req.clone());
                replaced = true;
                break;
            }
        }
        if !replaced {
            result.push(cr.clone());
        }
    }
    result.append(&mut added_reqs_unique.clone());
    if dev {
        if !added_reqs_unique.is_empty() {
            files::add_reqs_to_cfg(&cfg_path, &[], &added_reqs_unique);
        }
        (cfg.reqs.clone(), result)
    } else {
        if !added_reqs_unique.is_empty() {
            files::add_reqs_to_cfg(&cfg_path, &added_reqs_unique, &[]);
        }
        (result, cfg.dev_reqs.clone())
    }
}
pub fn merge_reqs ( added : & [ String ] , dev : bool , cfg : & crate :: Config , cfg_path : & Path , ) -> ( Vec < Req > , Vec < Req > ) { let mut added_reqs = vec ! [ ] ; for p in added . iter ( ) { let trimmed = p . replace ( ',' , " " ) ; match Req :: from_str ( & trimmed , false ) { Ok ( r ) => added_reqs . push ( r ) , Err ( _ ) => abort ( & format ! ( " \
 \
 " p ) ) , } } let existing = if dev { & cfg . dev_reqs } else { & cfg . reqs } ; // Reqs to add to `pyproject.toml` let mut added_reqs_unique : Vec < Req > = added_reqs . into_iter ( ) . filter ( | ar | { // return true if the added req's not in the cfg reqs, or if it is // and the version's different. let mut add = true ; for cr in existing . iter ( ) { if cr == ar || ( cr . name . to_lowercase ( ) == ar . name . to_lowercase ( ) && ar . constraints . is_empty ( ) ) { // Same req/version exists add = false ; break ; } } add } ) . collect ( ) ; // If no constraints are specified, use a caret constraint with the latest // version. for added_req in & mut added_reqs_unique { if added_req . constraints . is_empty ( ) { let ( _ , vers , _ ) = if let Ok ( r ) = dep_resolution :: get_version_info ( & added_req . name ) { r } else { abort ( " " ) ; unreachable ! ( ) } ; added_req . constraints . push ( Constraint :: new ( ReqType :: Caret , //                Version::new(vers.major, vers.minor, vers.patch), vers , ) ) ; } } let mut result = vec ! [ ] ; // Reqs to sync // Merge reqs from the config and added via CLI. If there's a conflict in version, // use the added req. for cr in existing . iter ( ) { let mut replaced = false ; for added_req in & added_reqs_unique { if compare_names ( & added_req . name , & cr . name ) && added_req . constraints != cr . constraints { result . push ( added_req . clone ( ) ) ; replaced = true ; break ; } } if ! replaced { result . push ( cr . clone ( ) ) ; } } result . append ( & mut added_reqs_unique . clone ( ) ) ; if dev { if ! added_reqs_unique . is_empty ( ) { files :: add_reqs_to_cfg ( & cfg_path , & [ ] , & added_reqs_unique ) ; } ( cfg . reqs . clone ( ) , result ) } else { if ! added_reqs_unique . is_empty ( ) { files :: add_reqs_to_cfg ( & cfg_path , & added_reqs_unique , & [ ] ) ; } ( result , cfg . dev_reqs . clone ( ) ) } }
Handle reqs added via the CLI.
Handle reqs added via the CLI .
added
&[String]
dev
bool
cfg
&crate::Config
cfg_path
&Path