@@ -11659,3 +11659,58 @@ fn strip_shebang_arguments() -> Result<()> {
1165911659
1166011660 Ok ( ( ) )
1166111661}
11662+
11663+ #[ test]
11664+ fn install_python_preference ( ) {
11665+ let context =
11666+ TestContext :: new_with_versions ( & [ "3.12" , "3.11" ] ) . with_versions_as_managed ( & [ "3.12" ] ) ;
11667+
11668+ // Create a managed interpreter environment
11669+ uv_snapshot ! ( context. filters( ) , context. venv( ) , @r"
11670+ success: true
11671+ exit_code: 0
11672+ ----- stdout -----
11673+
11674+ ----- stderr -----
11675+ Using CPython 3.12.[X] interpreter at: [PYTHON-3.12]
11676+ Creating virtual environment at: .venv
11677+ Activate with: source .venv/[BIN]/activate
11678+ " ) ;
11679+
11680+ // Install a package, requesting managed Python
11681+ uv_snapshot ! ( context. filters( ) , context. pip_install( ) . arg( "anyio" ) . arg( "--managed-python" ) , @r"
11682+ success: true
11683+ exit_code: 0
11684+ ----- stdout -----
11685+
11686+ ----- stderr -----
11687+ Resolved 3 packages in [TIME]
11688+ Prepared 3 packages in [TIME]
11689+ Installed 3 packages in [TIME]
11690+ + anyio==4.3.0
11691+ + idna==3.6
11692+ + sniffio==1.3.1
11693+ " ) ;
11694+
11695+ // Install a package, requesting unmanaged Python
11696+ // This is allowed, because the virtual environment already exists
11697+ uv_snapshot ! ( context. filters( ) , context. pip_install( ) . arg( "anyio" ) . arg( "--no-managed-python" ) , @r"
11698+ success: true
11699+ exit_code: 0
11700+ ----- stdout -----
11701+
11702+ ----- stderr -----
11703+ Audited 1 package in [TIME]
11704+ " ) ;
11705+
11706+ // This also works with `VIRTUAL_ENV` unset
11707+ uv_snapshot ! ( context. filters( ) , context. pip_install( )
11708+ . arg( "anyio" ) . arg( "--no-managed-python" ) . env_remove( "VIRTUAL_ENV" ) , @r"
11709+ success: true
11710+ exit_code: 0
11711+ ----- stdout -----
11712+
11713+ ----- stderr -----
11714+ Audited 1 package in [TIME]
11715+ " ) ;
11716+ }
0 commit comments