This commit is contained in:
Zanie Blue 2025-06-26 09:41:51 -05:00
parent bc64b1f989
commit c57cc1c58b
2 changed files with 10 additions and 5 deletions

View file

@ -218,11 +218,18 @@ impl PythonVersionFile {
}
/// Create a new representation of a global Python version file.
pub fn new_global() -> Option<Self> {
///
/// Returns [`None`] if the user configuration directory cannot be determined.
pub fn global() -> Option<Self> {
let path = user_uv_config_dir()?.join(PYTHON_VERSION_FILENAME);
Some(Self::new(path))
}
/// Returns `true` if the version file is a global version file.
pub fn is_global(&self) -> bool {
PythonVersionFile::global().is_some_and(|global| self.path() == global.path())
}
/// Return the first request declared in the file, if any.
pub fn version(&self) -> Option<&PythonRequest> {
self.versions.first()

View file

@ -72,9 +72,7 @@ pub(crate) async fn pin(
bail!("No Python version file found");
};
if !global
&& PythonVersionFile::new_global().is_some_and(|global| file.path() == global.path())
{
if !global && file.is_global() {
bail!("No Python version file found; use `--rm --global` to remove the global pin");
}
@ -203,7 +201,7 @@ pub(crate) async fn pin(
let existing = version_file.ok().flatten();
// TODO(zanieb): Allow updating the discovered version file with an `--update` flag.
let new = if global {
let Some(new) = PythonVersionFile::new_global() else {
let Some(new) = PythonVersionFile::global() else {
// TODO(zanieb): We should find a nice way to surface that as an error
bail!("Failed to determine directory for global Python pin");
};