Separate cache construction from initialization (#3607)

## Summary

Ensures that we only initialize the cache for commands that require it.

Closes https://github.com/astral-sh/uv/issues/3539.
This commit is contained in:
Charlie Marsh 2024-05-15 12:29:39 -04:00 committed by GitHub
parent 647f38be31
commit 55aedda379
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 78 additions and 49 deletions

View file

@ -53,7 +53,7 @@ pub(crate) async fn build(args: BuildArgs) -> Result<PathBuf> {
BuildKind::Wheel
};
let cache = Cache::try_from(args.cache_args)?;
let cache = Cache::try_from(args.cache_args)?.init()?;
let venv = PythonEnvironment::from_virtualenv(&cache)?;
let client = RegistryClientBuilder::new(cache.clone()).build();

View file

@ -15,7 +15,7 @@ pub(crate) struct CompileArgs {
}
pub(crate) async fn compile(args: CompileArgs) -> anyhow::Result<()> {
let cache = Cache::try_from(args.cache_args)?;
let cache = Cache::try_from(args.cache_args)?.init()?;
let interpreter = if let Some(python) = args.python {
python

View file

@ -18,9 +18,8 @@ pub(crate) struct WheelMetadataArgs {
}
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 cache = Cache::try_from(args.cache_args)?.init()?;
let client = RegistryClientBuilder::new(cache).build();
let filename = WheelFilename::from_str(
args.url