Skip to content

Commit

Permalink
Avoid panic with missing temporary directory (#6929)
Browse files Browse the repository at this point in the history
Forward an error for missing temp directories:

```
$ env TMPDIR=.tmp uv-debug pip install httpx
  error: No such file or directory (os error 2) at path "/home/konsti/projects/uv/.tmp/.tmpgIBhhh"
```

Fixes #6878
  • Loading branch information
konstin authored Sep 2, 2024
1 parent 7e6df8f commit 9edf2d8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
13 changes: 8 additions & 5 deletions crates/uv-client/src/registry_client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::BTreeMap;
use std::fmt::Debug;
use std::io;
use std::path::PathBuf;
use std::str::FromStr;

Expand Down Expand Up @@ -145,14 +146,16 @@ impl<'a> RegistryClientBuilder<'a> {
}
}

impl<'a> From<BaseClientBuilder<'a>> for RegistryClientBuilder<'a> {
fn from(value: BaseClientBuilder<'a>) -> Self {
Self {
impl<'a> TryFrom<BaseClientBuilder<'a>> for RegistryClientBuilder<'a> {
type Error = io::Error;

fn try_from(value: BaseClientBuilder<'a>) -> Result<Self, Self::Error> {
Ok(Self {
index_urls: IndexUrls::default(),
index_strategy: IndexStrategy::default(),
cache: Cache::temp().unwrap(),
cache: Cache::temp()?,
base_client_builder: value,
}
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/pip/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ pub(crate) async fn pip_compile(
}

// Initialize the registry client.
let client = RegistryClientBuilder::from(client_builder)
let client = RegistryClientBuilder::try_from(client_builder)?
.cache(cache.clone())
.index_urls(index_locations.index_urls())
.index_strategy(index_strategy)
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/pip/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ pub(crate) async fn pip_install(
}

// Initialize the registry client.
let client = RegistryClientBuilder::from(client_builder)
let client = RegistryClientBuilder::try_from(client_builder)?
.cache(cache.clone())
.index_urls(index_locations.index_urls())
.index_strategy(index_strategy)
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/pip/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub(crate) async fn pip_sync(
}

// Initialize the registry client.
let client = RegistryClientBuilder::from(client_builder)
let client = RegistryClientBuilder::try_from(client_builder)?
.cache(cache.clone())
.index_urls(index_locations.index_urls())
.index_strategy(index_strategy)
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/project/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub(crate) async fn add(
}

// Initialize the registry client.
let client = RegistryClientBuilder::from(client_builder)
let client = RegistryClientBuilder::try_from(client_builder)?
.index_urls(settings.index_locations.index_urls())
.index_strategy(settings.index_strategy)
.markers(&markers)
Expand Down
3 changes: 2 additions & 1 deletion crates/uv/src/commands/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ async fn venv_impl(
}

// Instantiate a client.
let client = RegistryClientBuilder::from(client_builder)
let client = RegistryClientBuilder::try_from(client_builder)
.into_diagnostic()?
.cache(cache.clone())
.index_urls(index_locations.index_urls())
.index_strategy(index_strategy)
Expand Down

0 comments on commit 9edf2d8

Please sign in to comment.