mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +00:00
Review
This commit is contained in:
parent
bc64b1f989
commit
c57cc1c58b
2 changed files with 10 additions and 5 deletions
|
@ -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()
|
||||
|
|
|
@ -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");
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue