Skip to content

Commit 8d1d949

Browse files
committed
Review
1 parent ddab215 commit 8d1d949

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

crates/uv-python/src/version_files.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,18 @@ impl PythonVersionFile {
218218
}
219219

220220
/// Create a new representation of a global Python version file.
221-
pub fn new_global() -> Option<Self> {
221+
///
222+
/// Returns [`None`] if the user configuration directory cannot be determined.
223+
pub fn global() -> Option<Self> {
222224
let path = user_uv_config_dir()?.join(PYTHON_VERSION_FILENAME);
223225
Some(Self::new(path))
224226
}
225227

228+
/// Returns `true` if the version file is a global version file.
229+
pub fn is_global(&self) -> bool {
230+
PythonVersionFile::global().is_some_and(|global| file.path() == global.path())
231+
}
232+
226233
/// Return the first request declared in the file, if any.
227234
pub fn version(&self) -> Option<&PythonRequest> {
228235
self.versions.first()

crates/uv/src/commands/python/pin.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ pub(crate) async fn pin(
7272
bail!("No Python version file found");
7373
};
7474

75-
if !global
76-
&& PythonVersionFile::new_global().is_some_and(|global| file.path() == global.path())
77-
{
75+
if !global && file.is_global() {
7876
bail!("No Python version file found; use `--rm --global` to remove the global pin");
7977
}
8078

@@ -203,7 +201,7 @@ pub(crate) async fn pin(
203201
let existing = version_file.ok().flatten();
204202
// TODO(zanieb): Allow updating the discovered version file with an `--update` flag.
205203
let new = if global {
206-
let Some(new) = PythonVersionFile::new_global() else {
204+
let Some(new) = PythonVersionFile::global() else {
207205
// TODO(zanieb): We should find a nice way to surface that as an error
208206
bail!("Failed to determine directory for global Python pin");
209207
};

0 commit comments

Comments
 (0)