File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -239,7 +239,10 @@ impl PythonVersionFile {
239239
240240 /// Returns `true` if the version file is a global version file.
241241 pub fn is_global ( & self ) -> bool {
242- Self :: global ( ) . is_some_and ( |global| self . path ( ) == global. path ( ) )
242+ user_uv_config_dir ( ) . is_some_and ( |directory| {
243+ self . path ( ) == directory. join ( PYTHON_VERSION_FILENAME )
244+ || self . path ( ) == directory. join ( PYTHON_VERSIONS_FILENAME )
245+ } )
243246 }
244247
245248 /// Return the first request declared in the file, if any.
Original file line number Diff line number Diff line change @@ -852,3 +852,41 @@ fn python_pin_rm() {
852852 error: No Python version file found; use `--rm --global` to remove the global pin
853853 " ) ;
854854}
855+
856+ #[ test]
857+ fn python_pin_rm_versions ( ) -> Result < ( ) > {
858+ let context = uv_test:: test_context_with_versions!( & [ ] ) ;
859+ let global = context. user_config_dir . child ( "uv" ) ;
860+ global. create_dir_all ( ) ?;
861+ let global_versions = global. child ( PYTHON_VERSIONS_FILENAME ) ;
862+ global_versions. write_str ( "3.11\n 3.12\n " ) ?;
863+
864+ let local_versions = context. temp_dir . child ( PYTHON_VERSIONS_FILENAME ) ;
865+ local_versions. write_str ( "3.12\n " ) ?;
866+
867+ uv_snapshot ! ( context. filters( ) , context. python_pin( ) . arg( "--rm" ) , @"
868+ exit_code: 0 (success)
869+ ----- stdout -----
870+ Removed Python version file at `.python-versions`
871+ " ) ;
872+ assert ! ( !local_versions. exists( ) ) ;
873+
874+ uv_snapshot ! ( context. filters( ) , context. python_pin( ) . arg( "--rm" ) , @"
875+ exit_code: 2 (failure)
876+ ----- stderr -----
877+ error: No Python version file found; use `--rm --global` to remove the global pin
878+ " ) ;
879+ assert_snapshot ! ( context. read( & global_versions) , @"
880+ 3.11
881+ 3.12
882+ " ) ;
883+
884+ uv_snapshot ! ( context. filters( ) , context. python_pin( ) . arg( "--rm" ) . arg( "--global" ) , @"
885+ exit_code: 0 (success)
886+ ----- stdout -----
887+ Removed global Python pin at `[UV_USER_CONFIG_DIR]/.python-versions`
888+ " ) ;
889+ assert ! ( !global_versions. exists( ) ) ;
890+
891+ Ok ( ( ) )
892+ }
You can’t perform that action at this time.
0 commit comments