pub fn find_best_release(
    data: &[WarehouseRelease],
    name: &str,
    version: &Version,
    os: Os,
    python_vers: &Version,
) -> (WarehouseRelease, PackageType) {
    // Find which release we should download. Preferably wheels, and if so, for the right OS and
    // Python version.
    let mut compatible_releases = vec![];
    // Store source releases as a fallback, for if no wheels are found.
    let mut source_releases = vec![];

    for rel in data.iter() {
        let mut compatible = true;
        match rel.packagetype.as_ref() {
            "bdist_wheel" => {
                // Now determine if this wheel is appropriate for the Os and Python version.
                if let Some(py_ver) = &rel.requires_python {
                    // If a version constraint exists, make sure it's compatible.
                    let py_constrs = Constraint::from_str_multiple(py_ver)
                        .expect("Problem parsing constraint from requires_python");

                    for constr in &py_constrs {
                        if !constr.is_compatible(python_vers) {
                            compatible = false;
                        }
                    }
                }

                let wheel_os =
                    os_from_wheel_fname(&rel.filename).expect("Problem getting os from wheel name");
                if wheel_os != os && wheel_os != Os::Any {
                    compatible = false;
                }

                // Packages that use C code(eg numpy) may fail to load C extensions if installing
                // for the wrong version of python (eg  cp35 when python 3.7 is installed), even
                // if `requires_python` doesn't indicate an incompatibility. Check `python_version`
                // instead of `requires_python`.
                // Note that the result of this parse is an any match.
                if let Ok(constrs) = Constraint::from_wh_py_vers(&rel.python_version) {
                    let mut compat_py_v = false;
                    for constr in &constrs {
                        if constr.is_compatible(python_vers) {
                            compat_py_v = true;
                        }
                    }
                    if !compat_py_v {
                        compatible = false;
                    }
                } else {
                    println!(
                        "Unable to match python version from python_version: {}",
                        &rel.python_version
                    )
                };

                if compatible {
                    compatible_releases.push(rel.clone());
                }
            }
            "sdist" => source_releases.push(rel.clone()),
            "bdist_wininst" | "bdist_msi" | "bdist_egg" => (), // Don't execute Windows installers
            _ => {
                println!("Found surprising package type: {}", rel.packagetype);
                continue;
            }
        }
    }

    let best_release;
    let package_type;
    // todo: Sort further / try to match exact python_version if able.
    if compatible_releases.is_empty() {
        if source_releases.is_empty() {
            abort(&format!(
                "Unable to find a compatible release for {}: {}",
                name,
                version.to_string()
            ));
            unreachable!()
        } else {
            best_release = source_releases[0].clone();
            package_type = install::PackageType::Source;
        }
    } else {
        best_release = compatible_releases[0].clone();
        package_type = install::PackageType::Wheel;
    }

    (best_release, package_type)
}
/// Find the most appropriate release to download. Ie Windows vs Linux, wheel vs source.
Find the most appropriate release to download. Ie Windows vs Linux, wheel vs source.
Find the most appropriate release to download . Ie Windows vs Linux wheel vs source .
pub fn find_best_release(
    data: &[WarehouseRelease],
    name: &str,
    version: &Version,
    os: Os,
    python_vers: &Version,
) -> (WarehouseRelease, PackageType) {
    // Find which release we should download. Preferably wheels, and if so, for the right OS and
    // Python version.
    let mut compatible_releases = vec![];
    // Store source releases as a fallback, for if no wheels are found.
    let mut source_releases = vec![];
    for rel in data.iter() {
        let mut compatible = true;
        match rel.packagetype.as_ref() {
            "bdist_wheel" => {
                // Now determine if this wheel is appropriate for the Os and Python version.
                if let Some(py_ver) = &rel.requires_python {
                    // If a version constraint exists, make sure it's compatible.
                    let py_constrs = Constraint::from_str_multiple(py_ver)
                        .expect("Problem parsing constraint from requires_python");
                    for constr in &py_constrs {
                        if !constr.is_compatible(python_vers) {
                            compatible = false;
                        }
                    }
                }
                let wheel_os =
                    os_from_wheel_fname(&rel.filename).expect("Problem getting os from wheel name");
                if wheel_os != os && wheel_os != Os::Any {
                    compatible = false;
                }
                // Packages that use C code(eg numpy) may fail to load C extensions if installing
                // for the wrong version of python (eg  cp35 when python 3.7 is installed), even
                // if `requires_python` doesn't indicate an incompatibility. Check `python_version`
                // instead of `requires_python`.
                // Note that the result of this parse is an any match.
                if let Ok(constrs) = Constraint::from_wh_py_vers(&rel.python_version) {
                    let mut compat_py_v = false;
                    for constr in &constrs {
                        if constr.is_compatible(python_vers) {
                            compat_py_v = true;
                        }
                    }
                    if !compat_py_v {
                        compatible = false;
                    }
                } else {
                    println!(
                        "Unable to match python version from python_version: {}",
                        &rel.python_version
                    )
                };
                if compatible {
                    compatible_releases.push(rel.clone());
                }
            }
            "sdist" => source_releases.push(rel.clone()),
            "bdist_wininst" | "bdist_msi" | "bdist_egg" => (), // Don't execute Windows installers
            _ => {
                println!("Found surprising package type: {}", rel.packagetype);
                continue;
            }
        }
    }
    let best_release;
    let package_type;
    // todo: Sort further / try to match exact python_version if able.
    if compatible_releases.is_empty() {
        if source_releases.is_empty() {
            abort(&format!(
                "Unable to find a compatible release for {}: {}",
                name,
                version.to_string()
            ));
            unreachable!()
        } else {
            best_release = source_releases[0].clone();
            package_type = install::PackageType::Source;
        }
    } else {
        best_release = compatible_releases[0].clone();
        package_type = install::PackageType::Wheel;
    }
    (best_release, package_type)
}
pub fn find_best_release ( data : & [ WarehouseRelease ] , name : & str , version : & Version , os : Os , python_vers : & Version , ) -> ( WarehouseRelease , PackageType ) { // Find which release we should download. Preferably wheels, and if so, for the right OS and // Python version. let mut compatible_releases = vec ! [ ] ; // Store source releases as a fallback, for if no wheels are found. let mut source_releases = vec ! [ ] ; for rel in data . iter ( ) { let mut compatible = true ; match rel . packagetype . as_ref ( ) { " " => { // Now determine if this wheel is appropriate for the Os and Python version. if let Some ( py_ver ) = & rel . requires_python { // If a version constraint exists, make sure it's compatible. let py_constrs = Constraint :: from_str_multiple ( py_ver ) . expect ( " " ) ; for constr in & py_constrs { if ! constr . is_compatible ( python_vers ) { compatible = false ; } } } let wheel_os = os_from_wheel_fname ( & rel . filename ) . expect ( " " ) ; if wheel_os != os && wheel_os != Os :: Any { compatible = false ; } // Packages that use C code(eg numpy) may fail to load C extensions if installing // for the wrong version of python (eg  cp35 when python 3.7 is installed), even // if `requires_python` doesn't indicate an incompatibility. Check `python_version` // instead of `requires_python`. // Note that the result of this parse is an any match. if let Ok ( constrs ) = Constraint :: from_wh_py_vers ( & rel . python_version ) { let mut compat_py_v = false ; for constr in & constrs { if constr . is_compatible ( python_vers ) { compat_py_v = true ; } } if ! compat_py_v { compatible = false ; } } else { println ! ( " " rel python_version ) } ; if compatible { compatible_releases . push ( rel . clone ( ) ) ; } } " " => source_releases . push ( rel . clone ( ) ) , " " | " " | " " => ( ) , // Don't execute Windows installers _ => { println ! ( " " rel packagetype ) ; continue ; } } } let best_release ; let package_type ; // todo: Sort further / try to match exact python_version if able. if compatible_releases . is_empty ( ) { if source_releases . is_empty ( ) { abort ( & format ! ( " " name version to_string ( ) ) ) ; unreachable ! ( ) } else { best_release = source_releases [ 0 ] . clone ( ) ; package_type = install :: PackageType :: Source ; } } else { best_release = compatible_releases [ 0 ] . clone ( ) ; package_type = install :: PackageType :: Wheel ; } ( best_release , package_type ) }
Find the most appropriate release to download.
Find the most appropriate release to download .
data
&[WarehouseRelease]
name
&str
version
&Version
os
Os
python_vers
&Version