mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +00:00
Eliminate dependencies on directores
and dirs-sys
(#8048)
Migrate all directory related logic to `etcetera`, eliminated two dependecies.
This commit is contained in:
parent
4874b32d85
commit
1df8f86c22
7 changed files with 39 additions and 46 deletions
|
@ -32,7 +32,7 @@ uv-static = { workspace = true }
|
|||
uv-warnings = { workspace = true }
|
||||
|
||||
clap = { workspace = true }
|
||||
dirs-sys = { workspace = true }
|
||||
etcetera = { workspace = true }
|
||||
fs-err = { workspace = true }
|
||||
schemars = { workspace = true, optional = true }
|
||||
serde = { workspace = true }
|
||||
|
|
|
@ -2,6 +2,8 @@ use std::env;
|
|||
use std::ops::Deref;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use etcetera::BaseStrategy;
|
||||
|
||||
use uv_fs::Simplified;
|
||||
use uv_static::EnvVars;
|
||||
use uv_warnings::warn_user;
|
||||
|
@ -174,23 +176,12 @@ impl From<Options> for FilesystemOptions {
|
|||
|
||||
/// Returns the path to the user configuration directory.
|
||||
///
|
||||
/// This is similar to the `config_dir()` returned by the `dirs` crate, but it uses the
|
||||
/// `XDG_CONFIG_HOME` environment variable on both Linux _and_ macOS, rather than the
|
||||
/// `Application Support` directory on macOS.
|
||||
/// On Windows, use, e.g., C:\Users\Alice\AppData\Roaming
|
||||
/// On Linux and macOS, use `XDG_CONFIG_HOME` or $HOME/.config, e.g., /home/alice/.config.
|
||||
fn user_config_dir() -> Option<PathBuf> {
|
||||
// On Windows, use, e.g., `C:\Users\Alice\AppData\Roaming`.
|
||||
#[cfg(windows)]
|
||||
{
|
||||
dirs_sys::known_folder_roaming_app_data()
|
||||
}
|
||||
|
||||
// On Linux and macOS, use, e.g., `/home/alice/.config`.
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
env::var_os(EnvVars::XDG_CONFIG_HOME)
|
||||
.and_then(dirs_sys::is_absolute_path)
|
||||
.or_else(|| dirs_sys::home_dir().map(|path| path.join(".config")))
|
||||
}
|
||||
etcetera::choose_base_strategy()
|
||||
.map(|dirs| dirs.config_dir())
|
||||
.ok()
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue