Files
uv/crates/puffin-dev/src/wheel_metadata.rs
T
Charlie Marsh ed8dfbfcf7 Preserve verbatim URLs (#639)
## Summary

This PR adds a `VerbatimUrl` struct to preserve verbatim URLs throughout
the resolution and installation pipeline. In short, alongside the parsed
`Url`, we also keep the URL as written by the user. This enables us to
display the URL exactly as written by the user, rather than the
serialized path that we use internally.

This will be especially useful once we start expanding environment
variables since, at that point, we'll be able to write the version of
the URL that includes the _unexpected_ environment variable to the
output file.
2023-12-14 15:03:39 +00:00

41 lines
1004 B
Rust

use std::str::FromStr;
use anyhow::Result;
use clap::Parser;
use distribution_filename::WheelFilename;
use distribution_types::{BuiltDist, DirectUrlBuiltDist};
use pep508_rs::VerbatimUrl;
use puffin_cache::{Cache, CacheArgs};
use puffin_client::RegistryClientBuilder;
#[derive(Parser)]
pub(crate) struct WheelMetadataArgs {
url: VerbatimUrl,
#[command(flatten)]
cache_args: CacheArgs,
}
pub(crate) async fn wheel_metadata(args: WheelMetadataArgs) -> Result<()> {
let cache_dir = Cache::try_from(args.cache_args)?;
let client = RegistryClientBuilder::new(cache_dir.clone()).build();
let filename = WheelFilename::from_str(
args.url
.path()
.rsplit_once('/')
.unwrap_or(("", args.url.path()))
.1,
)?;
let metadata = client
.wheel_metadata(&BuiltDist::DirectUrl(DirectUrlBuiltDist {
filename,
url: args.url,
}))
.await?;
println!("{metadata:?}");
Ok(())
}