Skip to content

Commit

Permalink
just parse from string
Browse files Browse the repository at this point in the history
  • Loading branch information
zen-xu committed Nov 27, 2024
1 parent 07afa44 commit 483ac58
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 31 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

12 changes: 1 addition & 11 deletions crates/pixi_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,6 @@ pub enum KeyringProvider {
Subprocess,
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub enum TrustedHost {
Wildcard,
Host {
scheme: Option<String>,
host: String,
port: Option<u16>,
},
}

#[derive(Clone, Debug, Deserialize, Serialize, Default)]
#[serde(rename_all = "kebab-case")]
pub struct PyPIConfig {
Expand All @@ -287,7 +277,7 @@ pub struct PyPIConfig {
/// Allow insecure connections to a host
#[serde(default)]
#[serde(skip_serializing_if = "Vec::is_empty")]
pub allow_insecure_host: Vec<TrustedHost>,
pub allow_insecure_host: Vec<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
Expand Down
1 change: 0 additions & 1 deletion crates/pixi_uv_conversions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ version = "0.1.0"
dunce = { workspace = true }
pep440_rs = { workspace = true }
pep508_rs = { workspace = true }
pixi_config = { workspace = true }
pixi_manifest = { workspace = true }
rattler_lock = { workspace = true }
serde_json = { workspace = true }
Expand Down
15 changes: 5 additions & 10 deletions crates/pixi_uv_conversions/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// use uv_normalize::PackageName;
// use pep508_rs::PackageName;

use pixi_config::TrustedHost;
use std::error::Error;
use std::{
fmt::{Debug, Display},
Expand Down Expand Up @@ -141,6 +140,9 @@ pub enum ConversionError {

#[error(transparent)]
InvalidVersion(#[from] VersionError),

#[error(transparent)]
TrustedHostError(#[from] uv_configuration::TrustedHostError),
}

pub fn to_requirements<'req>(
Expand Down Expand Up @@ -268,14 +270,7 @@ pub fn to_version_specifiers(

/// Converts `TrustedHost` to `uv_configuration::TrustedHost`
pub fn to_uv_trusted_host(
trusted_host: &TrustedHost,
trusted_host: &str,
) -> Result<uv_configuration::TrustedHost, ConversionError> {
match trusted_host {
TrustedHost::Wildcard => Ok(uv_configuration::TrustedHost::Wildcard),
TrustedHost::Host { scheme, host, port } => Ok(uv_configuration::TrustedHost::Host {
scheme: scheme.clone(),
host: host.to_string(),
port: *port,
}),
}
Ok(uv_configuration::TrustedHost::from_str(&trusted_host)?)
}
25 changes: 17 additions & 8 deletions src/lock_file/resolve/uv_resolution_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use uv_types::{HashStrategy, InFlight};
use crate::Project;
use pixi_config::{self, get_cache_dir};
use pixi_consts::consts;
use pixi_uv_conversions::to_uv_trusted_host;
use pixi_uv_conversions::{to_uv_trusted_host, ConversionError};

/// Objects that are needed for resolutions which can be shared between different resolutions.
#[derive(Clone)]
Expand Down Expand Up @@ -49,6 +49,21 @@ impl UvResolutionContext {
};

let in_flight = Arc::new(InFlight::default());
let allow_insecure_host = project
.config()
.pypi_config
.allow_insecure_host
.iter()
.try_fold(
Vec::new(),
|mut hosts, host| -> Result<Vec<TrustedHost>, ConversionError> {
let parsed = to_uv_trusted_host(host)?;
hosts.push(parsed);
Ok(hosts)
},
)
.into_diagnostic()
.context("failed to parse trusted host")?;
Ok(Self {
cache,
in_flight,
Expand All @@ -59,13 +74,7 @@ impl UvResolutionContext {
concurrency: Concurrency::default(),
source_strategy: SourceStrategy::Disabled,
capabilities: IndexCapabilities::default(),
allow_insecure_host: project
.config()
.pypi_config
.allow_insecure_host
.iter()
.map(|host| to_uv_trusted_host(host).unwrap())
.collect(),
allow_insecure_host,
})
}
}

0 comments on commit 483ac58

Please sign in to comment.