@@ -9,7 +9,6 @@ use tracing::debug;
99use uv_cache:: Cache ;
1010use uv_client:: BaseClientBuilder ;
1111use uv_configuration:: { DependencyGroupsWithDefaults , PreviewMode } ;
12- use uv_dirs:: user_uv_config_dir;
1312use uv_fs:: Simplified ;
1413use uv_python:: {
1514 EnvironmentPreference , PYTHON_VERSION_FILENAME , PythonDownloads , PythonInstallation ,
@@ -72,10 +71,22 @@ pub(crate) async fn pin(
7271 }
7372 bail ! ( "No Python version file found" ) ;
7473 } ;
74+
75+ if !global
76+ && PythonVersionFile :: new_global ( ) . is_some_and ( |global| file. path ( ) == global. path ( ) )
77+ {
78+ bail ! ( "No Python version file found; use `--rm --global` to remove the global pin" ) ;
79+ }
80+
7581 fs_err:: tokio:: remove_file ( file. path ( ) ) . await ?;
7682 writeln ! (
7783 printer. stdout( ) ,
78- "Removed Python version file at `{}`" ,
84+ "Removed {} at `{}`" ,
85+ if global {
86+ "global Python pin"
87+ } else {
88+ "Python version file"
89+ } ,
7990 file. path( ) . user_display( )
8091 ) ?;
8192 return Ok ( ExitStatus :: Success ) ;
@@ -192,12 +203,11 @@ pub(crate) async fn pin(
192203 let existing = version_file. ok ( ) . flatten ( ) ;
193204 // TODO(zanieb): Allow updating the discovered version file with an `--update` flag.
194205 let new = if global {
195- let Some ( config_dir) = user_uv_config_dir ( ) else {
196- return Err ( anyhow:: anyhow!( "No user-level config directory found." ) ) ;
206+ let Some ( new) = PythonVersionFile :: new_global ( ) else {
207+ // TODO(zanieb): We should find a nice way to surface that as an error
208+ bail ! ( "Failed to determine directory for global Python pin" ) ;
197209 } ;
198- fs_err:: tokio:: create_dir_all ( & config_dir) . await ?;
199- PythonVersionFile :: new ( config_dir. join ( PYTHON_VERSION_FILENAME ) )
200- . with_versions ( vec ! [ request] )
210+ new. with_versions ( vec ! [ request] )
201211 } else {
202212 PythonVersionFile :: new ( project_dir. join ( PYTHON_VERSION_FILENAME ) )
203213 . with_versions ( vec ! [ request] )
0 commit comments