diff --git a/crates/puffin-cli/src/commands/install.rs b/crates/puffin-cli/src/commands/install.rs index 70ebf4848..9bc5a81a6 100644 --- a/crates/puffin-cli/src/commands/install.rs +++ b/crates/puffin-cli/src/commands/install.rs @@ -20,7 +20,7 @@ pub(crate) async fn install(src: &Path) -> Result { let packument = client.simple(&requirement.name).await?; #[allow(clippy::print_stdout)] { - println!("{:#?}", packument); + println!("{packument:#?}"); println!("{requirement:#?}"); } } diff --git a/crates/puffin-client/src/api/mod.rs b/crates/puffin-client/src/api/mod.rs index 675984444..4f6a5ac82 100644 --- a/crates/puffin-client/src/api/mod.rs +++ b/crates/puffin-client/src/api/mod.rs @@ -58,7 +58,7 @@ pub struct SimpleJson { #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] -pub struct File { +pub(crate) struct File { core_metadata: Metadata, data_dist_info_metadata: Metadata, filename: String, @@ -72,122 +72,27 @@ pub struct File { #[derive(Debug, Serialize, Deserialize)] #[serde(untagged)] -pub enum Metadata { +pub(crate) enum Metadata { Bool(bool), Hashes(Hashes), } #[derive(Debug, Serialize, Deserialize)] #[serde(untagged)] -pub enum Yanked { +pub(crate) enum Yanked { Bool(bool), Reason(String), } #[derive(Debug, Serialize, Deserialize)] -pub struct Hashes { +pub(crate) struct Hashes { sha256: String, } #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] -pub struct Meta { +pub(crate) struct Meta { #[serde(rename = "_last-serial")] last_serial: i64, api_version: String, } - - -/// The metadata for a single package, including the pubishing versions and their artifacts. -/// -/// In npm, this is referred to as a "packument", which is a portmanteau of "package" and -/// "document". -#[derive(Debug, Serialize, Deserialize)] -pub struct PackageDocument { - pub meta: Meta, - pub artifacts: Vec, -} - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct Meta { - pub version: String, -} - -impl Default for Meta { - fn default() -> Self { - Self { - // According to the spec, clients SHOULD introspect each response for the repository - // version; if it doesn't exist, clients MUST assume that it is version 1.0. - version: "1.0".into(), - } - } -} - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct ArtifactInfo { - pub name: String, - pub url: Url, - pub hash: Option, - pub requires_python: Option, - pub dist_info_metadata: DistInfoMetadata, - pub yanked: Yanked, -} - -#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] -#[serde(from = "Option")] -pub struct DistInfoMetadata { - pub available: bool, - pub hash: Option, -} - -impl From> for DistInfoMetadata { - fn from(maybe_raw: Option) -> Self { - match maybe_raw { - None => Default::default(), - Some(raw) => match raw { - RawDistInfoMetadata::NoHashes(available) => Self { - available, - hash: None, - }, - RawDistInfoMetadata::WithHashes(_) => Self { - available: true, - hash: None, - }, - }, - } - } -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -enum RawDistInfoMetadata { - NoHashes(bool), - WithHashes(HashMap), -} - -#[derive(Debug, Clone, Deserialize)] -enum RawYanked { - NoReason(bool), - WithReason(String), -} - -#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] -#[serde(from = "RawYanked")] -pub struct Yanked { - pub yanked: bool, - pub reason: Option, -} - -impl From for Yanked { - fn from(raw: RawYanked) -> Self { - match raw { - RawYanked::NoReason(yanked) => Self { - yanked, - reason: None, - }, - RawYanked::WithReason(reason) => Self { - yanked: true, - reason: Some(reason), - }, - } - } -} diff --git a/crates/puffin-client/src/error.rs b/crates/puffin-client/src/error.rs index 48ccae958..698441165 100644 --- a/crates/puffin-client/src/error.rs +++ b/crates/puffin-client/src/error.rs @@ -33,9 +33,6 @@ pub enum PypiClientError { impl PypiClientError { pub fn from_json_err(err: serde_json::Error, url: String) -> Self { - Self::BadJson { - source: err, - url: url.clone(), - } + Self::BadJson { source: err, url } } } diff --git a/crates/puffin-client/src/lib.rs b/crates/puffin-client/src/lib.rs index 6456997d2..95806a290 100644 --- a/crates/puffin-client/src/lib.rs +++ b/crates/puffin-client/src/lib.rs @@ -11,10 +11,6 @@ use url::Url; mod api; mod error; -fn main() { - println!("Hello, world!"); -} - #[derive(Debug, Clone)] pub struct PypiClientBuilder { registry: Url, @@ -33,16 +29,19 @@ impl Default for PypiClientBuilder { } impl PypiClientBuilder { + #[must_use] pub fn registry(mut self, registry: Url) -> Self { self.registry = registry; self } + #[must_use] pub fn retries(mut self, retries: u32) -> Self { self.retries = retries; self } + #[must_use] pub fn cache(mut self, cache: impl AsRef) -> Self { self.cache = Some(PathBuf::from(cache.as_ref())); self @@ -50,7 +49,7 @@ impl PypiClientBuilder { pub fn build(self) -> PypiClient { let client_raw = { - let mut client_core = ClientBuilder::new() + let client_core = ClientBuilder::new() .user_agent("puffin") .pool_max_idle_per_host(20) .timeout(std::time::Duration::from_secs(60 * 5)); @@ -62,7 +61,7 @@ impl PypiClientBuilder { let retry_strategy = RetryTransientMiddleware::new_with_policy(retry_policy); let mut client_builder = - reqwest_middleware::ClientBuilder::new(client_raw.clone()).with(retry_strategy); + reqwest_middleware::ClientBuilder::new(client_raw).with(retry_strategy); if let Some(path) = self.cache { client_builder = client_builder.with(Cache(HttpCache { @@ -84,5 +83,3 @@ pub struct PypiClient { pub(crate) registry: Arc, pub(crate) client: ClientWithMiddleware, } - -impl PypiClient {} diff --git a/requirements.txt b/requirements.txt index 8f0a64ae0..e5def3e2b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,4 @@ -flask==2.0 +flask +black +jinja2 +pyyaml