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 {
1337
1337
"Non-base conda environment should be available for virtual environment preference"
1338
1338
) ;
1339
1339
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
+
1340
1370
Ok ( ( ) )
1341
1371
}
1342
1372
Original file line number Diff line number Diff line change @@ -98,6 +98,12 @@ impl CondaEnvironmentKind {
98
98
return Self :: Child ;
99
99
} ;
100
100
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
+
101
107
// These are the expected names for the base environment; we may want to remove this
102
108
// restriction in the future as it's not strictly necessary.
103
109
if current_env != "base" && current_env != "root" {
You can’t perform that action at this time.
0 commit comments