File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -1337,6 +1337,36 @@ mod tests {
13371337 "Non-base conda environment should be available for virtual environment preference"
13381338 ) ;
13391339
1340+ // When CONDA_PREFIX equals CONDA_DEFAULT_ENV, it should be treated as a virtual environment
1341+ let unnamed_env = context. tempdir . child ( "my-conda-env" ) ;
1342+ TestContext :: mock_conda_prefix ( & unnamed_env, "3.12.4" ) ?;
1343+ let unnamed_env_path = unnamed_env. to_string_lossy ( ) . to_string ( ) ;
1344+
1345+ let python = context. run_with_vars (
1346+ & [
1347+ ( EnvVars :: CONDA_PREFIX , Some ( unnamed_env. as_os_str ( ) ) ) ,
1348+ (
1349+ EnvVars :: CONDA_DEFAULT_ENV ,
1350+ Some ( & OsString :: from ( & unnamed_env_path) ) ,
1351+ ) ,
1352+ ] ,
1353+ || {
1354+ find_python_installation (
1355+ & PythonRequest :: Default ,
1356+ EnvironmentPreference :: OnlyVirtual ,
1357+ PythonPreference :: OnlySystem ,
1358+ & context. cache ,
1359+ Preview :: default ( ) ,
1360+ )
1361+ } ,
1362+ ) ??;
1363+
1364+ assert_eq ! (
1365+ python. interpreter( ) . python_full_version( ) . to_string( ) ,
1366+ "3.12.4" ,
1367+ "We should find the unnamed conda environment"
1368+ ) ;
1369+
13401370 Ok ( ( ) )
13411371 }
13421372
Original file line number Diff line number Diff line change @@ -98,6 +98,12 @@ impl CondaEnvironmentKind {
9898 return Self :: Child ;
9999 } ;
100100
101+ // If the `CONDA_PREFIX` equals the `CONDA_DEFAULT_ENV`, we're in an unnamed environment
102+ // which is typical for environments created with `conda create -p /path/to/env`.
103+ if path == Path :: new ( & current_env) {
104+ return Self :: Child ;
105+ }
106+
101107 // These are the expected names for the base environment; we may want to remove this
102108 // restriction in the future as it's not strictly necessary.
103109 if current_env != "base" && current_env != "root" {
You can’t perform that action at this time.
0 commit comments