mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
Remove normalized representation of SimpleJson
This commit is contained in:
parent
610fd9994f
commit
b08e8c78b5
5 changed files with 16 additions and 114 deletions
|
@ -20,7 +20,7 @@ pub(crate) async fn install(src: &Path) -> Result<ExitStatus> {
|
|||
let packument = client.simple(&requirement.name).await?;
|
||||
#[allow(clippy::print_stdout)]
|
||||
{
|
||||
println!("{:#?}", packument);
|
||||
println!("{packument:#?}");
|
||||
println!("{requirement:#?}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ArtifactInfo>,
|
||||
}
|
||||
|
||||
#[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<String>,
|
||||
pub requires_python: Option<String>,
|
||||
pub dist_info_metadata: DistInfoMetadata,
|
||||
pub yanked: Yanked,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(from = "Option<RawDistInfoMetadata>")]
|
||||
pub struct DistInfoMetadata {
|
||||
pub available: bool,
|
||||
pub hash: Option<String>,
|
||||
}
|
||||
|
||||
impl From<Option<RawDistInfoMetadata>> for DistInfoMetadata {
|
||||
fn from(maybe_raw: Option<RawDistInfoMetadata>) -> 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<String, String>),
|
||||
}
|
||||
|
||||
#[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<String>,
|
||||
}
|
||||
|
||||
impl From<RawYanked> 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),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Path>) -> 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<Url>,
|
||||
pub(crate) client: ClientWithMiddleware,
|
||||
}
|
||||
|
||||
impl PypiClient {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue