pub fn download_and_install_git(
    name: &str,
    url: &str,
    git_path: &Path,
    paths: &util::Paths,
) -> util::Metadata {
    if !git_path.exists() {
        fs::create_dir_all(git_path).expect("Problem creating git path");
    }

    let folder_name = util::standardize_name(name); // todo: Will this always work?
                                                    //    match url {
                                                    //        GitPath::Git(url) => {
                                                    // Download the repo into the pyflow folder.
                                                    // todo: Handle checking if it's current and correct; not just a matching folder
                                                    // todo name.
    if !&git_path.join(&folder_name).exists() && commands::download_git_repo(url, git_path).is_err()
    {
        util::abort(&format!("Problem cloning this repo: {}", url));
    } // todo to keep dl small while troubleshooting.
      //        }
      //        GitPath::Path(path) => {
      //            let f = &git_path.join(&folder_name);
      //            if !&f.exists() {
      //                fs::create_dir(f).expect("Problem creating dir for a path dependency");
      //                let options = fs_extra::dir::CopyOptions::new();
      //                fs_extra::dir::copy(PathBuf::from(path), &git_path, &options)
      //                    .expect("Problem copying path requirement to lib folder");
      //            }
      //        }
      //}

    // Build a wheel from the repo
    let output = Command::new(paths.bin.join("python"))
        // We assume that the module code is in the repo's immediate subfolder that has
        // the package's name.
        .current_dir(&git_path.join(&folder_name))
        .args(&["setup.py", "bdist_wheel"])
        .output()
        .expect("Problem running setup.py bdist_wheel");
    util::check_command_output(&output, "running setup.py bdist_wheel");

    let archive_path = util::find_first_file(&git_path.join(folder_name).join("dist"));
    let filename = archive_path
        .file_name()
        .expect("Problem pulling filename from archive path");

    // We've built the wheel; now move it into the lib path, as we would for a wheel download
    // from Pypi.
    let options = fs_extra::file::CopyOptions::new();
    fs_extra::file::move_file(&archive_path, paths.lib.join(&filename), &options)
        .expect("Problem moving the wheel.");

    let archive_path = &paths.lib.join(&filename);
    let archive_file = util::open_archive(archive_path);

    util::extract_zip(&archive_file, &paths.lib, &None, &None);

    // Use the wheel's name to find the dist-info path, to avoid the chicken-egg scenario
    // of need the dist-info path to find the version.
    let re = Regex::new(r"^(.*?)-(.*?)-.*$").unwrap();
    let dist_info = if let Some(caps) = re.captures(filename.to_str().unwrap()) {
        format!(
            "{}-{}.dist-info",
            caps.get(1).unwrap().as_str(),
            caps.get(2).unwrap().as_str()
        )
    } else {
        util::abort("Unable to find the dist info path from wheel filename")
    };

    let metadata = util::parse_metadata(&paths.lib.join(dist_info).join("METADATA")); // todo temp!

    setup_scripts(name, &metadata.version, &paths.lib, &paths.entry_pt);

    // Remove the created and moved wheel
    if fs::remove_file(&archive_path).is_err() {
        util::abort(&format!(
            "Problem removing this wheel built from a git repo: {:?}",
            archive_path
        ));
    }
    metadata
}
/// Clone a git repo of a Python package, and build/install a wheel from it.
/// Or do the same, but with a path instead of git.
Clone a git repo of a Python package, and build/install a wheel from it.
Or do the same, but with a path instead of git.
Clone a git repo of a Python package and build / install a wheel from it . Or do the same but with a path instead of git .
pub fn download_and_install_git(
    name: &str,
    url: &str,
    git_path: &Path,
    paths: &util::Paths,
) -> util::Metadata {
    if !git_path.exists() {
        fs::create_dir_all(git_path).expect("Problem creating git path");
    }
    let folder_name = util::standardize_name(name); // todo: Will this always work?
                                                    //    match url {
                                                    //        GitPath::Git(url) => {
                                                    // Download the repo into the pyflow folder.
                                                    // todo: Handle checking if it's current and correct; not just a matching folder
                                                    // todo name.
    if !&git_path.join(&folder_name).exists() && commands::download_git_repo(url, git_path).is_err()
    {
        util::abort(&format!("Problem cloning this repo: {}", url));
    } // todo to keep dl small while troubleshooting.
      //        }
      //        GitPath::Path(path) => {
      //            let f = &git_path.join(&folder_name);
      //            if !&f.exists() {
      //                fs::create_dir(f).expect("Problem creating dir for a path dependency");
      //                let options = fs_extra::dir::CopyOptions::new();
      //                fs_extra::dir::copy(PathBuf::from(path), &git_path, &options)
      //                    .expect("Problem copying path requirement to lib folder");
      //            }
      //        }
      //}
    // Build a wheel from the repo
    let output = Command::new(paths.bin.join("python"))
        // We assume that the module code is in the repo's immediate subfolder that has
        // the package's name.
        .current_dir(&git_path.join(&folder_name))
        .args(&["setup.py", "bdist_wheel"])
        .output()
        .expect("Problem running setup.py bdist_wheel");
    util::check_command_output(&output, "running setup.py bdist_wheel");
    let archive_path = util::find_first_file(&git_path.join(folder_name).join("dist"));
    let filename = archive_path
        .file_name()
        .expect("Problem pulling filename from archive path");
    // We've built the wheel; now move it into the lib path, as we would for a wheel download
    // from Pypi.
    let options = fs_extra::file::CopyOptions::new();
    fs_extra::file::move_file(&archive_path, paths.lib.join(&filename), &options)
        .expect("Problem moving the wheel.");
    let archive_path = &paths.lib.join(&filename);
    let archive_file = util::open_archive(archive_path);
    util::extract_zip(&archive_file, &paths.lib, &None, &None);
    // Use the wheel's name to find the dist-info path, to avoid the chicken-egg scenario
    // of need the dist-info path to find the version.
    let re = Regex::new(r"^(.*?)-(.*?)-.*$").unwrap();
    let dist_info = if let Some(caps) = re.captures(filename.to_str().unwrap()) {
        format!(
            "{}-{}.dist-info",
            caps.get(1).unwrap().as_str(),
            caps.get(2).unwrap().as_str()
        )
    } else {
        util::abort("Unable to find the dist info path from wheel filename")
    };
    let metadata = util::parse_metadata(&paths.lib.join(dist_info).join("METADATA")); // todo temp!
    setup_scripts(name, &metadata.version, &paths.lib, &paths.entry_pt);
    // Remove the created and moved wheel
    if fs::remove_file(&archive_path).is_err() {
        util::abort(&format!(
            "Problem removing this wheel built from a git repo: {:?}",
            archive_path
        ));
    }
    metadata
}
pub fn download_and_install_git ( name : & str , url : & str , git_path : & Path , paths : & util :: Paths , ) -> util :: Metadata { if ! git_path . exists ( ) { fs :: create_dir_all ( git_path ) . expect ( " " ) ; } let folder_name = util :: standardize_name ( name ) ; // todo: Will this always work? //    match url { //        GitPath::Git(url) => { // Download the repo into the pyflow folder. // todo: Handle checking if it's current and correct; not just a matching folder // todo name. if ! & git_path . join ( & folder_name ) . exists ( ) && commands :: download_git_repo ( url , git_path ) . is_err ( ) { util :: abort ( & format ! ( " " url ) ) ; } // todo to keep dl small while troubleshooting. //        } //        GitPath::Path(path) => { //            let f = &git_path.join(&folder_name); //            if !&f.exists() { //                fs::create_dir(f).expect("Problem creating dir for a path dependency"); //                let options = fs_extra::dir::CopyOptions::new(); //                fs_extra::dir::copy(PathBuf::from(path), &git_path, &options) //                    .expect("Problem copying path requirement to lib folder"); //            } //        } //} // Build a wheel from the repo let output = Command :: new ( paths . bin . join ( " " ) ) // We assume that the module code is in the repo's immediate subfolder that has // the package's name. . current_dir ( & git_path . join ( & folder_name ) ) . args ( & [ " " , " " ] ) . output ( ) . expect ( " " ) ; util :: check_command_output ( & output , " " ) ; let archive_path = util :: find_first_file ( & git_path . join ( folder_name ) . join ( " " ) ) ; let filename = archive_path . file_name ( ) . expect ( " " ) ; // We've built the wheel; now move it into the lib path, as we would for a wheel download // from Pypi. let options = fs_extra :: file :: CopyOptions :: new ( ) ; fs_extra :: file :: move_file ( & archive_path , paths . lib . join ( & filename ) , & options ) . expect ( " " ) ; let archive_path = & paths . lib . join ( & filename ) ; let archive_file = util :: open_archive ( archive_path ) ; util :: extract_zip ( & archive_file , & paths . lib , & None , & None ) ; // Use the wheel's name to find the dist-info path, to avoid the chicken-egg scenario // of need the dist-info path to find the version. let re = Regex :: new ( r"^(.*?)-(.*?)-.*$" ) . unwrap ( ) ; let dist_info = if let Some ( caps ) = re . captures ( filename . to_str ( ) . unwrap ( ) ) { format ! ( " " caps get ( 1 ) unwrap ( ) as_str ( ) caps get ( 2 ) unwrap ( ) as_str ( ) ) } else { util :: abort ( " " ) } ; let metadata = util :: parse_metadata ( & paths . lib . join ( dist_info ) . join ( " " ) ) ; // todo temp! setup_scripts ( name , & metadata . version , & paths . lib , & paths . entry_pt ) ; // Remove the created and moved wheel if fs :: remove_file ( & archive_path ) . is_err ( ) { util :: abort ( & format ! ( " " archive_path ) ) ; } metadata }
Clone a git repo of a Python package, and build/install a wheel from it.
Clone a git repo of a Python package and build / install a wheel from it .
name
&str
url
&str
git_path
&Path
paths
&util::Paths
name
&str
url
&str
git_path
&Path
paths
&util::Paths