-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
corey
committed
Mar 17, 2024
1 parent
b647ef1
commit 600cc85
Showing
11 changed files
with
313 additions
and
974 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/// Wrappers around the PyPi JSON API instead of pip | ||
/// https://warehouse.pypa.io/api-reference/json.html | ||
use crate::Result; | ||
|
||
lazy_static! { | ||
pub static ref PYPI_URL_BASE: &'static str = "https://pypi.org"; | ||
pub static ref PYPI_TEST_URL_BASE: &'static str = "https://test.pypi.org"; | ||
} | ||
|
||
pub fn get_package_details<S: AsRef<str>>(package_name: S) -> Result<serde_json::Value> { | ||
get_package_details_from(package_name, *PYPI_URL_BASE) | ||
} | ||
|
||
pub fn get_package_details_from_test_server<S: AsRef<str>>(package_name: S) -> Result<serde_json::Value> { | ||
get_package_details_from(package_name, *PYPI_TEST_URL_BASE) | ||
} | ||
|
||
pub fn get_package_details_from<S1: AsRef<str>, S2: AsRef<str>>(package_name: S1, url: S2) -> Result<serde_json::Value> | ||
{ | ||
let url = format!("{}/pypi/{}/json", url.as_ref(), package_name.as_ref()); | ||
let response = reqwest::blocking::get(&url)?; | ||
Ok(response.json::<serde_json::Value>()?) | ||
} | ||
|
||
pub fn get_package_versions<S: AsRef<str>>(package_name: S) -> Result<Vec<String>> { | ||
get_package_versions_from(package_name, *PYPI_URL_BASE) | ||
} | ||
|
||
pub fn get_package_versions_from_test_server<S: AsRef<str>>(package_name: S) -> Result<Vec<String>> { | ||
get_package_versions_from(package_name, *PYPI_TEST_URL_BASE) | ||
} | ||
|
||
pub fn get_package_versions_from<S1: AsRef<str>, S2: AsRef<str>>(package_name: S1, url: S2) -> Result<Vec<String>> { | ||
let res = get_package_details_from(package_name.as_ref(), url)?; | ||
let versions = res["releases"].as_object().unwrap().keys().map( |k| k.to_string()).collect::<Vec<String>>(); | ||
Ok(versions) | ||
} | ||
|
||
pub fn is_package_version_available<S1: AsRef<str>, S2: AsRef<str>>(package_name: S1, version: S2) -> Result<bool> { | ||
let pkgs = get_package_versions(package_name)?; | ||
Ok(pkgs.iter().find(|v| v == &version.as_ref()).is_none()) | ||
} | ||
|
||
pub fn is_package_version_available_on_test_server<S1: AsRef<str>, S2: AsRef<str>>(package_name: S1, version: S2) -> Result<bool> { | ||
let pkgs = get_package_versions_from_test_server(package_name)?; | ||
Ok(pkgs.iter().find(|v| v == &version.as_ref()).is_none()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.