File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ( )
Original file line number Diff line number Diff 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 } ;
You can’t perform that action at this time.
0 commit comments