pub fn find_or_create_venv(
    cfg_vers: &Version,
    pypackages_dir: &Path,
    pyflow_dir: &Path,
    dep_cache_path: &Path,
) -> (PathBuf, Version) {
    let venvs = find_venvs(pypackages_dir);
    // The version's explicitly specified; check if an environment for that version
    let compatible_venvs: Vec<&(u32, u32)> = venvs
        .iter()
        .filter(|(ma, mi)| cfg_vers.major == *ma && cfg_vers.minor == *mi)
        .collect();

    let vers_path;
    let py_vers;
    match compatible_venvs.len() {
        0 => {
            let vers =
                py_versions::create_venv(cfg_vers, pypackages_dir, pyflow_dir, dep_cache_path);
            vers_path = pypackages_dir.join(&format!("{}.{}", vers.major, vers.minor));
            py_vers = Version::new_short(vers.major, vers.minor); // Don't include patch.
        }
        1 => {
            vers_path = pypackages_dir.join(&format!(
                "{}.{}",
                compatible_venvs[0].0, compatible_venvs[0].1
            ));
            py_vers = Version::new_short(compatible_venvs[0].0, compatible_venvs[0].1);
        }
        _ => {
            abort(
                // todo: Handle this, eg by letting the user pick the one to use?
                "Multiple compatible Python environments found
                for this project.",
            );
            unreachable!()
        }
    }

    #[cfg(target_os = "windows")]
    {
        (vers_path, py_vers)
    }

    #[cfg(target_os = "linux")]
    {
        let vers_path = fs::canonicalize(vers_path);
        let vers_path = match vers_path {
            Ok(path) => path,
            Err(error) => {
                abort(&format!(
                    "Problem converting path to absolute path: {:?}",
                    error
                ));
                unreachable!()
            }
        };
        (vers_path, py_vers)
    }

    #[cfg(target_os = "macos")]
    {
        let vers_path = fs::canonicalize(vers_path);
        let vers_path = match vers_path {
            Ok(path) => path,
            Err(error) => {
                abort(&format!(
                    "Problem converting path to absolute path: {:?}",
                    error
                ));
                unreachable!()
            }
        };
        (vers_path, py_vers)
    }
}
/// Find venv info, creating a venv as required.
Find venv info, creating a venv as required.
Find venv info creating a venv as required .
pub fn find_or_create_venv(
    cfg_vers: &Version,
    pypackages_dir: &Path,
    pyflow_dir: &Path,
    dep_cache_path: &Path,
) -> (PathBuf, Version) {
    let venvs = find_venvs(pypackages_dir);
    // The version's explicitly specified; check if an environment for that version
    let compatible_venvs: Vec<&(u32, u32)> = venvs
        .iter()
        .filter(|(ma, mi)| cfg_vers.major == *ma && cfg_vers.minor == *mi)
        .collect();
    let vers_path;
    let py_vers;
    match compatible_venvs.len() {
        0 => {
            let vers =
                py_versions::create_venv(cfg_vers, pypackages_dir, pyflow_dir, dep_cache_path);
            vers_path = pypackages_dir.join(&format!("{}.{}", vers.major, vers.minor));
            py_vers = Version::new_short(vers.major, vers.minor); // Don't include patch.
        }
        1 => {
            vers_path = pypackages_dir.join(&format!(
                "{}.{}",
                compatible_venvs[0].0, compatible_venvs[0].1
            ));
            py_vers = Version::new_short(compatible_venvs[0].0, compatible_venvs[0].1);
        }
        _ => {
            abort(
                // todo: Handle this, eg by letting the user pick the one to use?
                "Multiple compatible Python environments found
                for this project.",
            );
            unreachable!()
        }
    }
    #[cfg(target_os = "windows")]
    {
        (vers_path, py_vers)
    }
    #[cfg(target_os = "linux")]
    {
        let vers_path = fs::canonicalize(vers_path);
        let vers_path = match vers_path {
            Ok(path) => path,
            Err(error) => {
                abort(&format!(
                    "Problem converting path to absolute path: {:?}",
                    error
                ));
                unreachable!()
            }
        };
        (vers_path, py_vers)
    }
    #[cfg(target_os = "macos")]
    {
        let vers_path = fs::canonicalize(vers_path);
        let vers_path = match vers_path {
            Ok(path) => path,
            Err(error) => {
                abort(&format!(
                    "Problem converting path to absolute path: {:?}",
                    error
                ));
                unreachable!()
            }
        };
        (vers_path, py_vers)
    }
}
pub fn find_or_create_venv ( cfg_vers : & Version , pypackages_dir : & Path , pyflow_dir : & Path , dep_cache_path : & Path , ) -> ( PathBuf , Version ) { let venvs = find_venvs ( pypackages_dir ) ; // The version's explicitly specified; check if an environment for that version let compatible_venvs : Vec < & ( u32 , u32 ) > = venvs . iter ( ) . filter ( | ( ma , mi ) | cfg_vers . major == * ma && cfg_vers . minor == * mi ) . collect ( ) ; let vers_path ; let py_vers ; match compatible_venvs . len ( ) { 0 => { let vers = py_versions :: create_venv ( cfg_vers , pypackages_dir , pyflow_dir , dep_cache_path ) ; vers_path = pypackages_dir . join ( & format ! ( " " vers major vers minor ) ) ; py_vers = Version :: new_short ( vers . major , vers . minor ) ; // Don't include patch. } 1 => { vers_path = pypackages_dir . join ( & format ! ( " " compatible_venvs [ 0 ] 0 compatible_venvs [ 0 ] 1 ) ) ; py_vers = Version :: new_short ( compatible_venvs [ 0 ] . 0 , compatible_venvs [ 0 ] . 1 ) ; } _ => { abort ( // todo: Handle this, eg by letting the user pick the one to use? " " , ) ; unreachable ! ( ) } } # [ cfg ( target_os " " ) ] { ( vers_path , py_vers ) } # [ cfg ( target_os " " ) ] { let vers_path = fs :: canonicalize ( vers_path ) ; let vers_path = match vers_path { Ok ( path ) => path , Err ( error ) => { abort ( & format ! ( " " error ) ) ; unreachable ! ( ) } } ; ( vers_path , py_vers ) } # [ cfg ( target_os " " ) ] { let vers_path = fs :: canonicalize ( vers_path ) ; let vers_path = match vers_path { Ok ( path ) => path , Err ( error ) => { abort ( & format ! ( " " error ) ) ; unreachable ! ( ) } } ; ( vers_path , py_vers ) } }
Find venv info, creating a venv as required.
Find venv info creating a venv as required .
cfg_vers
&Version
pypackages_dir
&Path
pyflow_dir
&Path
dep_cache_path
&Path