Skip to content

Commit

Permalink
add support for more generic python versions (#55)
Browse files Browse the repository at this point in the history
Function is as specified in the issue
  • Loading branch information
lmcgee4 authored Dec 2, 2024
1 parent ec33b15 commit 4333078
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
34 changes: 20 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ home = "0.5.9"
minreq = { version = "2.12.0", features = ["https", "json-using-serde"] }
semver = { version = "1.0.23", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
toml = "0.8.19"
ureq = { version = "2.10.1", features = ["json"] }
zip = "2.2.0"
37 changes: 37 additions & 0 deletions src/utils/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
path::PathBuf,
process,
};
use serde_json::{Value};

// todo docstring
pub fn user_string_to_version(version: Option<&String>) -> Version {
Expand Down Expand Up @@ -120,6 +121,42 @@ pub fn download_file(file_url: &str, file_path: &PathBuf) {
}
}

/// Takes the major and minor version and returns the full version using https://endoflife.date/api/python.json
///
/// # Arguments
/// - `major_minor_version` : a string representing the "x.y" part of the release
///
/// # Output
/// - Will output the full version from the provided major & minor
///
/// #Termination
/// - An error should be thrown if the file for checking is not found, or if the version is not found.
///
/// # Limitations
/// - The function assumes that all data passed to it is in the correct format
pub fn get_full_python_version(major_minor_version : &str) -> Option<String> {
let response = match minreq::get("https://endoflife.date/api/python.json").send() {
Ok(res) if (res.status_code == 200) => res,
Ok(_) => abort("todo", None),
Err(e) =>abort("todo", Some(&e))
};

let json = response.json::<Value>().unwrap();

if let Some(json) = json.as_array() {
for item in json {
for (key, value) in item.as_object().unwrap() {
if (key == "cycle") && (value == major_minor_version){
// returns the latest
return Some(item["latest"].to_string());
}
}
}
}
return None;
}


/// Checks if the specified dependencies are installed by running their `--help` command.
///
/// # Arguments
Expand Down

0 comments on commit 4333078

Please sign in to comment.