Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cache and retyr pypi name mapping #839

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 127 additions & 7 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dirs = "5.0.1"
dunce = "1.0.4"
flate2 = "1.0.28"
futures = "0.3.30"
http-cache-reqwest = "0.13.0"
human_bytes = "0.4.3"
humantime = "2.1.0"
indexmap = { version = "2.2.2", features = ["serde"] }
Expand All @@ -56,6 +57,7 @@ rattler_virtual_packages = { version = "0.18.0", default-features = false }
regex = "1.10.3"
reqwest = { version = "0.11.24", default-features = false }
reqwest-middleware = "0.2.4"
reqwest-retry = "0.3.0"
rip = { package = "rattler_installs_packages", version = "0.8.1", default-features = false }
self-replace = "1.3.7"
serde = "1.0.196"
Expand Down
23 changes: 22 additions & 1 deletion src/lock_file/pypi_name_mapping.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use crate::config::get_cache_dir;
use async_once_cell::OnceCell;
use http_cache_reqwest::{CACacheManager, Cache, CacheMode, HttpCache, HttpCacheOptions};
use miette::{IntoDiagnostic, WrapErr};
use rattler_conda_types::{PackageUrl, RepoDataRecord};
use rattler_networking::retry_policies::ExponentialBackoff;
use reqwest::Client;
use reqwest_middleware::ClientBuilder;
use reqwest_retry::RetryTransientMiddleware;
use serde::Deserialize;
use std::{collections::HashMap, str::FromStr};
use url::Url;
Expand All @@ -15,7 +21,22 @@ struct CondaPyPiNameMapping {
pub async fn conda_pypi_name_mapping() -> miette::Result<&'static HashMap<String, String>> {
static MAPPING: OnceCell<HashMap<String, String>> = OnceCell::new();
MAPPING.get_or_try_init(async {
let response = reqwest::get("https://raw.githubusercontent.com/regro/cf-graph-countyfair/master/mappings/pypi/name_mapping.json").await

// Construct a client with a retry policy and local caching
let retry_policy =
ExponentialBackoff::builder().build_with_max_retries(3);
let retry_strategy = RetryTransientMiddleware::new_with_policy(retry_policy);
let cache_strategy = Cache(HttpCache {
mode: CacheMode::Default,
manager: CACacheManager { path: get_cache_dir().expect("missing cache directory").join("http-cache") },
options: HttpCacheOptions::default(),
});
let client = ClientBuilder::new(Client::new())
.with(cache_strategy)
.with(retry_strategy)
.build();

let response = client.get("https://raw.githubusercontent.com/regro/cf-graph-countyfair/master/mappings/pypi/name_mapping.json").send().await
.into_diagnostic()
.context("failed to download pypi name mapping")?;
let mapping: Vec<CondaPyPiNameMapping> = response
Expand Down
Loading